Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix llvm-ar as archiver for msvc targets; fix clang-cl detection; fix assembler output flag detection; add clang/clang-cl windows CI #1015

Merged
merged 32 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
829e054
fix llvm-ar as archiver for msvc targets
russelltg Mar 19, 2024
094d406
fix usage of get_command
russelltg Mar 19, 2024
d388cb8
fmt
russelltg Mar 19, 2024
d737de1
initial attempt at clang windows CI
russelltg Mar 19, 2024
9eff753
apply suggestion
russelltg Mar 19, 2024
7c20d23
hopefully get clang in path
russelltg Mar 19, 2024
3da03c7
oops this is powershell
russelltg Mar 19, 2024
0571f2a
use -? to detect cl-style frontends
russelltg Mar 20, 2024
4581b26
use output flag directly for assembler type
russelltg Mar 21, 2024
c5c7562
apply ci suggestion
russelltg Mar 21, 2024
ea91a79
add windows clang-cl ci
russelltg Mar 21, 2024
0ec9ca3
remove duplicate env
russelltg Mar 21, 2024
d44e733
make sure output arg is in same arg
russelltg Mar 21, 2024
8b7ed60
fix creation of output arg
russelltg Mar 21, 2024
e022679
use msvc-style args for msvc
russelltg Mar 21, 2024
4c5260a
hopefully fix env
russelltg Mar 21, 2024
9d35dcd
add test env command
russelltg Mar 21, 2024
ba42c16
go back to previous env method
russelltg Mar 21, 2024
d69c416
maybe?
russelltg Mar 21, 2024
975a9d7
FIx CI
NobodyXu Mar 30, 2024
6237e2e
Re-enable warnings-as-error when compiling tests
NobodyXu Mar 30, 2024
f573a66
Fix `create_compile_object_cmd`
NobodyXu Mar 30, 2024
6e72ff5
Fix `is_flag_supported` and `create_compile_object_cmd`
NobodyXu Mar 30, 2024
ad8d072
another ci attempt
russelltg Mar 31, 2024
940bc3e
generalize NMakefile to allow clang flags
russelltg Mar 31, 2024
2c41d81
fmt
russelltg Mar 31, 2024
ff0f7af
try re-adding devenv
russelltg Mar 31, 2024
fe5ae81
fix env vars in commandline tests
russelltg Mar 31, 2024
fd6b59a
apparently clang-cl doesn't accept -Fo:
russelltg Mar 31, 2024
80a2f81
better check for if compiler is clang
russelltg Mar 31, 2024
006ac81
fix clang not being detected as clang
russelltg Mar 31, 2024
eed65b4
fix typo, minor cleanup
russelltg Mar 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 116 additions & 78 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [stable, beta, nightly, linux32, macos, aarch64-macos, aarch64-ios, win32, win64, mingw32, mingw64, windows-2019]
build:
[
stable,
beta,
nightly,
linux32,
macos,
aarch64-macos,
aarch64-ios,
win32,
win64,
mingw32,
mingw64,
windows-2019,
]
include:
- build: stable
os: ubuntu-latest
Expand Down Expand Up @@ -72,29 +86,53 @@ jobs:
os: windows-2019
rust: stable-x86_64
target: x86_64-pc-windows-msvc
- build: windows-clang
os: windows-2019
rust: stable
target: x86_64-pc-windows-msvc
CC: clang
CXX: clang++
- build: windows-clang-cl
os: windows-2019
rust: stable
target: x86_64-pc-windows-msvc
CC: clang-cl
CXX: clang-cl
steps:
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: |
set -euxo pipefail
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal --target ${{ matrix.target }}
rustup default ${{ matrix.rust }}
shell: bash
- name: Install g++-multilib
run: |
set -e
# Remove the ubuntu-toolchain-r/test PPA, which is added by default.
# Some packages were removed, and this is causing the g++multilib
# install to fail. Similar issue:
# https://github.com/scikit-learn/scikit-learn/issues/13928.
sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-multilib
if: matrix.build == 'linux32'
- uses: Swatinem/rust-cache@v2
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: |
set -euxo pipefail
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal --target ${{ matrix.target }}
rustup default ${{ matrix.rust }}
shell: bash
- name: Install g++-multilib
run: |
set -e
# Remove the ubuntu-toolchain-r/test PPA, which is added by default.
# Some packages were removed, and this is causing the g++multilib
# install to fail. Similar issue:
# https://github.com/scikit-learn/scikit-learn/issues/13928.
sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if it works...

