-
Notifications
You must be signed in to change notification settings - Fork 131
feat(v8)!: synchronize Rust crates with major updates #1117
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
2 commits
Select commit
Hold shift + click to select a range
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
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,189 @@ | ||
| import semver from 'semver'; | ||
| import * as TOML from 'smol-toml'; | ||
| import { promises as fs } from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { removeDirectory } from './util.js'; | ||
| import { forceRunAsync } from '../run.js'; | ||
|
|
||
| export default function updateCrates() { | ||
| return { | ||
| title: 'Update Rust crates', | ||
| skip: (ctx) => ctx.newVersion.majorMinor < 139, | ||
| task: (ctx, task) => { | ||
| return task.newListr([ | ||
| enumerateTemporalDependencies(), | ||
| removeExistingCrates(), | ||
| vendorCrates(), | ||
| buildManifest(), | ||
| generateLockfile(), | ||
| updateGYP(), | ||
| commitChanges() | ||
| ]); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| const chromiumCratesDir = 'deps/v8/third_party/rust/chromium_crates_io'; | ||
| const nodeCratesDir = 'deps/crates'; | ||
|
|
||
| function enumerateTemporalDependencies() { | ||
| return { | ||
| title: 'Enumerate Temporal dependency tree', | ||
| task: async(ctx) => { | ||
| const tree = await forceRunAsync( | ||
| ctx.cargo, | ||
| ['tree', '-Z', 'bindeps', '--package', 'temporal_capi', '--prefix', 'none'], | ||
| { | ||
| ignoreFailure: false, | ||
| captureStdout: true, | ||
| spawnArgs: { cwd: path.join(ctx.nodeDir, chromiumCratesDir) } | ||
| } | ||
| ); | ||
| const crates = new Set(); | ||
| for (const crate of tree.trimEnd().split('\n').sort()) { | ||
| const [name, version] = crate.split(' ', 2); | ||
| crates.add(`${name}@${version.substring(1)}`); | ||
| } | ||
| ctx.temporalCrates = crates; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function removeExistingCrates() { | ||
| return { | ||
| title: 'Remove existing crates', | ||
| task: (ctx) => removeDirectory(path.join(ctx.nodeDir, nodeCratesDir, 'vendor')) | ||
| }; | ||
| } | ||
|
|
||
| // Note that the crates vendored in third_party/rust/chromium_crates_io already have any custom | ||
| // Chromium patches applied by gnrt, so we don't need to worry about patching them ourselves. | ||
| function vendorCrates() { | ||
| return { | ||
| title: 'Copy vendored crates', | ||
| task: async(ctx, task) => { | ||
| const chromiumVendor = path.join(ctx.nodeDir, chromiumCratesDir, 'vendor'); | ||
| const nodeVendor = path.join(ctx.nodeDir, nodeCratesDir, 'vendor'); | ||
| await fs.mkdir(nodeVendor); | ||
|
|
||
| const subtasks = []; | ||
| const rustVersions = []; | ||
| for (const dir of await fs.readdir(chromiumVendor)) { | ||
| const crate = await getCrateInfo(dir); | ||
| if (!crate || !ctx.temporalCrates.has(`${crate.name}@${crate.version}`)) continue; | ||
| if (crate.name === 'temporal_capi') { | ||
| ctx.temporalCAPIDirectory = dir; | ||
| } | ||
| if (crate['rust-version']) { | ||
| rustVersions.push(crate['rust-version']); | ||
| } | ||
| subtasks.push({ | ||
| title: dir, | ||
| task: async(ctx) => { | ||
| await fs.cp( | ||
| path.join(chromiumVendor, dir), | ||
| path.join(nodeVendor, dir), | ||
| { recursive: true } | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| if (rustVersions.length) { | ||
| const msrv = rustVersions.map(semver.coerce).reduce((a, b) => (semver.gt(a, b) ? a : b)); | ||
| ctx.msrv = `${msrv.major}.${msrv.minor}`; | ||
| } | ||
|
|
||
| return task.newListr(subtasks, { concurrent: ctx.concurrent }); | ||
|
|
||
| async function getCrateInfo(crate) { | ||
| try { | ||
| const manifest = TOML.parse( | ||
| await fs.readFile(path.join(chromiumVendor, crate, 'Cargo.toml'), 'utf8') | ||
| ); | ||
| return manifest.package; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function buildManifest() { | ||
| return { | ||
| title: 'Build new manifest', | ||
| task: async(ctx) => { | ||
| const sourceManifest = TOML.parse( | ||
| await fs.readFile(path.join(ctx.nodeDir, chromiumCratesDir, 'Cargo.toml'), 'utf8') | ||
| ); | ||
|
|
||
| const header = | ||
| '# This manifest is generated by node-core-utils. Do not modify it directly.\n\n'; | ||
| const manifest = { | ||
| package: { | ||
| edition: sourceManifest.package.edition, | ||
| name: 'node_crates', | ||
| version: `${ctx.newVersion.major}.${ctx.newVersion.minor}.${ctx.newVersion.build}` | ||
| }, | ||
| lib: { | ||
| 'crate-type': ['staticlib'] | ||
| }, | ||
| dependencies: {} | ||
| }; | ||
| if (ctx.msrv) { | ||
| manifest.package['rust-version'] = ctx.msrv; | ||
| } | ||
| for (const crate of ctx.temporalCrates) { | ||
| const name = crate.split('@', 1)[0]; | ||
| if (name === 'temporal_capi' || typeof sourceManifest.dependencies[name] === 'object') { | ||
| manifest.dependencies[name] = sourceManifest.dependencies[name]; | ||
| } | ||
| } | ||
|
|
||
| const cargoTOML = header + TOML.stringify(manifest); | ||
| await fs.writeFile(path.join(ctx.nodeDir, nodeCratesDir, 'Cargo.toml'), cargoTOML); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function generateLockfile() { | ||
| return { | ||
| title: 'Generate lockfile', | ||
| task: (ctx) => forceRunAsync(ctx.cargo, ['generate-lockfile', '--quiet', '--offline'], { | ||
| ignoreFailure: false, | ||
| spawnArgs: { cwd: path.join(ctx.nodeDir, nodeCratesDir) } | ||
| }) | ||
| }; | ||
| } | ||
|
|
||
| function updateGYP() { | ||
| return { | ||
| title: 'Update include path in crates.gyp', | ||
| task: async(ctx, task) => { | ||
| const filePath = path.join(ctx.nodeDir, nodeCratesDir, 'crates.gyp'); | ||
| let gyp = await fs.readFile(filePath, 'utf8'); | ||
| const [definition, currentDirectory] = gyp.match(/'temporal_capi_dir': '(.+?)'/); | ||
| if (currentDirectory === ctx.temporalCAPIDirectory) { | ||
| task.skip('crates.gyp already up-to-date'); | ||
| return; | ||
| } | ||
| gyp = gyp.replace(definition, `'temporal_capi_dir': '${ctx.temporalCAPIDirectory}'`); | ||
| await fs.writeFile(filePath, gyp); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function commitChanges() { | ||
| return { | ||
| title: 'Commit changes', | ||
| task: async(ctx) => { | ||
| await ctx.execGitNode('add', ['--force', 'deps/crates']); | ||
| await ctx.execGitNode( | ||
| 'commit', | ||
| ['-m', `deps: update Rust crates for V8 ${ctx.newVersion}`] | ||
| ); | ||
| } | ||
| }; | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this change? Without it, this command fails on my computer with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like Chromium sets
RUSTC_BOOTSTRAP=1in its toolchain, does this work with your setup?The issue with
+xyzis that it only works in a rustup environment.