Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/lib/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ function workspaceArtifacts(roots) {
if (!metadata) continue;
try {
for (const pkg of JSON.parse(metadata).packages) {
for (const name of [pkg.name, ...pkg.targets.map((target) => target.name)]) {
// Every build script's target is named build-script-build, so its name
// would match each dependency's compiled script, and a missing script
// rebuilds the crate and all its dependents. The package name already
// covers the workspace's own build/<crate>-<hash>/ directories.
const targets = pkg.targets.filter((target) => !target.kind.includes('custom-build'));
for (const name of [pkg.name, ...targets.map((target) => target.name)]) {
names.add(name);
names.add(name.replace(/-/g, '_'));
}
Expand Down Expand Up @@ -169,7 +174,9 @@ const SPECS = {
if (fs.existsSync(path.join(bin, 'rustup')) || fs.existsSync(path.join(bin, 'cargo'))) core.addPath(bin);
},
version() {
return commandOutput('rustc', ['-vV']);
// The revision changes the key when the archived files change, so
// entries saved without dependencies' build scripts are replaced.
return `${commandOutput('rustc', ['-vV'])}\narchive-revision: 2`;
},
},
node: {
Expand Down
4 changes: 4 additions & 0 deletions test/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ test('drops workspace crate artifacts but keeps dependencies', { skip: !hasCargo
const root = path.join(sandbox, 'crate');
write(path.join(root, 'Cargo.toml'), '[package]\nname = "my-app"\nversion = "0.1.0"\nedition = "2021"\n');
write(path.join(root, 'src', 'main.rs'), 'fn main() {}\n');
write(path.join(root, 'build.rs'), 'fn main() {}\n');
const debug = path.join(root, 'target', 'debug');
fs.mkdirSync(path.join(debug, 'deps'), { recursive: true });
// cargo needs the real toolchain home to answer metadata.
Expand All @@ -453,6 +454,9 @@ test('drops workspace crate artifacts but keeps dependencies', { skip: !hasCargo
assert.ok(skip(debug, 'my-app'), 'uplifted binary');
for (const name of [`libserde-${hash}.rlib`, `my_app_utils-${hash}.rlib`, 'serde-1.0']) assert.ok(!skip(deps, name), name);
assert.ok(!skip(path.join(root, 'elsewhere'), 'my-app'), 'uplifted names only next to deps/');
// A dependency's compiled build script, which the workspace's build.rs shares a target name with.
const script = path.join(debug, 'build', `libc-${hash}`);
for (const name of [`build_script_build-${hash}`, `build_script_build-${hash}.d`, 'build-script-build']) assert.ok(!skip(script, name), name);
});

test('keys on lockfiles, falling back to manifests', () => {
Expand Down
Loading