sudo apt-get update
sudo apt-get install g++-multilib
if: matrix.build == 'linux32'
- name: add clang to path
if: startsWith(matrix.build, 'windows-clang')
run: |
echo "C:\msys64\mingw64\bin" >> "$GITHUB_PATH"
echo -e "AR=llvm-ar\nRUSTFLAGS=-Clinker=lld-link\nCC=${CC}\nCXX=${CXX}" >> "$GITHUB_ENV"
shell: bash
env:
CC: ${{ matrix.CC }}
CXX: ${{ matrix.CXX }}
- name: setup dev environment
uses: ilammy/msvc-dev-cmd@v1
if: startsWith(matrix.build, 'windows-clang')
- uses: Swatinem/rust-cache@v2
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
- run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel

# This is separate from the matrix above because there is no prebuilt rust-std component for these targets.
check-tvos:
Expand All @@ -120,37 +158,37 @@ jobs:
target: x86_64-apple-tvos
no_run: --no-run
steps:
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: |
set -euxo pipefail
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal
rustup component add rust-src --toolchain ${{ matrix.rust }}
rustup default ${{ matrix.rust }}
shell: bash
- uses: Swatinem/rust-cache@v2
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: |
set -euxo pipefail
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal
rustup component add rust-src --toolchain ${{ matrix.rust }}
rustup default ${{ matrix.rust }}
shell: bash
- uses: Swatinem/rust-cache@v2
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }}
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel

cuda:
name: Test CUDA support
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Install cuda-minimal-build-11-8
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
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-minimal-build-11-8
- uses: Swatinem/rust-cache@v2
- name: Test 'cudart' feature
shell: bash
run: |
PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda
- uses: actions/checkout@v4
- name: Install cuda-minimal-build-11-8
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
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-minimal-build-11-8
- uses: Swatinem/rust-cache@v2
- name: Test 'cudart' feature
shell: bash
run: |
PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda

msrv:
name: MSRV
Expand All @@ -160,42 +198,42 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install 1.53.0 --no-self-update --profile minimal
rustup toolchain install nightly --no-self-update --profile minimal
rustup default 1.53.0
shell: bash
- name: Create Cargo.lock with minimal version
run: cargo +nightly update -Zminimal-versions
- name: Cache downloaded crates since 1.53 is really slow in fetching
uses: Swatinem/rust-cache@v2
- run: cargo check --lib -p cc --locked
- run: cargo check --lib -p cc --locked --all-features
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install 1.53.0 --no-self-update --profile minimal
rustup toolchain install nightly --no-self-update --profile minimal
rustup default 1.53.0
shell: bash
- name: Create Cargo.lock with minimal version
run: cargo +nightly update -Zminimal-versions
- name: Cache downloaded crates since 1.53 is really slow in fetching
uses: Swatinem/rust-cache@v2
- run: cargo check --lib -p cc --locked
- run: cargo check --lib -p cc --locked --all-features

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
rustup default stable
shell: bash
- uses: Swatinem/rust-cache@v2
- run: cargo clippy
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
rustup default stable
shell: bash
- uses: Swatinem/rust-cache@v2
- run: cargo clippy

rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
rustup default stable
shell: bash
- uses: Swatinem/rust-cache@v2
- run: cargo fmt -- --check
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
rustup default stable
shell: bash
- uses: Swatinem/rust-cache@v2
- run: cargo fmt -- --check
20 changes: 18 additions & 2 deletions dev-tools/cc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ fn main() {
run_forked_capture_output(&out, "warnings-on");
}

cc::Build::new()
let mut build = cc::Build::new();
build
.file("src/foo.c")
.flag_if_supported("-Wall")
.flag_if_supported("-Wfoo-bar-this-flag-does-not-exist")
.define("FOO", None)
.define("BAR", "1")
.compile("foo");

