Repository navigation
fix: compile Node 24+ prebuilds as C++20 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4af5018
fix: compile Node 24+ prebuilds as C++20
cursoragent d089870
test: run C++ standard checks in the test suite
cursoragent d821f7c
test: ignore inherited Electron runtime in Node standard checks
cursoragent 881aa05
ci: name the Publish and Tests workflows
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| name: Publish | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| name: Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| const assert = require("assert"); | ||
| const fs = require("fs"); | ||
| const os = require("os"); | ||
| const path = require("path"); | ||
| const { spawnSync } = require("child_process"); | ||
| const test = require("node:test"); | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| const script = path.join(__dirname, "defaultCxxStandard.js"); | ||
|
|
||
| function writeHeaders(builtWithElectron) { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), "nodegit-headers-")); | ||
| const includeDir = path.join(root, "include", "node"); | ||
| fs.mkdirSync(includeDir, { recursive: true }); | ||
| const variables = builtWithElectron | ||
| ? "{ 'variables': { 'built_with_electron': 1 } }" | ||
| : "{ 'variables': { 'node_module_version': 137 } }"; | ||
| fs.writeFileSync(path.join(includeDir, "config.gypi"), variables); | ||
| return root; | ||
| } | ||
|
|
||
| function cxxStandard(target, nodeRootDir, env) { | ||
| const args = [script, target]; | ||
| if (nodeRootDir) { | ||
| args.push(nodeRootDir); | ||
| } | ||
| // Drop an inherited Electron or NW.js runtime so Node fixtures stay Node | ||
| // fixtures. Callers that need that runtime pass it in env. | ||
| const childEnv = Object.assign({}, process.env); | ||
| delete childEnv.npm_config_runtime; | ||
| if (env) { | ||
| Object.assign(childEnv, env); | ||
| } | ||
| const result = spawnSync(process.execPath, args, { | ||
| encoding: "utf8", | ||
| env: childEnv, | ||
| }); | ||
| assert.strictEqual(result.status, 0, result.stderr); | ||
| return result.stdout; | ||
| } | ||
|
|
||
| test("node prebuild targets use C++20 from Node 23 up", () => { | ||
| const headers = writeHeaders(false); | ||
| assert.strictEqual(cxxStandard("22.22.0", headers), "17"); | ||
| assert.strictEqual(cxxStandard("23.0.0", headers), "20"); | ||
| assert.strictEqual(cxxStandard("24.18.0", headers), "20"); | ||
| assert.strictEqual(cxxStandard("26.5.0", headers), "20"); | ||
| }); | ||
|
|
||
| test("electron targets keep the electron C++ mapping", () => { | ||
| const headers = writeHeaders(true); | ||
| assert.strictEqual(cxxStandard("24.0.0", headers), "17"); | ||
| assert.strictEqual(cxxStandard("31.7.7", headers), "17"); | ||
| assert.strictEqual(cxxStandard("32.2.0", headers), "20"); | ||
| }); | ||
|
|
||
| test("node prebuild targets ignore an inherited electron runtime", () => { | ||
| const headers = writeHeaders(false); | ||
| const previous = process.env.npm_config_runtime; | ||
| process.env.npm_config_runtime = "electron"; | ||
| try { | ||
| assert.strictEqual(cxxStandard("23.0.0", headers), "20"); | ||
| assert.strictEqual(cxxStandard("24.18.0", headers), "20"); | ||
| assert.strictEqual( | ||
| cxxStandard("28.0.0", undefined, { npm_config_runtime: "electron" }), | ||
| "17" | ||
| ); | ||
| process.env.npm_config_runtime = "node-webkit"; | ||
| assert.strictEqual(cxxStandard("24.18.0", headers), "20"); | ||
| } finally { | ||
| if (previous === undefined) { | ||
| delete process.env.npm_config_runtime; | ||
| } else { | ||
| process.env.npm_config_runtime = previous; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| test("npm electron runtime is treated as electron even without headers", () => { | ||
| assert.strictEqual( | ||
| cxxStandard("28.0.0", undefined, { npm_config_runtime: "electron" }), | ||
| "17" | ||
| ); | ||
| assert.strictEqual( | ||
| cxxStandard("34.0.0", undefined, { npm_config_runtime: "electron" }), | ||
| "20" | ||
| ); | ||
| }); | ||
|
|
||
| test("an unspecified target follows the running Node ABI", () => { | ||
| const abi = Number.parseInt(process.versions.modules, 10); | ||
| const expected = abi >= 131 ? "20" : abi >= 108 ? "17" : "14"; | ||
| assert.strictEqual(cxxStandard("none"), expected); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.