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

Don't set CMAKE_SYSTEM_NAME when using the Visual Studio generator #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,22 @@ jobs:
env:
# If this isn't specified the default is iOS 7, for which zlib-ng will not compile due to the lack of thread-local storage.
IPHONEOS_DEPLOYMENT_TARGET: 16

win_cross_compile_test:
name: Test Cross Compile - ${{ matrix.platform.target }}
needs: [ test ]
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
platform:
- target: aarch64-pc-windows-msvc
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.platform.target }}
- name: build
run: cargo build -vv --target ${{ matrix.platform.target }}
working-directory: test-crate
22 changes: 15 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ impl Config {
};
let host = self.host.clone().unwrap_or_else(|| getenv_unwrap("HOST"));

let generator = self
.generator
.clone()
.or_else(|| self.getenv_target_os("CMAKE_GENERATOR"));

let msvc = target.contains("msvc");

// Some decisions later on are made if CMAKE_TOOLCHAIN_FILE is defined,
// so we need to read it from the environment variables from the beginning.
if !self.defined("CMAKE_TOOLCHAIN_FILE") {
Expand All @@ -448,7 +455,14 @@ impl Config {
if !self.defined("CMAKE_SYSTEM_NAME") {
self.define("CMAKE_SYSTEM_NAME", "Generic");
}
} else if target != host && !self.defined("CMAKE_SYSTEM_NAME") {
} else if target != host
&& !self.defined("CMAKE_SYSTEM_NAME")
&& !(msvc
&& self
.generator
.as_deref()
.map_or(true, |g| g.to_string_lossy().starts_with("Visual Studio")))
Comment on lines +460 to +464
Copy link
Author

Choose a reason for hiding this comment

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

This is definitely weirdly complicated for an inline condition, and depends on the default generator choice for MSVC being Visual Studio (implemented below, unchanged). Suggestions welcome on how to reorganize this.

{
// Set CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR when cross compiling
let os = getenv_unwrap("CARGO_CFG_TARGET_OS");
let arch = getenv_unwrap("CARGO_CFG_TARGET_ARCH");
Expand Down Expand Up @@ -495,12 +509,6 @@ impl Config {
}
}

let generator = self
.generator
.clone()
.or_else(|| self.getenv_target_os("CMAKE_GENERATOR"));

let msvc = target.contains("msvc");
let ndk = self.uses_android_ndk();
let mut c_cfg = self.c_cfg.clone().unwrap_or_default();
c_cfg
Expand Down
Loading