Skip to content

Commit c90bbb7

Browse files
committed
fix VS Toolset version
1 parent 2f35ed7 commit c90bbb7

File tree

5 files changed

+215
-57
lines changed

5 files changed

+215
-57
lines changed

.github/workflows/build.yml

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,48 @@ jobs:
2020
with:
2121
submodules: 'recursive'
2222

23+
- name: Locate VS Installer (setup.exe) or download bootstrapper
24+
if: runner.os == 'Windows'
25+
id: vsinst
26+
shell: pwsh
27+
run: |
28+
$local = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe'
29+
if (Test-Path $local) {
30+
echo "cmd=$local" >> $env:GITHUB_OUTPUT
31+
echo "op=modify" >> $env:GITHUB_OUTPUT
32+
}
33+
else {
34+
$bootstrap = Join-Path $env:RUNNER_TEMP 'vs_enterprise.exe'
35+
Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_enterprise.exe' -OutFile $bootstrap
36+
echo "cmd=$bootstrap" >> $env:GITHUB_OUTPUT
37+
echo "op=install" >> $env:GITHUB_OUTPUT
38+
}
39+
40+
- name: Get VS installation path
41+
if: runner.os == 'Windows'
42+
id: vs
43+
shell: pwsh
44+
run: |
45+
$path = vswhere -latest -products * -property installationPath
46+
if (-not $path) { throw "vswhere could not find Visual Studio" }
47+
echo "path=$path" >> $env:GITHUB_OUTPUT
48+
49+
- name: Install MSVC 14.36.32532
50+
shell: pwsh
51+
run: |
52+
& '${{ steps.vsinst.outputs.cmd }}' ${{ steps.vsinst.outputs.op }} `
53+
--channelId VisualStudio.17.Release `
54+
--installPath '${{ steps.vs.outputs.path }}' `
55+
--add Microsoft.VisualStudio.Component.VC.14.36.17.6.x86.x64 `
56+
--quiet --norestart
57+
58+
- name: Ensure MSVC Toolset 14.36.32532 is installed
59+
if: runner.os == 'Windows'
60+
uses: TheMrMilchmann/setup-msvc-dev@v3
61+
with:
62+
arch: x64
63+
toolset: 14.36.32532
64+
2365
- name: Setup alpine
2466
uses: jirutka/setup-alpine@v1
2567
if: runner.os != 'Windows'
@@ -55,23 +97,6 @@ jobs:
5597
uses: ilammy/setup-nasm@v1
5698
if: runner.os == 'Windows'
5799

58-
- name: Ensure MSVC Toolset 14.36.32532 is installed
59-
if: runner.os == 'Windows'
60-
shell: powershell
61-
run: |
62-
$vsPath = & '"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"' -latest -property installationPath
63-
if (-not $vsPath) {
64-
Write-Error "Visual Studio installation not found."
65-
exit 1
66-
}
67-
$msvcDir = Join-Path $vsPath "VC\Tools\MSVC\14.36.32532"
68-
if (-Not (Test-Path $msvcDir)) {
69-
Write-Host "MSVC toolset 14.36.32532 not found. Attempting installation..."
70-
& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify --installPath $vsPath --add Microsoft.VisualStudio.Component.VC.14.36.17.6.x86.x64 --quiet --wait
71-
} else {
72-
Write-Host "MSVC toolset 14.36.32532 is already installed."
73-
}
74-
75100
- name: Build
76101
if: runner.os == 'Windows'
77102
shell: bash

HandleScope.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import re
3+
import sys
4+
5+
pattern = re.compile(r'(?P<scope>(?:v8::)?(?:HandleScope|EscapableHandleScope|SealHandleScope) )')
6+
7+
def process_file(file_path):
8+
try:
9+
with open(file_path, 'r', encoding='utf-8') as f:
10+
content = f.read()
11+
except Exception as e:
12+
print(f"Error reading {file_path}: {e}")
13+
return
14+
15+
changed = False
16+
new_lines = []
17+
for line in content.splitlines(keepends=True):
18+
if 'using' in line or '//' in line or 'Debug' in line or 'Node' in line:
19+
new_lines.append(line)
20+
else:
21+
def replacement(m):
22+
text = m.group("scope")
23+
if text.startswith("v8::"):
24+
return "node::Node" + text[4:]
25+
else:
26+
return "node::Node" + text
27+
28+
new_line = pattern.sub(replacement, line)
29+
if new_line != line:
30+
changed = True
31+
new_lines.append(new_line)
32+
33+
new_content = ''.join(new_lines)
34+
if changed:
35+
try:
36+
with open(file_path, 'w', encoding='utf-8') as f:
37+
f.write(new_content)
38+
print(f"Modified: {file_path}")
39+
except Exception as e:
40+
print(f"Error writing {file_path}: {e}")
41+
42+
def process_directory(directory):
43+
blocklist = ['node.h', 'environment.cc']
44+
for root, dirs, files in os.walk(directory):
45+
for file in files:
46+
if (file.endswith('.cc') or file.endswith('.h')) and str(file) not in blocklist:
47+
file_path = os.path.join(root, file)
48+
process_file(file_path)
49+
50+
if __name__ == '__main__':
51+
if len(sys.argv) < 2:
52+
print("Usage: python HandleScope.py <directory>")
53+
sys.exit(1)
54+
target_directory = sys.argv[1]
55+
process_directory(target_directory)

build-windows.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ for %%f in (../patches/*.patch) do (
66
git apply --reject --whitespace=fix "../patches/%%f"
77
)
88

9+
python ../HandleScope.py src
10+
911
vcbuild.bat release x64 dll no-cctest clang-cl nonpm
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git forkSrcPrefix/deps/uv/src/win/async.c forkDstPrefix/deps/uv/src/win/async.c
2+
index b904676e3a72ddbf8370e2f2111385513c9698f3..352654d5863bd54f717ed3b3f84298889bdc99a7 100644
3+
--- forkSrcPrefix/deps/uv/src/win/async.c
4+
+++ forkDstPrefix/deps/uv/src/win/async.c
5+
@@ -71,9 +71,8 @@ int uv_async_send(uv_async_t* handle) {
6+
return -1;
7+
}
8+
9+
- /* The user should make sure never to call uv_async_send to a closing or
10+
- * closed handle. */
11+
- assert(!(handle->flags & UV_HANDLE_CLOSING));
12+
+ if (handle->flags & UV_HANDLE_CLOSING)
13+
+ return 0; /* ignore like Unix */
14+
15+
if (!uv__atomic_exchange_set(&handle->async_sent)) {
16+
POST_COMPLETION_FOR_REQ(loop, &handle->async_req);

patches/handle_scope.patch

Lines changed: 100 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,107 @@
1-
diff --git forkSrcPrefix/deps/v8/src/api/api.cc forkDstPrefix/deps/v8/src/api/api.cc
2-
index 2dd476dda34f1cfe3a75b7895009af24963372f2..6476204733a8aa87c4681dbeb5fee12db54e529d 100644
3-
--- forkSrcPrefix/deps/v8/src/api/api.cc
4-
+++ forkDstPrefix/deps/v8/src/api/api.cc
5-
@@ -883,7 +883,21 @@ void InternalFieldOutOfBounds(int index) {
1+
diff --git forkSrcPrefix/src/node.h forkDstPrefix/src/node.h
2+
index 60598f54114b2424f10706e57d8aa50c4634bcb0..9213adb06dd45f521867591ff9a4af70096802de 100644
3+
--- forkSrcPrefix/src/node.h
4+
+++ forkDstPrefix/src/node.h
5+
@@ -228,6 +228,67 @@ namespace node {
66

7-
// --- H a n d l e s ---
8-
9-
-HandleScope::HandleScope(Isolate* v8_isolate) { Initialize(v8_isolate); }
10-
+static std::function<void(Isolate*)> g_enterScopeCB;
11-
+static std::function<void(Isolate*)> g_leaveScopeCB;
12-
+
13-
+V8_EXPORT void SetScopeHandler(const std::function<void(Isolate*)>& enter,
14-
+ const std::function<void(Isolate*)>& exit) {
15-
+ g_enterScopeCB = enter;
16-
+ g_leaveScopeCB = exit;
17-
+}
7+
class IsolateData;
8+
class Environment;
189
+
19-
+HandleScope::HandleScope(Isolate* v8_isolate) {
20-
+ if(g_enterScopeCB) {
21-
+ g_enterScopeCB(v8_isolate);
10+
+class ScopeCB
11+
+{
12+
+ v8::Isolate* m_isolate;
13+
+public:
14+
+ inline ScopeCB(v8::Isolate* isolate) : m_isolate(isolate) {
15+
+ if(g_enterScopeCB) {
16+
+ g_enterScopeCB(isolate);
17+
+ }
2218
+ }
23-
+ Initialize(v8_isolate);
24-
+}
19+
+
20+
+ inline ~ScopeCB() {
21+
+ if(g_leaveScopeCB) {
22+
+ g_leaveScopeCB(m_isolate);
23+
+ }
24+
+ }
25+
+
26+
+ inline static std::function<void(v8::Isolate*)> g_enterScopeCB;
27+
+ inline static std::function<void(v8::Isolate*)> g_leaveScopeCB;
28+
+};
29+
+
30+
+NODE_EXTERN void SetScopeHandler(const std::function<void(v8::Isolate*)>& enter,
31+
+ const std::function<void(v8::Isolate*)>& exit);
32+
+
33+
+class NodeHandleScope
34+
+{
35+
+ ScopeCB m_scopeCB;
36+
+ v8::HandleScope m_handleScope;
37+
+public:
38+
+ inline NodeHandleScope(v8::Isolate* isolate) : m_scopeCB(isolate), m_handleScope(isolate) {}
39+
+ inline ~NodeHandleScope() = default;
40+
+};
41+
+
42+
+class NodeEscapableHandleScope
43+
+{
44+
+ ScopeCB m_scopeCB;
45+
+ v8::EscapableHandleScope m_handleScope;
46+
+public:
47+
+ inline NodeEscapableHandleScope(v8::Isolate* isolate) : m_scopeCB(isolate), m_handleScope(isolate) {}
48+
+ inline ~NodeEscapableHandleScope() = default;
49+
+
50+
+ template <class T>
51+
+ inline v8::Local<T> Escape(v8::Local<T> value) {
52+
+ return m_handleScope.Escape(value);
53+
+ }
54+
+
55+
+ template <class T>
56+
+ inline v8::MaybeLocal<T> EscapeMaybe(v8::MaybeLocal<T> value) {
57+
+ return m_handleScope.EscapeMaybe(value);
58+
+ }
59+
+};
60+
+
61+
+class NodeSealHandleScope
62+
+{
63+
+ ScopeCB m_scopeCB;
64+
+ v8::SealHandleScope m_handleScope;
65+
+public:
66+
+ inline NodeSealHandleScope(v8::Isolate* isolate) : m_scopeCB(isolate), m_handleScope(isolate) {}
67+
+ inline ~NodeSealHandleScope() = default;
68+
+};
69+
+
70+
class MultiIsolatePlatform;
71+
class InitializationResultImpl;
72+
73+
diff --git forkSrcPrefix/src/node.cc forkDstPrefix/src/node.cc
74+
index 1a2a43bdd37441400323a800c147fcb89f0d549a..81f15f01e2a59f3752254a768f6a58d4286a23fc 100644
75+
--- forkSrcPrefix/src/node.cc
76+
+++ forkDstPrefix/src/node.cc
77+
@@ -290,7 +290,7 @@ void Environment::InitializeDiagnostics() {
78+
79+
static
80+
MaybeLocal<Value> StartExecution(Environment* env, const char* main_script_id) {
81+
- EscapableHandleScope scope(env->isolate());
82+
+ NodeEscapableHandleScope scope(env->isolate());
83+
CHECK_NOT_NULL(main_script_id);
84+
Realm* realm = env->principal_realm();
2585

26-
void HandleScope::Initialize(Isolate* v8_isolate) {
27-
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
28-
@@ -908,6 +922,9 @@ void HandleScope::Initialize(Isolate* v8_isolate) {
86+
@@ -338,7 +338,7 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
87+
// Only snapshot builder or embedder applications set the
88+
// callback.
89+
if (cb != nullptr) {
90+
- EscapableHandleScope scope(env->isolate());
91+
+ NodeEscapableHandleScope scope(env->isolate());
92+
93+
Local<Value> result;
94+
if (env->isolate_data()->is_building_snapshot()) {
95+
@@ -1548,6 +1548,12 @@ int Stop(Environment* env, StopFlags::Flags flags) {
96+
return 0;
2997
}
3098

31-
HandleScope::~HandleScope() {
32-
+ if(g_leaveScopeCB) {
33-
+ g_leaveScopeCB(reinterpret_cast<Isolate*>(i_isolate_));
34-
+ }
35-
#ifdef V8_ENABLE_CHECKS
36-
CHECK_EQ(scope_level_, i_isolate_->handle_scope_data()->level);
37-
#endif
38-
@@ -938,6 +955,9 @@ i::Address* HandleScope::CreateHandleForCurrentIsolate(i::Address value) {
39-
#endif // V8_ENABLE_DIRECT_LOCAL
99+
+void SetScopeHandler(const std::function<void(v8::Isolate*)>& enter,
100+
+ const std::function<void(v8::Isolate*)>& exit) {
101+
+ ScopeCB::g_enterScopeCB = enter;
102+
+ ScopeCB::g_leaveScopeCB = exit;
103+
+}
104+
+
105+
} // namespace node
40106

41-
EscapableHandleScopeBase::EscapableHandleScopeBase(Isolate* v8_isolate) {
42-
+ if(g_enterScopeCB) {
43-
+ g_enterScopeCB(v8_isolate);
44-
+ }
45-
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
46-
escape_slot_ = CreateHandle(
47-
i_isolate, i::ReadOnlyRoots(i_isolate).the_hole_value().ptr());
107+
#if !HAVE_INSPECTOR

0 commit comments

Comments
 (0)