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

Automatically use CMake for Windows builds #672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chklauser
Copy link

This PR changes the rdkafka-sys/build.rs script to automatically choose CMake if the target platform is Windows. The cmake-build cargo feature no longer has an effect on Windows. It can still be used to select the CMake build for other targets. The official rdkafka build system remains the default for other targets.

This solves a number of problems:

  • Projects using rdkafka/rdkafka-sys no longer have to conditionally enable cmake-build when they reference the crates just to have something that compiles across platforms.
  • JetBrains RustRover + rust-analyzer fail to initialize on Windows because the rdkafka-sys/build.rs script fails. In RustRover, even if you otherwise enable the cmake-build feature, there is an early "disovery" execution of the project that uses default features and fails miserably.
  • People evaluating the crate have a better experience if they happen to run Windows

I had initially tried to use the cmake-build feature, but there doesn't seem to a reliable mechanism to conditionally add a default feature. One option is to exploit a side effect of the v1 feature resolver: in the rdkafka crate, if we add a dependencies section that is conditional on target_os = "windows" and pass cmake-build as a feature to rdkafka-sys, that feature accidentally remains enabled even if you run cargo test --package rdkafka-sys from the root. This is definitely fixed in the v2 feature resolver, though.

This PR changes the `rdkafka-sys/build.rs` script to automatically choose CMake
if the target platform is Windows. The `cmake-build` cargo feature no longer
has an effect on Windows. It can still be used to select the CMake build for
other targets. The official rdkafka build system remains the default for other
targets.

This solves a number of problems:
 - Projects using `rdkafka`/`rdkafka-sys` no longer have to conditionally
	enable `cmake-build` when they reference the crates just to have something that
	compiles across platforms.
 - JetBrains RustRover + rust-analyzer fail to initialize on Windows because the
	`rdkafka-sys/build.rs` script fails. In RustRover, even if you otherwise enable
	the `cmake-build` feature, there is an early "disovery" execution of the project
	that uses default features and fails miserably.
 - People evaluating the crate have a better experience if they happen to run
	Windows
@chklauser chklauser force-pushed the windows-enables-cmake-build-by-default branch from 3cdb2e6 to efb04fb Compare August 6, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant