nabijaczleweli / rust-embed-resource

A Cargo build script library to handle compilation and inclusion of Windows resources, in the most resilient fashion imaginable
MIT License
166 stars 28 forks source link

fail to cross-compile linux->windows: clang-cl rejects `-xc` #68

Open tanriol opened 2 months ago

tanriol commented 2 months ago

I've been using rust-embed-resource via tauri for quite some time by cross-compiling the Windows version on Linux using clang-cl as compiler (cargo config.toml snippet below).

# Defined based on https://jake-shadle.github.io/xwin/
[target.x86_64-pc-windows-msvc]
linker = "lld-link"
rustflags = [
    "-Lnative=/path/to/xwin/crt/lib/x86_64",
    "-Lnative=/path/to/xwin/sdk/lib/um/x86_64",
    "-Lnative=/path/to/xwin/sdk/lib/ucrt/x86_64",
]

[env]
CC_x86_64_pc_windows_msvc = "clang-cl"
CXX_x86_64_pc_windows_msvc = "clang-cl"
AR_x86_64_pc_windows_msvc = "llvm-lib"

For some time the build used to succeed with a warning about -xc being unrecognized. Now (presumably after clang/llvm upgrade, although I'm not sure) the build fails with the following error: clang-cl: error: unsupported option '-x c'; did you mean '/TC' or '/TP'?

More context ``` The following warnings were emitted during compilation: warning: test-cross@0.0.0: clang-cl: error: unsupported option '-x c'; did you mean '/TC' or '/TP'? error: failed to run custom build command for `test-cross v0.0.0 (/tmp/test-cross/src-tauri)` Caused by: process didn't exit successfully: `/tmp/test-cross/src-tauri/target/debug/build/test-cross-35b858db60db2b87/build-script-build` (exit status: 1) --- stdout cargo:rerun-if-env-changed=TAURI_CONFIG cargo:rerun-if-changed=tauri.conf.json cargo:rustc-cfg=desktop cargo:rustc-env=TAURI_ANDROID_PACKAGE_PREFIX=com_tauri_dev cargo:rustc-cfg=dev cargo:PERMISSION_FILES_PATH=/tmp/test-cross/src-tauri/target/x86_64-pc-windows-msvc/debug/build/test-cross-18f49f7db6edd6fc/out/app-manifest/__app__-permission-files cargo:rerun-if-changed=capabilities cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE=x86_64-pc-windows-msvc package.metadata does not exist cargo:warning=clang-cl: error: unsupported option '-x c'; did you mean '/TC' or '/TP'? --- stderr error occurred: Command "clang-cl" "-nologo" "-MD" "-Z7" "-Brepro" "-m64" "-I" "/tmp/test-cross/src-tauri/target/x86_64-pc-windows-msvc/debug/build/test-cross-18f49f7db6edd6fc/out" "-W4" "-xc" "-DRC_INVOKED" "-E" "--" "/tmp/test-cros s/src-tauri/target/x86_64-pc-windows-msvc/debug/build/test-cross-18f49f7db6edd6fc/out/resource.rc" with args clang-cl did not execute successfully (status code exit status: 1). warning: build failed, waiting for other jobs to finish... ```

I've traced this to this cc invocation.

nabijaczleweli commented 2 months ago

Indeed, and ever-so-helpfully I don't see a generalised way to pass -x-equivalents in https://docs.rs/cc/latest/cc/struct.Build.html :v

Can you try making the line with .flag("-xc") be .flag("-Xclang").flag("-xc") instead? That would turn this into Tool::is_like_msvc().