let compiler = build.get_compiler();

cc::Build::new()
.file("src/bar1.c")
.file("src/bar2.c")
Expand Down Expand Up @@ -84,6 +87,14 @@ fn main() {
// nmake which runs vanilla cl, and then also test it after we remove all
// the relevant env vars from our own process.
if target.contains("msvc") {
let cc_frontend = if compiler.is_like_msvc() {
"MSVC"
} else if compiler.is_like_clang() {
"CLANG"
} else {
unimplemented!("Unknown compiler that targets msvc but isn't clang-like or msvc-like")
};

let out = out.join("tmp");
fs::create_dir(&out).unwrap();
println!("nmake 1");
Expand All @@ -92,14 +103,18 @@ fn main() {
.env_remove("MAKEFLAGS")
.arg("/fsrc/NMakefile")
.env("OUT_DIR", &out)
.env("CC_FRONTEND", cc_frontend)
.status()
.unwrap();
assert!(status.success());

fs::remove_dir_all(&out).unwrap();
fs::create_dir(&out).unwrap();

env::remove_var("PATH");
// windows registry won't find clang in path
if !compiler.path().to_string_lossy().starts_with("clang") {
env::remove_var("PATH");
}
env::remove_var("VCINSTALLDIR");
env::remove_var("INCLUDE");
env::remove_var("LIB");
Expand All @@ -109,6 +124,7 @@ fn main() {
.env_remove("MAKEFLAGS")
.arg("/fsrc/NMakefile")
.env("OUT_DIR", &out)
.env("CC_FRONTEND", cc_frontend)
.status()
.unwrap();
assert!(status.success());
Expand Down
14 changes: 10 additions & 4 deletions dev-tools/cc-test/src/NMakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
all: $(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.exe

!IF "$(CC_FRONTEND)" == "MSVC"
EXTRA_CFLAGS=-nologo
CFLAG_OUTPUT=-Fo
!ELSE
CFLAG_OUTPUT=-o
!ENDIF

$(OUT_DIR)/msvc.lib: $(OUT_DIR)/msvc.o
lib -nologo -out:$(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.o
rc -h

$(OUT_DIR)/msvc.o: src/msvc.c
$(CC) -nologo -c -Fo:$@ src/msvc.c -MD
$(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -MD

$(OUT_DIR)/msvc.exe: $(OUT_DIR)/msvc2.o
$(CC) -nologo -Fo:$@ $(OUT_DIR)/msvc2.o
$(CC) $(EXTRA_CFLAGS) $(CFLAG_OUTPUT)$@ $(OUT_DIR)/msvc2.o

$(OUT_DIR)/msvc2.o: src/msvc.c
$(CC) -nologo -c -Fo:$@ src/msvc.c -DMAIN -MD
$(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -DMAIN -MD
25 changes: 14 additions & 11 deletions src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,20 @@ for help)"
}
}

pub(crate) fn command_add_output_file(
cmd: &mut Command,
dst: &Path,
cuda: bool,
msvc: bool,
clang: bool,
gnu: bool,
is_asm: bool,
is_arm: bool,
) {
if msvc && !clang && !gnu && !cuda && !(is_asm && is_arm) {
pub(crate) struct CmdAddOutputFileArgs {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

pub(crate) cuda: bool,
pub(crate) is_assembler_msvc: bool,
pub(crate) msvc: bool,
pub(crate) clang: bool,
pub(crate) gnu: bool,
pub(crate) is_asm: bool,
pub(crate) is_arm: bool,
}

pub(crate) fn command_add_output_file(cmd: &mut Command, dst: &Path, args: CmdAddOutputFileArgs) {
if args.is_assembler_msvc
|| (args.msvc && !args.clang && !args.gnu && !args.cuda && !(args.is_asm && args.is_arm))
{
let mut s = OsString::from("-Fo");
s.push(dst);
cmd.arg(s);
Expand Down
4 changes: 0 additions & 4 deletions src/detect_compiler_family.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@
#ifdef __GNUC__
#pragma message "gcc"
#endif

#ifdef _MSC_VER
#pragma message "msvc"
#endif
Loading