Skip to content

Commit

Permalink
fix: force windows compiler to run in out_dir to prevent artifacts …
Browse files Browse the repository at this point in the history
…in cwd (#1415)
  • Loading branch information
wmmc88 authored Feb 25, 2025
1 parent 181c03d commit 439b75f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
18 changes: 18 additions & 0 deletions .github/actions/check-clean-git-working-tree/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Check Clean Git Working Tree"
description: "Check that the git working tree is clean"

runs:
using: "composite"
steps:
- name: Check clean Git working tree
shell: bash
run: |
status_output=$(git status --porcelain=v1)
if [ -z "$status_output" ]; then
echo "Git working tree is clean."
exit 0
else
echo "dirty Git working tree detected!"
echo "$status_output"
exit 1
fi
24 changes: 23 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ jobs:
if: startsWith(matrix.build, 'cross-macos') || startsWith(matrix.build, 'cross-ios')
run: sudo apt-get install llvm
- name: Download macOS SDK
working-directory: ${{ runner.temp }}
if: startsWith(matrix.build, 'cross-macos')
run: |
wget https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz
tar -xf MacOSX11.3.sdk.tar.xz
echo "SDKROOT=$(pwd)/MacOSX11.3.sdk" >> $GITHUB_ENV
- name: Download iOS SDK
working-directory: ${{ runner.temp }}
if: startsWith(matrix.build, 'cross-ios')
run: |
wget https://github.com/xybp888/iOS-SDKs/releases/download/iOS18.1-SDKs/iPhoneOS18.1.sdk.zip
Expand All @@ -196,6 +198,9 @@ jobs:
- run: cargo update
- uses: Swatinem/rust-cache@v2
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} ${{ matrix.cargo_flags }}
# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
- name: check clean Git workting tree
uses: ./.github/actions/check-clean-git-working-tree

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

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

test-wasm32-wasip1-thread:
name: Test wasm32-wasip1-thread
Expand All @@ -274,7 +285,7 @@ jobs:
echo "WASI_TOOLCHAIN_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Install wasi-sdk
working-directory: /tmp
working-directory: ${{ runner.temp }}
env:
REPO: WebAssembly/wasi-sdk
run: |
Expand All @@ -297,12 +308,17 @@ jobs:
- name: Run tests
run: cargo +nightly build -p $TARGET-test --target $TARGET

# check that there are no uncommitted changes to prevent bugs like https://github.com/rust-lang/cc-rs/issues/1411
- name: check clean Git workting tree
uses: ./.github/actions/check-clean-git-working-tree

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

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

rustfmt:
name: Rustfmt
Expand Down
14 changes: 5 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,17 +1337,15 @@ impl Build {

let mut cmd = compiler.to_command();
let is_arm = matches!(target.arch, "aarch64" | "arm");
let clang = compiler.is_like_clang();
let gnu = compiler.family == ToolFamily::Gnu;
command_add_output_file(
&mut cmd,
&obj,
CmdAddOutputFileArgs {
cuda: self.cuda,
is_assembler_msvc: false,
msvc: compiler.is_like_msvc(),
clang,
gnu,
clang: compiler.is_like_clang(),
gnu: compiler.is_like_gnu(),
is_asm: false,
is_arm,
},
Expand All @@ -1366,7 +1364,7 @@ impl Build {
cmd.env("_LINK_", "-entry:main");
}

let output = cmd.output()?;
let output = cmd.current_dir(out_dir).output()?;
let is_supported = output.status.success() && output.stderr.is_empty();

self.build_cache
Expand Down Expand Up @@ -1749,8 +1747,6 @@ impl Build {
let target = self.get_target()?;
let msvc = target.env == "msvc";
let compiler = self.try_get_compiler()?;
let clang = compiler.is_like_clang();
let gnu = compiler.family == ToolFamily::Gnu;

let is_assembler_msvc = msvc && asm_ext == Some(AsmFileExt::DotAsm);
let mut cmd = if is_assembler_msvc {
Expand All @@ -1770,8 +1766,8 @@ impl Build {
cuda: self.cuda,
is_assembler_msvc,
msvc: compiler.is_like_msvc(),
clang,
gnu,
clang: compiler.is_like_clang(),
gnu: compiler.is_like_gnu(),
is_asm,
is_arm,
},
Expand Down

0 comments on commit 439b75f

Please sign in to comment.