0oscpu v1.0.0
0oscpu
Usage
0oscpu init// package.json
{
"name": "myapp",
"version": "4.5.6",
"scripts": {
"build": "cargo build",
"postbuild": "0oscpu build me && 0oscpu link me",
"build:x": "bash ./just build:x",
"postbuild:x": "0oscpu build",
"postversion": "0oscpu version",
"prepublishOnly": "0oscpu publish"
},
"0oscpu": {
"win32-x64": "target/{x86_64-pc-windows-msvc/,}{release,debug}/myapp.exe",
"linux-arm64": "target/{aarch64-unknown-linux-gnu/,}{release,debug}/myapp",
"linux-x64": "target/{x86_64-unknown-linux-gnu/,}{release,debug}/myapp",
"darwin-arm64": "target/{aarch64-apple-darwin/,}{release,debug}/myapp",
"darwin-x64": "target/{x86_64-apple-darwin/,}{release,debug}/myapp"
},
"optionalDependencies": {
"@0oscpu/win32-x64": "npm:myapp@0.0.0-0oscpu.4.5.6.win32-x64",
"@0oscpu/darwin-arm64": "npm:myapp@0.0.0-0oscpu.4.5.6.darwin-arm64",
"@0oscpu/darwin-x64": "npm:myapp@0.0.0-0oscpu.4.5.6.darwin-x64",
"@0oscpu/linux-x64": "npm:myapp@0.0.0-0oscpu.4.5.6.linux-x64"
}
}#!/bin/bash
set -e
build:x()(
true "${NODE:?}"
for target in \
x86_64-pc-windows-msvc \
aarch64-unknown-linux-gnu \
x86_64-unknown-linux-gnu \
aarch64-apple-darwin \
x86_64-apple-darwin \
; do
cargo build --target "$target" "$@"
done
)
cd "$(dirname "${BASH_SOURCE[0]}")"; c=$1; shift; "$c" "$@"This example uses a ./just <script>-style runner. Why? So that all the scripts can be contained in a single Bash just file. It runs on Windows too using either Git Bash or WSL.
What's going on there? Let's break it down:
"build": "<build-own-target>": This should build only for your local target. Think likecargo buildorgo build. For local development."postbuild": "0oscpu build me && 0oscpu link me": Builds theout/$OS-$ARCH/package folder andnpm link-s it to the current workspace."build:x": "<build-all-targets>": This should build all the targets. Usually this is something likebash ./build-all-targets.sh. Should be run beforenpm publishto build everything."postbuild:x": "0oscpu build": Builds theout/$OS-$ARCH/package folders for every key in thepackage.json's0oscpumap. Should be run beforenpm publish."optionalDependencies": { ... }: This is the magic. We are mapping custom names (@me/$OS-$ARCHby convention) to the magic prerelease versions.