Skip to content

Commit 2ede1bf

Browse files
committed
Set up per-platform builds with native prebuilt binaries where available
1 parent 9374d4f commit 2ede1bf

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

build-release.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# This script takes a target platform as an argument, and then
5+
# builds the server for that platform - installing the correct
6+
# native-built modules for the platform as appropriate.
7+
8+
# ------------------------------------------------------------------------
9+
# Configure everything for the target platform
10+
# ------------------------------------------------------------------------
11+
12+
TARGET_PLATFORM=$1
13+
14+
echo "CONFIGURING FOR $TARGET_PLATFORM"
15+
16+
if [ -z "$TARGET_PLATFORM" ]; then
17+
echo 'A target platform (linux/win32/darwin) is required'
18+
exit 1
19+
fi
20+
21+
TARGET_ARCH=`node -e 'console.log(process.arch)'`
22+
23+
export PATH=./node_modules/.bin:$PATH
24+
25+
# Pick the target platform for prebuild-install:
26+
export npm_config_platform=$TARGET_PLATFORM
27+
# Pick the target platform for node-pre-gyp:
28+
export npm_config_target_platform=$TARGET_PLATFORM
29+
30+
TARGET=$TARGET_PLATFORM-$TARGET_ARCH
31+
32+
# ------------------------------------------------------------------------
33+
# Clean the existing build workspace, to keep targets 100% independent
34+
# ------------------------------------------------------------------------
35+
36+
rm -r ./tmp || true
37+
38+
# ------------------------------------------------------------------------
39+
# Build the package for this platform
40+
# ------------------------------------------------------------------------
41+
42+
env | grep -E 'npm_|TARGET_'
43+
44+
echo
45+
echo "BUILDING FOR $TARGET_PLATFORM"
46+
echo
47+
48+
oclif-dev pack --targets=$TARGET
49+
50+
echo
51+
echo "BUILT"
52+
echo
53+
54+
# ------------------------------------------------------------------------
55+
# Confirm that the installed binaries all support the target platform.
56+
# This is not 100% by any means, but catches obvious mistakes.
57+
# ------------------------------------------------------------------------
58+
59+
# Whitelist (as a regex) for packages that may include binaries for other platforms
60+
PACKAGE_WHITELIST=''
61+
62+
case "$TARGET_PLATFORM" in
63+
linux)
64+
EXPECTED_BIN_STRING="ELF"
65+
# Builds raw on non-Windows, but never used
66+
PACKAGE_WHITELIST="registry-js"
67+
;;
68+
win32)
69+
EXPECTED_BIN_STRING="MS Windows"
70+
PACKAGE_WHITELIST=""
71+
;;
72+
darwin)
73+
EXPECTED_BIN_STRING="Mach-O"
74+
# Builds raw on non-Windows, but never used
75+
PACKAGE_WHITELIST="registry-js"
76+
;;
77+
*)
78+
echo "Unknown platform $TARGET_PLATFORM"
79+
exit 1
80+
;;
81+
esac
82+
83+
echo "CHECKING FOR BAD CONFIG"
84+
echo "EXPECTING: $EXPECTED_BIN_STRING"
85+
echo "WHITELIST: $PACKAGE_WHITELIST"
86+
87+
# Find all *.node files in the build that `file` doesn't describe with the above
88+
NATIVE_BINARIES=$(
89+
find ./tmp/$TARGET/ \
90+
-name '*.node' \
91+
-type f \
92+
-exec file {} \;
93+
)
94+
echo "NATIVE BINS: $NATIVE_BINARIES"
95+
96+
BAD_BINS=$(echo "$NATIVE_BINARIES" | grep -v "$EXPECTED_BIN_STRING" || true)
97+
98+
if [[ ! -z "$PACKAGE_WHITELIST" ]]; then
99+
BAD_BINS=$(echo "$BAD_BINS" | grep -E -v "$PACKAGE_WHITELIST" || true)
100+
fi
101+
102+
if [ `echo "$BAD_BINS" | wc -w` -ne 0 ]; then
103+
echo
104+
echo "***** BUILD FAILED *****"
105+
echo
106+
echo "Invalid build! $TARGET_PLATFORM build has binaries for the wrong platform."
107+
echo "Bad binaries are:"
108+
echo "$BAD_BINS"
109+
echo
110+
echo "---"
111+
112+
exit 1
113+
fi
114+
115+
echo "BUILD SUCCESSFUL"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
],
1515
"scripts": {
1616
"start": "node-dev ./bin/run start",
17-
"build": "npm run build:src && npm run build:pack",
17+
"build": "npm run build:src && npm run build:release",
1818
"build:src": "rm -rf lib && tsc -b && cp -r src/interceptors/terminal-wrappers lib/interceptors",
19-
"build:pack": "oclif-dev manifest && oclif-dev pack",
19+
"build:release": "oclif-dev manifest && ./build-release.sh linux && ./build-release.sh darwin && ./build-release.sh win32",
2020
"prepack": "npm run build:src && oclif-dev manifest",
2121
"test": "TS_NODE_FILES=true mocha -r ts-node/register 'test/**/*.spec.ts'"
2222
},

0 commit comments

Comments
 (0)