Skip to content

Commit fd912ec

Browse files
authored
fix llvm-ar as archiver for msvc targets; fix clang-cl detection; fix assembler output flag detection; add clang/clang-cl windows CI (#1015)
1 parent be62f4a commit fd912ec

File tree

8 files changed

+224
-130
lines changed

8 files changed

+224
-130
lines changed

.github/workflows/main.yml

Lines changed: 116 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
build: [stable, beta, nightly, linux32, macos, aarch64-macos, aarch64-ios, win32, win64, mingw32, mingw64, windows-2019]
15+
build:
16+
[
17+
stable,
18+
beta,
19+
nightly,
20+
linux32,
21+
macos,
22+
aarch64-macos,
23+
aarch64-ios,
24+
win32,
25+
win64,
26+
mingw32,
27+
mingw64,
28+
windows-2019,
29+
]
1630
include:
1731
- build: stable
1832
os: ubuntu-latest
@@ -72,29 +86,53 @@ jobs:
7286
os: windows-2019
7387
rust: stable-x86_64
7488
target: x86_64-pc-windows-msvc
89+
- build: windows-clang
90+
os: windows-2019
91+
rust: stable
92+
target: x86_64-pc-windows-msvc
93+
CC: clang
94+
CXX: clang++
95+
- build: windows-clang-cl
96+
os: windows-2019
97+
rust: stable
98+
target: x86_64-pc-windows-msvc
99+
CC: clang-cl
100+
CXX: clang-cl
75101
steps:
76-
- uses: actions/checkout@v4
77-
- name: Install Rust (rustup)
78-
run: |
79-
set -euxo pipefail
80-
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal --target ${{ matrix.target }}
81-
rustup default ${{ matrix.rust }}
82-
shell: bash
83-
- name: Install g++-multilib
84-
run: |
85-
set -e
86-
# Remove the ubuntu-toolchain-r/test PPA, which is added by default.
87-
# Some packages were removed, and this is causing the g++multilib
88-
# install to fail. Similar issue:
89-
# https://github.com/scikit-learn/scikit-learn/issues/13928.
90-
sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
91-
sudo apt-get update
92-
sudo apt-get install g++-multilib
93-
if: matrix.build == 'linux32'
94-
- uses: Swatinem/rust-cache@v2
95-
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
96-
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
97-
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel
102+
- uses: actions/checkout@v4
103+
- name: Install Rust (rustup)
104+
run: |
105+
set -euxo pipefail
106+
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal --target ${{ matrix.target }}
107+
rustup default ${{ matrix.rust }}
108+
shell: bash
109+
- name: Install g++-multilib
110+
run: |
111+
set -e
112+
# Remove the ubuntu-toolchain-r/test PPA, which is added by default.
113+
# Some packages were removed, and this is causing the g++multilib
114+
# install to fail. Similar issue:
115+
# https://github.com/scikit-learn/scikit-learn/issues/13928.
116+
sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
117+
sudo apt-get update
118+
sudo apt-get install g++-multilib
119+
if: matrix.build == 'linux32'
120+
- name: add clang to path
121+
if: startsWith(matrix.build, 'windows-clang')
122+
run: |
123+
echo "C:\msys64\mingw64\bin" >> "$GITHUB_PATH"
124+
echo -e "AR=llvm-ar\nRUSTFLAGS=-Clinker=lld-link\nCC=${CC}\nCXX=${CXX}" >> "$GITHUB_ENV"
125+
shell: bash
126+
env:
127+
CC: ${{ matrix.CC }}
128+
CXX: ${{ matrix.CXX }}
129+
- name: setup dev environment
130+
uses: ilammy/msvc-dev-cmd@v1
131+
if: startsWith(matrix.build, 'windows-clang')
132+
- uses: Swatinem/rust-cache@v2
133+
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
134+
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
135+
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel
98136

99137
# This is separate from the matrix above because there is no prebuilt rust-std component for these targets.
100138
check-tvos:
@@ -120,37 +158,37 @@ jobs:
120158
target: x86_64-apple-tvos
121159
no_run: --no-run
122160
steps:
123-
- uses: actions/checkout@v4
124-
- name: Install Rust (rustup)
125-
run: |
126-
set -euxo pipefail
127-
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal
128-
rustup component add rust-src --toolchain ${{ matrix.rust }}
129-
rustup default ${{ matrix.rust }}
130-
shell: bash
131-
- uses: Swatinem/rust-cache@v2
132-
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
133-
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
134-
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel
161+
- uses: actions/checkout@v4
162+
- name: Install Rust (rustup)
163+
run: |
164+
set -euxo pipefail
165+
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal
166+
rustup component add rust-src --toolchain ${{ matrix.rust }}
167+
rustup default ${{ matrix.rust }}
168+
shell: bash
169+
- uses: Swatinem/rust-cache@v2
170+
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
171+
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
172+
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel
135173

136174
cuda:
137175
name: Test CUDA support
138176
runs-on: ubuntu-20.04
139177
steps:
140-
- uses: actions/checkout@v4
141-
- name: Install cuda-minimal-build-11-8
142-
shell: bash
143-
run: |
144-
# https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network
145-
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
146-
sudo dpkg -i cuda-keyring_1.0-1_all.deb
147-
sudo apt-get update
148-
sudo apt-get -y install cuda-minimal-build-11-8
149-
- uses: Swatinem/rust-cache@v2
150-
- name: Test 'cudart' feature
151-
shell: bash
152-
run: |
153-
PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda
178+
- uses: actions/checkout@v4
179+
- name: Install cuda-minimal-build-11-8
180+
shell: bash
181+
run: |
182+
# https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network
183+
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
184+
sudo dpkg -i cuda-keyring_1.0-1_all.deb
185+
sudo apt-get update
186+
sudo apt-get -y install cuda-minimal-build-11-8
187+
- uses: Swatinem/rust-cache@v2
188+
- name: Test 'cudart' feature
189+
shell: bash
190+
run: |
191+
PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda
154192
155193
msrv:
156194
name: MSRV
@@ -160,42 +198,42 @@ jobs:
160198
matrix:
161199
os: [ubuntu-latest, windows-latest]
162200
steps:
163-
- uses: actions/checkout@v4
164-
- name: Install Rust
165-
run: |
166-
rustup toolchain install 1.53.0 --no-self-update --profile minimal
167-
rustup toolchain install nightly --no-self-update --profile minimal
168-
rustup default 1.53.0
169-
shell: bash
170-
- name: Create Cargo.lock with minimal version
171-
run: cargo +nightly update -Zminimal-versions
172-
- name: Cache downloaded crates since 1.53 is really slow in fetching
173-
uses: Swatinem/rust-cache@v2
174-
- run: cargo check --lib -p cc --locked
175-
- run: cargo check --lib -p cc --locked --all-features
201+
- uses: actions/checkout@v4
202+
- name: Install Rust
203+
run: |
204+
rustup toolchain install 1.53.0 --no-self-update --profile minimal
205+
rustup toolchain install nightly --no-self-update --profile minimal
206+
rustup default 1.53.0
207+
shell: bash
208+
- name: Create Cargo.lock with minimal version
209+
run: cargo +nightly update -Zminimal-versions
210+
- name: Cache downloaded crates since 1.53 is really slow in fetching
211+
uses: Swatinem/rust-cache@v2
212+
- run: cargo check --lib -p cc --locked
213+
- run: cargo check --lib -p cc --locked --all-features
176214

177215
clippy:
178216
name: Clippy
179217
runs-on: ubuntu-latest
180218
steps:
181-
- uses: actions/checkout@v4
182-
- name: Install Rust
183-
run: |
184-
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
185-
rustup default stable
186-
shell: bash
187-
- uses: Swatinem/rust-cache@v2
188-
- run: cargo clippy
219+
- uses: actions/checkout@v4
220+
- name: Install Rust
221+
run: |
222+
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
223+
rustup default stable
224+
shell: bash
225+
- uses: Swatinem/rust-cache@v2
226+
- run: cargo clippy
189227

190228
rustfmt:
191229
name: Rustfmt
192230
runs-on: ubuntu-latest
193231
steps:
194-
- uses: actions/checkout@v4
195-
- name: Install Rust
196-
run: |
197-
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
198-
rustup default stable
199-
shell: bash
200-
- uses: Swatinem/rust-cache@v2
201-
- run: cargo fmt -- --check
232+
- uses: actions/checkout@v4
233+
- name: Install Rust
234+
run: |
235+
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
236+
rustup default stable
237+
shell: bash
238+
- uses: Swatinem/rust-cache@v2
239+
- run: cargo fmt -- --check

dev-tools/cc-test/build.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ fn main() {
3030
run_forked_capture_output(&out, "warnings-on");
3131
}
3232

33-
cc::Build::new()
33+
let mut build = cc::Build::new();
34+
build
3435
.file("src/foo.c")
3536
.flag_if_supported("-Wall")
3637
.flag_if_supported("-Wfoo-bar-this-flag-does-not-exist")
3738
.define("FOO", None)
3839
.define("BAR", "1")
3940
.compile("foo");
4041

42+
let compiler = build.get_compiler();
43+
4144
cc::Build::new()
4245
.file("src/bar1.c")
4346
.file("src/bar2.c")
@@ -84,6 +87,14 @@ fn main() {
8487
// nmake which runs vanilla cl, and then also test it after we remove all
8588
// the relevant env vars from our own process.
8689
if target.contains("msvc") {
90+
let cc_frontend = if compiler.is_like_msvc() {
91+
"MSVC"
92+
} else if compiler.is_like_clang() {
93+
"CLANG"
94+
} else {
95+
unimplemented!("Unknown compiler that targets msvc but isn't clang-like or msvc-like")
96+
};
97+
8798
let out = out.join("tmp");
8899
fs::create_dir(&out).unwrap();
89100
println!("nmake 1");
@@ -92,14 +103,18 @@ fn main() {
92103
.env_remove("MAKEFLAGS")
93104
.arg("/fsrc/NMakefile")
94105
.env("OUT_DIR", &out)
106+
.env("CC_FRONTEND", cc_frontend)
95107
.status()
96108
.unwrap();
97109
assert!(status.success());
98110

99111
fs::remove_dir_all(&out).unwrap();
100112
fs::create_dir(&out).unwrap();
101113

102-
env::remove_var("PATH");
114+
// windows registry won't find clang in path
115+
if !compiler.path().to_string_lossy().starts_with("clang") {
116+
env::remove_var("PATH");
117+
}
103118
env::remove_var("VCINSTALLDIR");
104119
env::remove_var("INCLUDE");
105120
env::remove_var("LIB");
@@ -109,6 +124,7 @@ fn main() {
109124
.env_remove("MAKEFLAGS")
110125
.arg("/fsrc/NMakefile")
111126
.env("OUT_DIR", &out)
127+
.env("CC_FRONTEND", cc_frontend)
112128
.status()
113129
.unwrap();
114130
assert!(status.success());

dev-tools/cc-test/src/NMakefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
all: $(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.exe
22

3+
!IF "$(CC_FRONTEND)" == "MSVC"
4+
EXTRA_CFLAGS=-nologo
5+
CFLAG_OUTPUT=-Fo
6+
!ELSE
7+
CFLAG_OUTPUT=-o
8+
!ENDIF
9+
310
$(OUT_DIR)/msvc.lib: $(OUT_DIR)/msvc.o
411
lib -nologo -out:$(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.o
5-
rc -h
612

713
$(OUT_DIR)/msvc.o: src/msvc.c
8-
$(CC) -nologo -c -Fo:$@ src/msvc.c -MD
14+
$(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -MD
915

1016
$(OUT_DIR)/msvc.exe: $(OUT_DIR)/msvc2.o
11-
$(CC) -nologo -Fo:$@ $(OUT_DIR)/msvc2.o
17+
$(CC) $(EXTRA_CFLAGS) $(CFLAG_OUTPUT)$@ $(OUT_DIR)/msvc2.o
1218

1319
$(OUT_DIR)/msvc2.o: src/msvc.c
14-
$(CC) -nologo -c -Fo:$@ src/msvc.c -DMAIN -MD
20+
$(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -DMAIN -MD

src/command_helpers.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,20 @@ for help)"
385385
}
386386
}
387387

388-
pub(crate) fn command_add_output_file(
389-
cmd: &mut Command,
390-
dst: &Path,
391-
cuda: bool,
392-
msvc: bool,
393-
clang: bool,
394-
gnu: bool,
395-
is_asm: bool,
396-
is_arm: bool,
397-
) {
398-
if msvc && !clang && !gnu && !cuda && !(is_asm && is_arm) {
388+
pub(crate) struct CmdAddOutputFileArgs {
389+
pub(crate) cuda: bool,
390+
pub(crate) is_assembler_msvc: bool,
391+
pub(crate) msvc: bool,
392+
pub(crate) clang: bool,
393+
pub(crate) gnu: bool,
394+
pub(crate) is_asm: bool,
395+
pub(crate) is_arm: bool,
396+
}
397+
398+
pub(crate) fn command_add_output_file(cmd: &mut Command, dst: &Path, args: CmdAddOutputFileArgs) {
399+
if args.is_assembler_msvc
400+
|| (args.msvc && !args.clang && !args.gnu && !args.cuda && !(args.is_asm && args.is_arm))
401+
{
399402
let mut s = OsString::from("-Fo");
400403
s.push(dst);
401404
cmd.arg(s);

src/detect_compiler_family.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@
55
#ifdef __GNUC__
66
#pragma message "gcc"
77
#endif
8-
9-
#ifdef _MSC_VER
10-
#pragma message "msvc"
11-
#endif

0 commit comments

Comments
 (0)