@@ -12,6 +12,142 @@ permissions:
1212 contents : read
1313
1414jobs :
15+ binary :
16+ runs-on : ${{ matrix.platform.runner }}
17+ env :
18+ ZIG_VERSION : 0.13.0
19+ strategy :
20+ matrix :
21+ platform :
22+ - runner : ubuntu-22.04
23+ target : x86_64
24+ - runner : ubuntu-22.04
25+ target : aarch64
26+ - runner : macos-13
27+ target : x86_64
28+ - runner : macos-14
29+ target : aarch64
30+ - runner : windows-latest
31+ target : x86_64
32+ steps :
33+ - uses : actions/checkout@v5
34+ with :
35+ persist-credentials : false
36+
37+ - name : Prepare target
38+ shell : bash
39+ env :
40+ RUNNER_OS : ${{ runner.os }}
41+ PLATFORM_TARGET : ${{ matrix.platform.target }}
42+ run : |
43+ target="${PLATFORM_TARGET}"
44+
45+ if [[ "${RUNNER_OS}" == "Linux" ]]; then
46+ target+="-unknown-linux-gnu"
47+ elif [[ "${RUNNER_OS}" == "macOS" ]]; then
48+ target+="-apple-darwin"
49+ elif [[ "${RUNNER_OS}" == "Windows" ]]; then
50+ target+="-pc-windows-msvc"
51+ fi
52+
53+ echo "TARGET=${target}" >> $GITHUB_ENV
54+
55+ - uses : actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c
56+ with :
57+ cache : ${{ !startsWith(github.ref, 'refs/tags/') }}
58+ target : ${{ env.TARGET }}
59+
60+ - name : Cache Zig toolchain
61+ if : ${{ runner.os == 'Linux' && matrix.platform.target == 'aarch64' }}
62+ id : cache-zig
63+ uses : actions/cache@v4
64+ with :
65+ path : |
66+ zig-linux-x86_64-${{ env.ZIG_VERSION }}
67+ ~/.cargo/bin/cargo-zigbuild
68+ key : ${{ runner.os }}-zig-toolchain-${{ env.ZIG_VERSION }}
69+
70+ - name : Install Zig and cargo-zigbuild
71+ if : ${{ runner.os == 'Linux' && matrix.platform.target == 'aarch64' && steps.cache-zig. outputs.cache-hit != 'true' }}
72+ shell : bash
73+ run : |
74+ wget -q "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-x86_64-${ZIG_VERSION}.tar. xz"
75+ tar xf "zig-linux-x86_64-${ZIG_VERSION}.tar.xz"
76+ cargo install cargo-zigbuild
77+
78+ - name : Add Zig to PATH
79+ if : ${{ runner.os == 'Linux' && matrix.platform.target == 'aarch64' }}
80+ shell : bash
81+ run : echo "$PWD/zig-linux-x86_64-${ZIG_VERSION}" >> $GITHUB_PATH
82+
83+ - name : Build release binary
84+ shell : bash
85+ env :
86+ RUNNER_OS : ${{ runner.os }}
87+ PLATFORM_TARGET : ${{ matrix.platform.target }}
88+ PLATFORM_RUNNER : ${{ matrix.platform.runner }}
89+ run : |
90+ if [[ "${RUNNER_OS}" == "Linux" && "${PLATFORM_TARGET}" == "aarch64" ]]; then
91+ cargo zigbuild --release --target "${TARGET}"
92+ else
93+ cargo build --verbose --release --target "${TARGET}"
94+ fi
95+
96+ if [[ "${PLATFORM_RUNNER}" == windows-* ]]; then
97+ bin="./target/${TARGET}/release/djls.exe"
98+ else
99+ bin="./target/${TARGET}/release/djls"
100+ fi
101+
102+ echo "BIN=${bin}" >> $GITHUB_ENV
103+
104+ - name : Determine binary name
105+ shell : bash
106+ run : |
107+ target="${TARGET}"
108+ name="djls"
109+
110+ if [[ "$target" == *linux* ]]; then
111+ name+="-linux"
112+ elif [[ "$target" == *apple* ]]; then
113+ name+="-darwin"
114+ elif [[ "$target" == *windows* ]]; then
115+ name+="-windows"
116+ fi
117+
118+ if [[ "$target" == x86_64* ]]; then
119+ name+="-x64"
120+ elif [[ "$target" == aarch64* ]]; then
121+ name+="-arm64"
122+ fi
123+
124+ if [[ "$target" == *windows* ]]; then
125+ name+=".exe"
126+ fi
127+
128+ echo "BINARY_NAME=${name}" >> $GITHUB_ENV
129+
130+ - name : Strip release binary (Unix)
131+ if : ${{ runner.os != 'Windows' }}
132+ shell : bash
133+ env :
134+ RUNNER_OS : ${{ runner.os }}
135+ PLATFORM_TARGET : ${{ matrix.platform.target }}
136+ run : |
137+ if [[ "${RUNNER_OS}" == "Linux" && "${PLATFORM_TARGET}" == "aarch64" ]]; then
138+ sudo apt-get update
139+ sudo apt-get install -y binutils-aarch64-linux-gnu
140+ aarch64-linux-gnu-strip "${BIN}"
141+ else
142+ strip "${BIN}"
143+ fi
144+
145+ - name : Upload binary
146+ uses : actions/upload-artifact@v4
147+ with :
148+ name : binary-${{ env.BINARY_NAME }}
149+ path : ${{ env.BIN }}
150+
15151 linux :
16152 runs-on : ${{ matrix.platform.runner }}
17153 strategy :
@@ -38,6 +174,19 @@ jobs:
38174 with :
39175 python-version : 3.x
40176
177+ - uses : actions/cache@v4
178+ with :
179+ path : |
180+ ~/.cargo/bin/
181+ ~/.cargo/registry/index/
182+ ~/.cargo/registry/cache/
183+ ~/.cargo/git/db/
184+ target/
185+ key : ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-${{ hashFiles('**/Cargo. lock') }}
186+ restore-keys : |
187+ ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-
188+ ${{ runner.os }}-cargo-wheels-
189+
41190 - name : Build wheels
42191 uses : PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380
43192 with :
@@ -74,6 +223,19 @@ jobs:
74223 with :
75224 python-version : 3.x
76225
226+ - uses : actions/cache@v4
227+ with :
228+ path : |
229+ ~/.cargo/bin/
230+ ~/.cargo/registry/index/
231+ ~/.cargo/registry/cache/
232+ ~/.cargo/git/db/
233+ target/
234+ key : ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-${{ hashFiles('**/Cargo. lock') }}
235+ restore-keys : |
236+ ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-
237+ ${{ runner.os }}-cargo-wheels-
238+
77239 - name : Build wheels
78240 uses : PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380
79241 with :
@@ -104,8 +266,21 @@ jobs:
104266
105267 - uses : actions/setup-python@v6
106268 with :
107- python-version : 3.x
108269 architecture : ${{ matrix.platform.target }}
270+ python-version : 3.x
271+
272+ - uses : actions/cache@v4
273+ with :
274+ path : |
275+ ~/.cargo/bin/
276+ ~/.cargo/registry/index/
277+ ~/.cargo/registry/cache/
278+ ~/.cargo/git/db/
279+ target/
280+ key : ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-${{ hashFiles('**/Cargo. lock') }}
281+ restore-keys : |
282+ ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-
283+ ${{ runner.os }}-cargo-wheels-
109284
110285 - name : Build wheels
111286 uses : PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380
@@ -138,6 +313,19 @@ jobs:
138313 with :
139314 python-version : 3.x
140315
316+ - uses : actions/cache@v4
317+ with :
318+ path : |
319+ ~/.cargo/bin/
320+ ~/.cargo/registry/index/
321+ ~/.cargo/registry/cache/
322+ ~/.cargo/git/db/
323+ target/
324+ key : ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-${{ hashFiles('**/Cargo. lock') }}
325+ restore-keys : |
326+ ${{ runner.os }}-cargo-wheels-${{ matrix.platform.target }}-
327+ ${{ runner.os }}-cargo-wheels-
328+
141329 - name : Build wheels
142330 uses : PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380
143331 with :
0 commit comments