Skip to content

Commit e7c733a

Browse files
authored
Merge pull request #921 from neon-bindings/kv/unlink-before-copy
fix(cargo-cp-artifact): Unlink .node files before copying to flush macOS code signature cache
2 parents e7ac0a4 + 871d67a commit e7c733a

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/cargo-cp-artifact/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cargo-cp-artifact",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Copies compiler artifacts emitted by rustc by parsing Cargo metadata",
55
"main": "src/index.js",
66
"files": [

pkgs/cargo-cp-artifact/src/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
const { spawn } = require("child_process");
44
const {
5-
promises: { copyFile, mkdir, stat },
5+
promises: { copyFile, mkdir, stat, unlink },
66
} = require("fs");
7-
const { dirname } = require("path");
7+
const { dirname, extname } = require("path");
88
const readline = require("readline");
99

1010
const { ParseError, getArtifactName, parse } = require("./args");
@@ -122,6 +122,24 @@ async function copyArtifact(filename, outputFile) {
122122
await mkdir(outputDir, { recursive: true });
123123
}
124124

125+
// Apple Silicon (M1, etc.) requires shared libraries to be signed. However,
126+
// the macOS code signing cache isn't cleared when overwriting a file.
127+
// Deleting the file before copying works around the issue.
128+
//
129+
// Unfortunately, this workaround is incomplete because the file must be
130+
// deleted from the location it is loaded. If further steps in the user's
131+
// build process copy or move the file in place, the code signing cache
132+
// will not be cleared.
133+
//
134+
// https://github.com/neon-bindings/neon/issues/911
135+
if (extname(outputFile) === ".node") {
136+
try {
137+
await unlink(outputFile);
138+
} catch (_e) {
139+
// Ignore errors; the file might not exist
140+
}
141+
}
142+
125143
await copyFile(filename, outputFile);
126144
}
127145

test/electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"repository": "https://github.com/electron/electron-quick-start",
1414
"devDependencies": {
1515
"@playwright/test": "^1.23.1",
16-
"cargo-cp-artifact": "^0.1.6",
16+
"cargo-cp-artifact": "^0.1.7",
1717
"electron": "^19.0.7",
1818
"playwright": "^1.23.1"
1919
}

test/napi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "mocha --v8-expose-gc --timeout 5000 --recursive lib"
1010
},
1111
"devDependencies": {
12-
"cargo-cp-artifact": "^0.1.6",
12+
"cargo-cp-artifact": "^0.1.7",
1313
"chai": "^4.3.6",
1414
"mocha": "^10.0.0"
1515
}

0 commit comments

Comments
 (0)