Skip to content

Commit 6cfcf3c

Browse files
authored
CI: build Linux x64 binaries directly on runner (no docker) (#6917)
* CI: build Linux x64 binaries directly on runner (no docker) * Check that all Linux executables are statically linked
1 parent c0694b6 commit 6cfcf3c

File tree

2 files changed

+63
-44
lines changed

2 files changed

+63
-44
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,14 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
os: [
28-
macos-13, # x64
29-
macos-14, # ARM
30-
ubuntu-latest, # x64
31-
buildjet-2vcpu-ubuntu-2204-arm, # ARM
32-
windows-latest,
33-
]
3427
include:
35-
- os: macos-13
28+
- os: macos-13 # x64
3629
rust-target: x86_64-apple-darwin
37-
- os: macos-14
30+
- os: macos-14 # ARM
3831
rust-target: aarch64-apple-darwin
39-
- os: ubuntu-latest
32+
- os: ubuntu-latest # x64
4033
rust-target: x86_64-unknown-linux-musl
41-
- os: buildjet-2vcpu-ubuntu-2204-arm
34+
- os: buildjet-2vcpu-ubuntu-2204-arm # ARM
4235
rust-target: aarch64-unknown-linux-musl
4336
- os: windows-latest
4437
rust-target: x86_64-pc-windows-gnu
@@ -96,13 +89,10 @@ jobs:
9689
# for more info.
9790
# The container already comes with all required tools pre-installed
9891
# (see https://github.com/rescript-lang/docker-rescript-ci-build/blob/main/Dockerfile).
99-
static-binaries-linux:
100-
strategy:
101-
fail-fast: false
102-
matrix:
103-
os: [ubuntu-latest, buildjet-2vcpu-ubuntu-2204-arm]
104-
105-
runs-on: ${{matrix.os}}
92+
# Note: Static ARM64 binaries cannot be built directly on Ubuntu runner because of
93+
# https://github.com/ocaml/opam-repository/issues/26216
94+
static-binaries-linux-arm:
95+
runs-on: buildjet-2vcpu-ubuntu-2204-arm
10696

10797
steps:
10898
- name: Checkout
@@ -131,7 +121,7 @@ jobs:
131121
upload-linux-arm64-binaries:
132122
needs:
133123
- build-rewatch
134-
- static-binaries-linux
124+
- static-binaries-linux-arm
135125

136126
runs-on: buildjet-2vcpu-ubuntu-2204-arm
137127

@@ -140,7 +130,6 @@ jobs:
140130
uses: actions/checkout@v4
141131

142132
- name: Download static linux binaries
143-
if: runner.os == 'Linux'
144133
uses: actions/download-artifact@v4
145134
with:
146135
name: static-binaries-linux-${{ runner.arch }}
@@ -171,18 +160,19 @@ jobs:
171160
build:
172161
needs:
173162
- build-rewatch
174-
- static-binaries-linux
175163

176164
strategy:
177165
fail-fast: false
178166
matrix:
179-
os: [
180-
macos-13, # x64
181-
macos-14, # ARM
182-
ubuntu-latest,
183-
windows-latest,
184-
]
185-
ocaml_compiler: [5.2.0]
167+
include:
168+
- os: macos-13 # x64
169+
ocaml_compiler: 5.2.0
170+
- os: macos-14 # ARM
171+
ocaml_compiler: 5.2.0
172+
- os: ubuntu-latest # x64
173+
ocaml_compiler: ocaml-variants.5.2.0+options,ocaml-option-static
174+
- os: windows-latest
175+
ocaml_compiler: 5.2.0
186176

187177
runs-on: ${{matrix.os}}
188178

@@ -204,12 +194,6 @@ jobs:
204194
with:
205195
fetch-depth: 2 # to be able to check for changes in subfolder jscomp/syntax later
206196

207-
- name: Download static linux binaries
208-
if: runner.os == 'Linux'
209-
uses: actions/download-artifact@v4
210-
with:
211-
name: static-binaries-linux-${{ runner.arch }}
212-
213197
- name: Get artifact dir name
214198
run: node .github/workflows/get_artifact_dir_name.js
215199

@@ -219,13 +203,6 @@ jobs:
219203
name: rewatch-${{ env.artifact_dir_name }}
220204
path: rewatch
221205

222-
- name: Make static linux binaries executable
223-
if: runner.os == 'Linux'
224-
run: |
225-
chmod +x ninja/ninja
226-
chmod +x rewatch/rewatch
227-
chmod +x _build/install/default/bin/*
228-
229206
- name: Install dependencies (Linux)
230207
if: runner.os == 'Linux'
231208
uses: awalsh128/[email protected]
@@ -239,6 +216,11 @@ jobs:
239216
with:
240217
python-version: '3.10'
241218

219+
# matrix.ocaml_compiler may contain commas
220+
- name: Get OPAM cache key
221+
shell: bash
222+
run: echo "opam_cache_key=opam-env-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV
223+
242224
- name: Restore OPAM environment
243225
id: cache-opam-env
244226
uses: actions/cache/restore@v4
@@ -250,7 +232,7 @@ jobs:
250232
.opam-path
251233
D:\cygwin
252234
D:\.opam
253-
key: opam-env-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}
235+
key: ${{ env.opam_cache_key }}
254236

255237
- name: Use OCaml ${{matrix.ocaml_compiler}}
256238
uses: ocaml/[email protected]
@@ -286,7 +268,7 @@ jobs:
286268
.opam-path
287269
D:\cygwin
288270
D:\.opam
289-
key: opam-env-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}
271+
key: ${{ env.opam_cache_key }}
290272

291273
- name: Use cached OPAM environment
292274
if: steps.cache-opam-env.outputs.cache-hit == 'true'
@@ -334,6 +316,10 @@ jobs:
334316
if: runner.os != 'Linux'
335317
run: opam exec -- dune build --display quiet --profile release
336318

319+
- name: Build compiler (Linux static)
320+
if: runner.os == 'Linux'
321+
run: opam exec -- dune build --display quiet --profile static
322+
337323
- name: Use Node.js
338324
uses: actions/setup-node@v4
339325
with:
@@ -352,6 +338,12 @@ jobs:
352338
if: runner.os != 'Linux'
353339
run: node scripts/buildNinjaBinary.js
354340

341+
- name: Build ninja (Linux static)
342+
if: runner.os == 'Linux'
343+
env:
344+
LDFLAGS: -static
345+
run: node scripts/buildNinjaBinary.js
346+
355347
- name: Copy exes to platform bin dirs
356348
run: node ./scripts/copyExes.js
357349

scripts/moveArtifacts.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -e
33

4+
check_statically_linked() {
5+
local dir=$1
6+
local all_statically_linked=true
7+
8+
for file in "$dir"/*; do
9+
if [ -f "$file" ]; then
10+
if file "$file" | grep -Eq "statically linked|static-pie linked"; then
11+
echo "$file is statically linked."
12+
else
13+
echo "$file is NOT statically linked."
14+
all_statically_linked=false
15+
fi
16+
fi
17+
done
18+
19+
if $all_statically_linked; then
20+
echo "All files in $dir are statically linked executables."
21+
else
22+
echo "Error: Not all files in $dir are statically linked executables."
23+
exit 1
24+
fi
25+
}
26+
427
chmod +x binaries-*/*.exe
528

629
mv binaries-darwin darwin
@@ -11,3 +34,7 @@ mv binaries-win32 win32
1134

1235
mv lib-ocaml lib/ocaml
1336
mv ninja/COPYING ninja.COPYING
37+
38+
check_statically_linked "linux"
39+
check_statically_linked "linuxarm64"
40+

0 commit comments

Comments
 (0)