Skip to content

Commit 439b75f

Browse files
authored
fix: force windows compiler to run in out_dir to prevent artifacts in cwd (#1415)
1 parent 181c03d commit 439b75f

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Check Clean Git Working Tree"
2+
description: "Check that the git working tree is clean"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Check clean Git working tree
8+
shell: bash
9+
run: |
10+
status_output=$(git status --porcelain=v1)
11+
if [ -z "$status_output" ]; then
12+
echo "Git working tree is clean."
13+
exit 0
14+
else
15+
echo "dirty Git working tree detected!"
16+
echo "$status_output"
17+
exit 1
18+
fi

.github/workflows/main.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ jobs:
169169
if: startsWith(matrix.build, 'cross-macos') || startsWith(matrix.build, 'cross-ios')
170170
run: sudo apt-get install llvm
171171
- name: Download macOS SDK
172+
working-directory: ${{ runner.temp }}
172173
if: startsWith(matrix.build, 'cross-macos')
173174
run: |
174175
wget https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz
175176
tar -xf MacOSX11.3.sdk.tar.xz
176177
echo "SDKROOT=$(pwd)/MacOSX11.3.sdk" >> $GITHUB_ENV
177178
- name: Download iOS SDK
179+
working-directory: ${{ runner.temp }}
178180
if: startsWith(matrix.build, 'cross-ios')
179181
run: |
180182
wget https://github.com/xybp888/iOS-SDKs/releases/download/iOS18.1-SDKs/iPhoneOS18.1.sdk.zip
@@ -196,6 +198,9 @@ jobs:
196198
- run: cargo update
197199
- uses: Swatinem/rust-cache@v2
198200
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} ${{ matrix.cargo_flags }}
201+
# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
202+
- name: check clean Git workting tree
203+
uses: ./.github/actions/check-clean-git-working-tree
199204

200205
# This is separate from the matrix above because there is no prebuilt rust-std component for these targets.
201206
check-build-std:
@@ -234,6 +239,9 @@ jobs:
234239
- run: cargo test -Z build-std=std --no-run --workspace --target ${{ matrix.target }}
235240
- run: cargo test -Z build-std=std --no-run --workspace --target ${{ matrix.target }} --release
236241
- run: cargo test -Z build-std=std --no-run --workspace --target ${{ matrix.target }} --features parallel
242+
# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
243+
- name: check clean Git workting tree
244+
uses: ./.github/actions/check-clean-git-working-tree
237245

238246
check-wasm:
239247
name: Test wasm
@@ -252,6 +260,9 @@ jobs:
252260
- run: cargo test --no-run --target ${{ matrix.target }}
253261
- run: cargo test --no-run --target ${{ matrix.target }} --release
254262
- run: cargo test --no-run --target ${{ matrix.target }} --features parallel
263+
# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
264+
- name: check clean Git workting tree
265+
uses: ./.github/actions/check-clean-git-working-tree
255266

256267
test-wasm32-wasip1-thread:
257268
name: Test wasm32-wasip1-thread
@@ -274,7 +285,7 @@ jobs:
274285
echo "WASI_TOOLCHAIN_VERSION=$VERSION" >> "$GITHUB_ENV"
275286
276287
- name: Install wasi-sdk
277-
working-directory: /tmp
288+
working-directory: ${{ runner.temp }}
278289
env:
279290
REPO: WebAssembly/wasi-sdk
280291
run: |
@@ -297,12 +308,17 @@ jobs:
297308
- name: Run tests
298309
run: cargo +nightly build -p $TARGET-test --target $TARGET
299310

311+
# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
312+
- name: check clean Git workting tree
313+
uses: ./.github/actions/check-clean-git-working-tree
314+
300315
cuda:
301316
name: Test CUDA support
302317
runs-on: ubuntu-22.04
303318
steps:
304319
- uses: actions/checkout@v4
305320
- name: Install cuda-minimal-build-11-8
321+
working-directory: ${{ runner.temp }}
306322
shell: bash
307323
run: |
308324
# https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network
@@ -317,6 +333,9 @@ jobs:
317333
run: |
318334
PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda
319335
PATH="/usr/local/cuda/bin:$PATH" CXX=clang++ cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda
336+
# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
337+
- name: check clean Git workting tree
338+
uses: ./.github/actions/check-clean-git-working-tree
320339

321340
msrv:
322341
name: MSRV
@@ -353,6 +372,9 @@ jobs:
353372
shell: bash
354373
- uses: Swatinem/rust-cache@v2
355374
- run: cargo clippy --no-deps
375+
# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
376+
- name: check clean Git workting tree
377+
uses: ./.github/actions/check-clean-git-working-tree
356378

357379
rustfmt:
358380
name: Rustfmt

src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,17 +1337,15 @@ impl Build {
13371337

13381338
let mut cmd = compiler.to_command();
13391339
let is_arm = matches!(target.arch, "aarch64" | "arm");
1340-
let clang = compiler.is_like_clang();
1341-
let gnu = compiler.family == ToolFamily::Gnu;
13421340
command_add_output_file(
13431341
&mut cmd,
13441342
&obj,
13451343
CmdAddOutputFileArgs {
13461344
cuda: self.cuda,
13471345
is_assembler_msvc: false,
13481346
msvc: compiler.is_like_msvc(),
1349-
clang,
1350-
gnu,
1347+
clang: compiler.is_like_clang(),
1348+
gnu: compiler.is_like_gnu(),
13511349
is_asm: false,
13521350
is_arm,
13531351
},
@@ -1366,7 +1364,7 @@ impl Build {
13661364
cmd.env("_LINK_", "-entry:main");
13671365
}
13681366

1369-
let output = cmd.output()?;
1367+
let output = cmd.current_dir(out_dir).output()?;
13701368
let is_supported = output.status.success() && output.stderr.is_empty();
13711369

13721370
self.build_cache
@@ -1749,8 +1747,6 @@ impl Build {
17491747
let target = self.get_target()?;
17501748
let msvc = target.env == "msvc";
17511749
let compiler = self.try_get_compiler()?;
1752-
let clang = compiler.is_like_clang();
1753-
let gnu = compiler.family == ToolFamily::Gnu;
17541750

17551751
let is_assembler_msvc = msvc && asm_ext == Some(AsmFileExt::DotAsm);
17561752
let mut cmd = if is_assembler_msvc {
@@ -1770,8 +1766,8 @@ impl Build {
17701766
cuda: self.cuda,
17711767
is_assembler_msvc,
17721768
msvc: compiler.is_like_msvc(),
1773-
clang,
1774-
gnu,
1769+
clang: compiler.is_like_clang(),
1770+
gnu: compiler.is_like_gnu(),
17751771
is_asm,
17761772
is_arm,
17771773
},

0 commit comments

Comments
 (0)