Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MacOS arm64 support #42

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion .github/workflows/nexe-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ jobs:
# TODO: Bump to windows-latest once it can be solved how to install Python2
# such that the Node.js build system can detect it.
os: [ubuntu-latest, windows-2019, macos-latest]
node_version: ['14.16.0', '14.18.0', '14.18.1', '16.11.0', '16.13.0', '16.13.1', '16.19.0', '18.14.0']
node_version: ['18.14.0'] # ['14.16.0', '14.18.0', '14.18.1', '16.11.0', '16.13.0', '16.13.1', '16.19.0', '18.14.0']
node_arch: [x64]
include:
- { os: macos-latest, node_version: '16.19.0', node_arch: arm64 }
#- { os: macos-latest, node_version: '18.14.0', node_arch: arm64 }

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -65,6 +69,7 @@ jobs:
echo "build_occurred=$build_occurred" >> $GITHUB_OUTPUT
env:
NODE_VERSION: ${{ matrix.node_version }}
NODE_ARCH: ${{ matrix.node_arch }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CREATE_RELEASE: "${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}"

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,27 @@ Enjoy 🚀
1. Args:
1. Command (`build` or `build-check`)
2. Node.js version to build for.
3. OS arch to build, options: `x64`, `arm64`. (optional)
2. Environmental Variables: None
3. Files created:
1. Nexe build artifact (`$repo_dir/dist/$os_env-$os_arch-$node_target`)
4. Exit codes:
1. `0`: Success
2. `*`: Failure

# TMP

https://github.com/nodejs/node/issues/40350
https://github.com/nodejs/node-v0.x-archive/issues/5195
https://github.com/nodejs/node/issues/37309
https://github.com/sjitech/build-nodejs-for-android
https://github.com/briansmith/ring/issues/1442
https://github.com/nodejs/node/issues/37441
https://github.com/nodejs/node/issues/40302
https://github.com/nodejs/build/issues/2474
https://github.com/eclipse-openj9/openj9/issues/5018
https://github.com/nodejs/node/blob/main/BUILDING.md
https://github.com/dotnet/runtime/issues/41133
https://github.com/openssl/openssl/issues/12254
https://embeddedartistry.com/blog/2017/10/11/demystifying-arm-floating-point-compiler-options/
https://github.com/nodejs/gyp-next/pull/78
43 changes: 28 additions & 15 deletions bin/build_nexe
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ source "$script_dir/bash_utils.sh"
os_env="$(get_os_type)"

node_target="$2"
if [ "$os_env" = "mac" ]; then
os_arch="$(uname -m)"
else
os_arch="$(arch)"
target_arch="$3"
os_arch=""
if [ "$os_arch" = "" ]; then
if [ "$os_env" = "mac" ]; then
os_arch="$(uname -m)"
else
os_arch="$(arch)"
fi
if [ "$os_arch" = "x86_64" ]; then
os_arch="x64"
fi
fi
if [ "$os_arch" = "x86_64" ]; then
os_arch="x64"
fi
if [ "$os_arch" != "x64" ]; then
echo "Error! Unsupported architecture: $os_arch"
# Validate OS arch
if [ "$target_arch" != "x64" ] && [ "$target_arch" != "arm64" ]; then
echo "Error! Unsupported architecture: $target_arch"
exit 1
fi
nexe_target="${os_arch}-$node_target"
nexe_target="$target_arch-$node_target"

help_text="
build_nexe
Expand Down Expand Up @@ -101,16 +106,24 @@ function main(){
;;
esac

python2_path="$(which python2)"
python3_path="$(which python3)"
python2_path="$(command -v python2 || true)"
python3_path="$(command -v python3)"
echo "python2_path=$python2_path"
echo "python3_path=$python3_path"
nexe_part_1_cmd="nexe --build --verbose --no-mange --target=$nexe_target --make=-j$cpu_core_count"
nexe_part_1_cmd="nexe --build --verbose --no-mange --target=$nexe_target --make=DESTCPU=$target_arch --make=-j$cpu_core_count"
nexe_part_2_cmd="--configure=--openssl-no-asm --configure=--without-snapshot --configure=--without-inspector --configure=--without-intl --configure=--with-arm-fpu=neon --configure=--with-arm-float-abi=hard --configure=--cross-compiling"
# if [ "$target_arch" != "$os_arch"] ; then
# nexe_part_2_cmd="$nexe_part_2_cmd --configure=--cross-compiling"
# fi
nexe_part_3_cmd="-o $nexe_no_mangle_path '$repo_dir/index.js'"

echo "console.log('TEST NEXE SCRIPT'); console.log(process.version); var os = require('os'); console.log('os.userInfo() =', os.userInfo());" > "$repo_dir/index.js"
echo "console.log('TEST NEXE SCRIPT'); console.log(process.version); var os = require('os'); console.log('os.arch() =', os.arch()); console.log('os.userInfo() =', os.userInfo());" > "$repo_dir/index.js"
echo "Building $nexe_no_mangle_name (python 3)"
nexe_cmd="$nexe_part_1_cmd --python=$python3_path $nexe_part_3_cmd"

export NEON32_CFLAGS="-march=armv7-a -mfloat-abi=hard -mfpu=neon"
export NEON64_CFLAGS="-march=armv8-a -mfloat-abi=hard"

nexe_cmd="$nexe_part_1_cmd --python=$python3_path $nexe_part_2_cmd $nexe_part_3_cmd"
echo " $nexe_cmd"
set +e
time npx $nexe_cmd || build_failed="true"
Expand Down
16 changes: 11 additions & 5 deletions bin/check_asset
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const osNameMap = {
'win32': 'windows',
};
const archNameMap = {
'arm64': 'arm64',
'x64': 'x64',
'x32': 'x86',
};
const osArch = os.arch();

async function main() {
try {
Expand All @@ -42,21 +42,27 @@ async function main() {
console.log("Please provide target repo commit for release as second arg (use `git rev-parse HEAD`)");
process.exit(1);
}
if (myArgs.length === 3) {
assert(myArgs[2] === '--no-create-release', `Invalid flag given: ${myArgs[2]}`);
if (myArgs.length === 2) {
console.log("Please provide target OS for release as third arg (options: x64, arm64)");
process.exit(1);
}
if (myArgs.length === 4) {
assert(myArgs[3] === '--no-create-release', `Invalid flag given: ${myArgs[3]}`);
doCreate = false;
}
const apiToken = process.env.GITHUB_TOKEN;
if (!apiToken) {
console.log("Please provide github API token via env. var. GITHUB_TOKEN");
process.exit(1);
}
const targetNodeVersion = myArgs[0];
const releaseCommitish = myArgs[1];
const osArch = myArgs[2];
assert(Object.keys(osNameMap).includes(process.platform), `Unsupported platform: ${process.platform}`);
assert(Object.keys(archNameMap).includes(osArch), `Unsupported architecture: ${osArch}`);
const targetOs = osNameMap[process.platform];
const targetArch = archNameMap[osArch];
const targetNodeVersion = myArgs[0];
const releaseCommitish = myArgs[1];

const nexeAssetName = `${targetOs}-${targetArch}-${targetNodeVersion}`;
const packageData = getPackgeData();
const nexeVersion = packageData.dependencies.nexe.replace('^','');
Expand Down
10 changes: 6 additions & 4 deletions bin/run_cd
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ script_dir="$repo_dir/bin"
source "$script_dir/bash_utils.sh"
os_env="$(get_os_type)"

NODE_ARCH="${NODE_ARCH:-x64}"
if [ "$NODE_VERSION" = "" ]; then
echo "Please set NODE_VERSION env. var."
exit 1
else
echo "NODE_VERSION=$NODE_VERSION"
echo "NODE_ARCH=$NODE_ARCH"
fi

if [ "$GITHUB_TOKEN" = "" ]; then
Expand Down Expand Up @@ -69,7 +71,7 @@ fi

echo "Running: bin/check_asset"
set +e
$script_dir/check_asset "$NODE_VERSION" "$GIT_COMMIT" $check_asset_flags
$script_dir/check_asset "$NODE_VERSION" "$GIT_COMMIT" "$NODE_ARCH" $check_asset_flags
exit_code="$?"
set -e

Expand All @@ -81,9 +83,9 @@ case "$exit_code" in
"10")
echo "Running: bin/install_dependencies"
$script_dir/install_dependencies || exit 2
echo "Running: bin/build_nexe build $NODE_VERSION"
$script_dir/build_nexe build "$NODE_VERSION" || exit 3
echo "Finished: bin/build_nexe build $NODE_VERSION"
echo "Running: bin/build_nexe build $NODE_VERSION $NODE_ARCH"
$script_dir/build_nexe build "$NODE_VERSION" "$NODE_ARCH" || exit 3
echo "Finished: bin/build_nexe build $NODE_VERSION $NODE_ARCH"
;;
*)
echo "Error exit code detected ($exit_code) from check_asset script! Crashing."
Expand Down