Skip to content

Commit

Permalink
Merge pull request #47 from mcgordonite/multi-arch
Browse files Browse the repository at this point in the history
Add aarch64 binaries
  • Loading branch information
cowboyd authored Dec 18, 2024
2 parents 0e60af3 + 06dabc0 commit 631c550
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-papayas-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ctrlc-windows": minor
---

Added support for arm64.
12 changes: 8 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ jobs:
name: Publish Releases
runs-on: windows-latest
steps:
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.63
- name: Install Rust Toolchain
run: |
rustup install 1.63.0
rustup default 1.63.0
rustup target add x86_64-pc-windows-msvc
rustup target add aarch64-pc-windows-msvc
- uses: volta-cli/action@v3
with:
node-version: 14
Expand All @@ -22,7 +25,8 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/checkout@v3
- run: yarn install
- run: yarn build
- run: yarn build --arch=arm64
- run: yarn build --arch=x64
- name: Publish Releases
uses: thefrontside/actions/synchronize-with-npm@v2
with:
Expand Down
9 changes: 6 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { platform } = require("os");
const { platform, arch } = require("os");
const { join } = require("path");

const archDistDirName = arch() === "arm64" ? "arm64" : "x64";

const native =
platform() === "win32"
? require("../dist/ctrlc-windows.node")
? require(`../dist/${archDistDirName}/ctrlc-windows.node`)
: require("./posix");

module.exports = {
Expand All @@ -12,7 +14,8 @@ module.exports = {
// don't even attempt if the
// process is not running
if (process.kill(pid, 0)) {
native.ctrlc(pid, join(__dirname, "..", "dist/process-killer.exe"));
const processKillerPath = join(__dirname, "..", `dist/${archDistDirName}/process-killer.exe`);
native.ctrlc(pid, processKillerPath);
}
} catch (error) {
if (error.code !== "ESRCH") {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
"triples": {
"defaults": false,
"additional": [
"aarch64-pc-windows-msvc",
"x86_64-pc-windows-msvc"
]
}
},
"author": "Frontside Engineering <[email protected]>",
"license": "MIT",
"scripts": {
"build": "napi build --release && rimraf dist && mkdirp dist && mv ctrlc-windows.node dist && mv ./target/release/process-killer dist",
"build": "node ./scripts/build.js --release",
"test": "mocha -r ts-node/register \"test/**/*.test.ts\"",
"build:debug": "napi build --platform",
"build:debug": "node ./scripts/build.js",
"format": "run-p format:prettier format:rs",
"format:prettier": "prettier . -w",
"format:rs": "cargo fmt",
Expand All @@ -43,7 +44,8 @@
"mocha": "^10.0.0",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"yargs": "^17.7.2"
},
"volta": {
"node": "14.20.0",
Expand Down
57 changes: 57 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node
const { execSync } = require("child_process");
const os = require("os");
const path = require("path");
const mkdirp = require("mkdirp");
const fs = require("fs");

const { arch, release } = require("yargs")
.usage(
"$0",
"build for the given architecture",
(yargs) => {
yargs.option("r", {
alias: "release",
describe: "make a release build",
boolean: true,
require: false,
default: false,
});
yargs.option("a", {
alias: "arch",
describe: "target architecture, defaults to host architecture",
type: "string",
default: os.arch(),
require: false,
});
},
)
.help("help").argv;

if (os.platform() !== "win32") {
console.log("Skipping native build on non-Windows platform");
process.exit(0);
}

const targetTriple = arch === "arm64" ?
"aarch64-pc-windows-msvc" : "x86_64-pc-windows-msvc";

const rootDir = path.resolve(__dirname, "..");
const archDistDir = path.join(rootDir, "dist", arch);

const buildCommand = `yarn napi build --target=${targetTriple}${release ? " --release" : ""}`;
console.log(buildCommand);
execSync(buildCommand, { stdio: "inherit" });

console.log("Moving artifacts to dist directory");
mkdirp.sync(archDistDir);

fs.renameSync(
path.join(rootDir, "target", targetTriple, release ? "release" : "debug", "process-killer.exe"),
path.join(archDistDir, "process-killer.exe"),
);

fs.renameSync(
path.join(rootDir, 'ctrlc-windows.node'),
path.join(archDistDir, 'ctrlc-windows.node'),
);
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,15 @@ cliui@^7.0.2:
strip-ansi "^6.0.0"
wrap-ansi "^7.0.0"

cliui@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa"
integrity sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==
dependencies:
string-width "^4.2.0"
strip-ansi "^6.0.1"
wrap-ansi "^7.0.0"

clone@^1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"
Expand Down Expand Up @@ -2394,7 +2403,7 @@ yargs-parser@^20.2.2:
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a"
integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw==

yargs-parser@^21.0.0:
yargs-parser@^21.0.0, yargs-parser@^21.1.1:
version "21.1.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==
Expand Down Expand Up @@ -2452,6 +2461,19 @@ yargs@^17.1.1:
y18n "^5.0.5"
yargs-parser "^21.0.0"

yargs@^17.7.2:
version "17.7.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
dependencies:
cliui "^8.0.1"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^21.1.1"

[email protected]:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
Expand Down

0 comments on commit 631c550

Please sign in to comment.