Use env::var instead of cfg in some cases in build.rs#961
Use env::var instead of cfg in some cases in build.rs#961thomcc merged 8 commits intorusqlite:masterfrom
env::var instead of cfg in some cases in build.rs#961Conversation
|
OK it actually doesn't build... I'll have a look at it |
|
I think you should probably stick to moving the cfg!(windows) to the runtime check. Moving everything will be a problem, as you're seeing. That said, part of the reason I never bothered with this is cargo seems to set this properly in my experience. I did cross-compilation builds of rusqlite many times for https://github.com/mozilla/application-services, and its even part of one of the CI tasks there. |
Properly using std::env::var("CARGO_CFG_whatever") instead of cfg!(whatever)
See https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
35854cc to
474a2c4
Compare
|
This version should now build. I'm interested about your last message. You're talking about CI tests that try to cross-compile rusqlite in |
Codecov Report
@@ Coverage Diff @@
## master #961 +/- ##
==========================================
+ Coverage 77.49% 77.71% +0.21%
==========================================
Files 48 48
Lines 5719 5703 -16
==========================================
Hits 4432 4432
+ Misses 1287 1271 -16
Continue to review full report at Codecov.
|
|
In here somewhere, https://github.com/mozilla/application-services/blob/main/taskcluster/ci/module-build/kind.yml. Note that it goes through https://github.com/mozilla/rust-android-gradle/. I guess mozilla/application-services#3917 indicates that this no longer works in the CI, but that seems unrelated to the use of these macros in rusqlite, which have been there for quite a while. Also, supposedly the cross compile build still works manually, outside of CI (note that getting that repo setup to build manually is a hassle). That said, I'm not strictly speaking opposed to these changes, as long as they're minimally disruptive. I don't know that I think requiring vcpkg and cc everywhere is minimally disruptive, though. |
|
Anyway, I think the |
|
I've pushed a few review commits. Thanks for the link, I would not have found it myself! |
|
Note that (on the master branch, without these changes) running a cross compilation (from Linux to Windows) displays a warning, but does not fail the build: Maybe that's the reason your cross-compilation CI tests did not report an error? But this turns into a hard error when I try to use rusqlite as a dependency from another rust crate (or from the tests themselves) |
|
Any hesitation @gwenn? |
95c5422 to
c04a0d2
Compare
c04a0d2 to
3bce49b
Compare
|
Hm, I'm not sure why GHA CI didn't trigger here (the CI in appveyor isn't complete)... |
env::var instead of cfg in some cases in build.rs
These variables are documented as being available: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts The latest rusqlite depends on CARGO_CFG_WINDOWS to be defined in order to link correctly: rusqlite/rusqlite#961
These variables are documented as being available: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts The latest rusqlite depends on CARGO_CFG_WINDOWS to be defined in order to link correctly: rusqlite/rusqlite#961
* declare CARGO_CFG_(WINDOWS|UNIX) in build scripts These variables are documented as being available: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts The latest rusqlite depends on CARGO_CFG_WINDOWS to be defined in order to link correctly: rusqlite/rusqlite#961 * add a test for rustc cfg parsing
* declare CARGO_CFG_(WINDOWS|UNIX) in build scripts These variables are documented as being available: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts The latest rusqlite depends on CARGO_CFG_WINDOWS to be defined in order to link correctly: rusqlite/rusqlite#961 * add a test for rustc cfg parsing
This MR is properly using
std::env::var("CARGO_CFG_whatever")instead ofcfg!(whatever)This is required to handle cross-compilation, see https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
Note that this requires to pull
vcpkgas a dev-dependency whatever cargo features are used. But this does not cuase any trouble on native Windows, native Linux or cross Linux-to-Windows.Without these changes, using msvc-wine to build rusqlite would try to compile libsqlite with
-DHAVE_LOCALTIME_R(which fails).(Note also that there is an undocumented feature (
bundled-windows), that you may want to either document or drop completely)