From 948e60454a9ada5b223e8f9ea8b2c4a0ccfd6647 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Wed, 18 Aug 2021 13:12:10 +0300 Subject: [PATCH 1/2] Attempt to fix-up clang-cl support If the user specifies `CC=...` then the previous fallback to `clang` would fail to work if `clang` wasn't in the path. This is quite likely on Windows in particular. Lets just drop the use of preprocessor on Windows and directly code the one constant that the preprocessor was handling. --- psm/build.rs | 46 ++++++++++++------------------- psm/src/arch/x86_64_windows_gnu.s | 4 +-- psm/src/arch/x86_windows_gnu.s | 5 +--- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/psm/build.rs b/psm/build.rs index 60e89f6..07baeb8 100644 --- a/psm/build.rs +++ b/psm/build.rs @@ -73,38 +73,28 @@ fn main() { } let mut cfg = cc::Build::new(); - // There seems to be a bug with clang-cl where using - // `/clang:-xassembler-with-cpp` is apparently accepted (ie no warnings - // about unused/unknown arguments), but results in the same exact error - // as if the flag was not present, so instead we take advantage of the - // fact that we're not actually compiling any C/C++ code, only assembling - // and can just use clang directly. - if cfg + let msvc = cfg.get_compiler().is_like_msvc(); + let clang_cl = cfg .get_compiler() .path() .file_name() .and_then(|f| f.to_str()) - .map(|fname| fname.contains("clang-cl")) - .unwrap_or(false) - { - cfg.compiler("clang"); - } - - let msvc = cfg.get_compiler().is_like_msvc(); - let asm = - if let Some((asm, canswitch)) = find_assembly(&arch, &endian, &os, &env, msvc) { - println!("cargo:rustc-cfg=asm"); - if canswitch { - println!("cargo:rustc-cfg=switchable_stack") - } - asm - } else { - println!( - "cargo:warning=Target {}-{}-{} has no assembly files!", - arch, os, env - ); - return; - }; + .map(|f| f.contains("clang-cl")) + .unwrap_or(false); + let masm = msvc && !clang_cl; + let asm = if let Some((asm, canswitch)) = find_assembly(&arch, &endian, &os, &env, masm) { + println!("cargo:rustc-cfg=asm"); + if canswitch { + println!("cargo:rustc-cfg=switchable_stack") + } + asm + } else { + println!( + "cargo:warning=Target {}-{}-{} has no assembly files!", + arch, os, env + ); + return; + }; if !msvc { cfg.flag("-xassembler-with-cpp"); diff --git a/psm/src/arch/x86_64_windows_gnu.s b/psm/src/arch/x86_64_windows_gnu.s index 37c9e1c..8f12583 100644 --- a/psm/src/arch/x86_64_windows_gnu.s +++ b/psm/src/arch/x86_64_windows_gnu.s @@ -1,5 +1,3 @@ -#include "psm.h" - .text .def rust_psm_stack_direction @@ -11,7 +9,7 @@ rust_psm_stack_direction: /* extern "sysv64" fn() -> u8 (%al) */ .cfi_startproc - movb $STACK_DIRECTION_DESCENDING, %al # always descending on x86_64 + movb $2, %al # always descending on x86_64 retq .cfi_endproc diff --git a/psm/src/arch/x86_windows_gnu.s b/psm/src/arch/x86_windows_gnu.s index cf7f483..474d416 100644 --- a/psm/src/arch/x86_windows_gnu.s +++ b/psm/src/arch/x86_windows_gnu.s @@ -1,8 +1,5 @@ /* FIXME: this works locally but not on appveyor??!? */ - -#include "psm.h" /* NOTE: fastcall calling convention used on all x86 targets */ - .text .def @rust_psm_stack_direction@0 @@ -14,7 +11,7 @@ @rust_psm_stack_direction@0: /* extern "fastcall" fn() -> u8 (%al) */ .cfi_startproc - movb $STACK_DIRECTION_DESCENDING, %al # always descending on x86_64 + movb $2, %al # always descending on x86_64 retl .cfi_endproc From 01c77f5036aa9be32beeada46e846465d2644526 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Wed, 18 Aug 2021 13:21:15 +0300 Subject: [PATCH 2/2] Add clang-cl test, maybe? --- .github/workflows/test.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27dca96..a5c045c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,6 +46,36 @@ jobs: command: test args: --manifest-path=${{ matrix.manifest }} ${{ matrix.mode }} --examples -- --nocapture + clang-cl-test: + name: Test ${{ matrix.manifest }} on ${{ matrix.rust_target }} with ${{ matrix.clang_cl }} + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + manifest: ['psm/Cargo.toml', 'Cargo.toml'] + rust_target: + - x86_64-pc-windows-msvc + - i686-pc-windows-msvc + include: + - rust_target: x86_64-pc-windows-msvc + clang_cl: C:/msys64/mingw64/bin/clang-cl.exe + - rust_target: i686-pc-windows-msvc + clang_cl: C:/msys64/mingw32/bin/clang-cl.exe + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + default: true + target: ${{ matrix.rust_target }} + - uses: actions-rs/cargo@v1 + with: + command: test + args: --manifest-path=${{ matrix.manifest }} -- --nocapture + env: + CC: ${{ matrix.clang_cl }} + windows-gnu-test: name: Test ${{ matrix.manifest }} on ${{ matrix.rust_target }} with ${{ matrix.rust_toolchain }} runs-on: windows-latest