From 33a0ce3754ef7ae3b638db47319b21c6996a64dd Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 11 Nov 2026 00:23:32 +0100 Subject: [PATCH 1/2] fix(v8): fetch replace_with crates from crates.io This is a stop-gap fix to keep the canary green. To keep the data in sync we need to genereate the replacement crates from chromium's data. For now this just fetch the crates from crates.io and fail if patches are detected. Signed-off-by: Joyee Cheung --- lib/update-v8/updateCrates.js | 84 ++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/lib/update-v8/updateCrates.js b/lib/update-v8/updateCrates.js index 672cb3c3..ff86933b 100644 --- a/lib/update-v8/updateCrates.js +++ b/lib/update-v8/updateCrates.js @@ -1,6 +1,7 @@ import semver from 'semver'; import * as TOML from 'smol-toml'; import { promises as fs } from 'node:fs'; +import os from 'node:os'; import path from 'node:path'; import { removeDirectory } from './util.js'; @@ -15,6 +16,7 @@ export default function updateCrates() { enumerateTemporalDependencies(), removeExistingCrates(), vendorCrates(), + fetchPlaceholderCrates(), buildManifest(), generateLockfile(), updateGYP(), @@ -78,15 +80,23 @@ function vendorCrates() { await fs.mkdir(nodeVendor); const subtasks = []; - const rustVersions = []; + ctx.rustVersions = []; + ctx.placeholderCrates = []; 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; } + // Fetch replace_with placeholders from crates.io. + // This is a stop-gap fix that only works as long as the + // See https://chromium-review.googlesource.com/c/chromium/src/+/8527739 + if (crate.metadata?.gnrt?.is_placeholder) { + ctx.placeholderCrates.push({ dir, name: crate.name, version: crate.version }); + continue; + } if (crate['rust-version']) { - rustVersions.push(crate['rust-version']); + ctx.rustVersions.push(crate['rust-version']); } subtasks.push({ title: dir, @@ -100,11 +110,6 @@ function vendorCrates() { }); } - 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) { @@ -121,10 +126,75 @@ function vendorCrates() { }; } +// TODO(joyeecheung): Instead of fetching the crates from crates.io, +// generate the replacement crates from Chromium's data. e.g. +// For `replace_with = "//third_party/rust/icu4x_data:lib"` +// in gnrt_config.toml, copy the `.rs.data` files that the dependent +// crates use (`impl_!(Baked)` in their provider.rs) from +// third_party/rust/icu4x_data/src/data/common and generate a data/mod.rs in the +// upstream crate layout. +// See https://github.com/nodejs/node-core-utils/pull/1117 +function fetchPlaceholderCrates() { + return { + title: 'Fetch placeholder crates from crates.io', + skip: (ctx) => ctx.placeholderCrates.length === 0 && 'No placeholder crates', + task: async(ctx) => { + const nodeVendor = path.join(ctx.nodeDir, nodeCratesDir, 'vendor'); + const chromiumPatches = path.join(ctx.nodeDir, chromiumCratesDir, 'patches'); + for (const { dir, name } of ctx.placeholderCrates) { + try { + await fs.access(path.join(chromiumPatches, dir)); + } catch { + continue; + } + throw new Error(`Detected Chromium patches ${name} in ${chromiumPatches}/${dir}, ` + + 'the stop-gap fix of fetching crates from crates.io no longer work.'); + } + + // Vendor a temporary package that depends on on the crates to fetch them. + const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'node-crates-')); + try { + const manifest = { + package: { name: 'placeholder_crates', version: '0.0.0', edition: '2021' }, + dependencies: Object.fromEntries(ctx.placeholderCrates.map(({ name, version }) => ( + [name, { version: `=${version}`, 'default-features': false }] + ))) + }; + await fs.writeFile(path.join(tmpDir, 'Cargo.toml'), TOML.stringify(manifest)); + await fs.mkdir(path.join(tmpDir, 'src')); + await fs.writeFile(path.join(tmpDir, 'src/lib.rs'), ''); + const vendorDir = path.join(tmpDir, 'vendor'); + await forceRunAsync(ctx.cargo, ['vendor', '--quiet', '--versioned-dirs', vendorDir], { + ignoreFailure: false, + spawnArgs: { cwd: tmpDir } + }); + + for (const { dir, name, version } of ctx.placeholderCrates) { + const dest = path.join(nodeVendor, dir); + await fs.cp(path.join(vendorDir, `${name}-${version}`), dest, { recursive: true }); + await fs.writeFile(path.join(dest, '.cargo-checksum.json'), '{"files":{}}\n'); + const crate = TOML.parse(await fs.readFile(path.join(dest, 'Cargo.toml'), 'utf8')); + if (crate.package['rust-version']) { + ctx.rustVersions.push(crate.package['rust-version']); + } + } + } finally { + await removeDirectory(tmpDir); + } + } + }; +} + function buildManifest() { return { title: 'Build new manifest', task: async(ctx) => { + if (ctx.rustVersions.length) { + const msrv = ctx.rustVersions.map(semver.coerce) + .reduce((a, b) => (semver.gt(a, b) ? a : b)); + ctx.msrv = `${msrv.major}.${msrv.minor}`; + } + const sourceManifest = TOML.parse( await fs.readFile(path.join(ctx.nodeDir, chromiumCratesDir, 'Cargo.toml'), 'utf8') ); From c8cc0c610545e671809805aade6dd8ddd3ca29e5 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 11 Nov 2026 23:17:59 +0100 Subject: [PATCH 2/2] fixup! fix(v8): fetch replace_with crates from crates.io --- lib/update-v8/updateCrates.js | 38 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/update-v8/updateCrates.js b/lib/update-v8/updateCrates.js index ff86933b..abcc35c4 100644 --- a/lib/update-v8/updateCrates.js +++ b/lib/update-v8/updateCrates.js @@ -27,6 +27,7 @@ export default function updateCrates() { } const chromiumCratesDir = 'deps/v8/third_party/rust/chromium_crates_io'; +const icu4xDataPatchesDir = 'deps/v8/third_party/rust/icu4x_data/patches'; const nodeCratesDir = 'deps/crates'; function enumerateTemporalDependencies() { @@ -89,7 +90,6 @@ function vendorCrates() { ctx.temporalCAPIDirectory = dir; } // Fetch replace_with placeholders from crates.io. - // This is a stop-gap fix that only works as long as the // See https://chromium-review.googlesource.com/c/chromium/src/+/8527739 if (crate.metadata?.gnrt?.is_placeholder) { ctx.placeholderCrates.push({ dir, name: crate.name, version: crate.version }); @@ -126,6 +126,17 @@ function vendorCrates() { }; } +// This is a stop-gap fix that only works as long as the Chromium doesn't +// patch the data Node.js uses with third_party/rust/icu4x_data/patches/ +// or the locale filters. See third_party/rust/icu4x_data/patches/README.md +// for the markers affected. + +// Current markers used by Node.js: +// icu_locale_fallback: locale_likely_subtags_language +// locale_parents +// icu_calendar: calendar_japanese_modern +// calendar_preferred +// calendar_week // TODO(joyeecheung): Instead of fetching the crates from crates.io, // generate the replacement crates from Chromium's data. e.g. // For `replace_with = "//third_party/rust/icu4x_data:lib"` @@ -138,20 +149,15 @@ function fetchPlaceholderCrates() { return { title: 'Fetch placeholder crates from crates.io', skip: (ctx) => ctx.placeholderCrates.length === 0 && 'No placeholder crates', - task: async(ctx) => { + task: async(ctx, task) => { const nodeVendor = path.join(ctx.nodeDir, nodeCratesDir, 'vendor'); - const chromiumPatches = path.join(ctx.nodeDir, chromiumCratesDir, 'patches'); - for (const { dir, name } of ctx.placeholderCrates) { - try { - await fs.access(path.join(chromiumPatches, dir)); - } catch { - continue; - } - throw new Error(`Detected Chromium patches ${name} in ${chromiumPatches}/${dir}, ` + - 'the stop-gap fix of fetching crates from crates.io no longer work.'); + + const patches = await listPatches(path.join(ctx.nodeDir, icu4xDataPatchesDir)); + if (patches.length) { + task.title += `, ${icu4xDataPatchesDir} affects: ${patches.join(', ')})`; } - // Vendor a temporary package that depends on on the crates to fetch them. + // Vendor a temporary package that depends on the crates to fetch them. const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'node-crates-')); try { const manifest = { @@ -185,6 +191,14 @@ function fetchPlaceholderCrates() { }; } +async function listPatches(dir) { + try { + return (await fs.readdir(dir)).filter((file) => file.endsWith('.patch')).sort(); + } catch { + return []; + } +} + function buildManifest() { return { title: 'Build new manifest',