Skip to content

fix cross compilation#16

Open
Emilgardis wants to merge 3 commits intodcuddeback:masterfrom
Emilgardis:fix-cross-compilation
Open

fix cross compilation#16
Emilgardis wants to merge 3 commits intodcuddeback:masterfrom
Emilgardis:fix-cross-compilation

Conversation

@Emilgardis
Copy link

Fixes cross-rs/cross#1377

This fixes wrong assumptions done in the build script so that the correct link paths, linker and target are used.

includes #11

cfrantz and others added 2 commits December 10, 2021 15:31
When executing build scripts, [cargo sets several environment variables](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts).
Use the cargo-supplied value for `RUSTC`.

This _also_ allows `libudev-sys` to be build by [bazel](https://bazel.build)
using rules created by `cargo raze`.

Signed-off-by: Chris Frantz <cfrantz@google.com>
@Emilgardis
Copy link
Author

The reason this has worked for many is due to libudev being installed correctly for the host, but if libudev is only available for the target, the old implementation fails.

Comment on lines 47 to 68
if !output.status.success() {
println!(
"cargo:warning=Failed to compile test program for udev function `{}`",
function_name
);
println!("cargo:warning=Using command`{:?}`", cmd);
println!(
"cargo:warning=stdout={}",
String::from_utf8_lossy(&output.stdout)
.trim()
.replace("\n", "\ncargo:warning=")
);
println!(
"cargo:warning=stderr={}",
String::from_utf8_lossy(&output.stderr)
.trim()
.replace("\n", "\ncargo:warning=")
);
false
} else {
true
}
Copy link
Author

Choose a reason for hiding this comment

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

this might be a bit noisy if the function is not expected to work. would be better if this crate instead of checking if udev_hwdb_new works, include hwdb unconditionally if feature flag hwdb is included, and let the normal rustc invocation fail linking

@tuna-f1sh
Copy link

Thanks for this fix, it resolves cross targets for me. For native, I don't think RUSTC_LINKER is always defined however and so I get:

Caused by:
  process didn't exit successfully: `/home/john/.cargo/target/debug/build/libudev-sys-3bf863781c7050cd/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=LIBUDEV_STATIC
  cargo:rerun-if-env-changed=LIBUDEV_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=SYSROOT
  cargo:rerun-if-env-changed=LIBUDEV_STATIC
  cargo:rerun-if-env-changed=LIBUDEV_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rustc-link-search=native=/usr/lib
  cargo:rustc-link-lib=udev
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=LIBUDEV_STATIC
  cargo:rerun-if-env-changed=LIBUDEV_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at /home/john/.cargo/git/checkouts/libudev-sys-77334e26c4b07c4a/220890f/build.rs:43:61:
  called `Result::unwrap()` on an `Err` value: NotPresent
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

I believe this can be resolved with an unwrap_or("cc") - not perfect if the default linker changes at some point but not sure of other solution? I have a patched, patch that I've tested resolves it: Emilgardis/libudev-sys@fix-cross-compilation...tuna-f1sh:libudev-sys:fix-cross-compilation

Can be tested with test project: https://github.com/tuna-f1sh/cross-udev-hwdb/tree/main

@Emilgardis
Copy link
Author

Emilgardis commented Nov 22, 2023

fixed! @tuna-f1sh

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.

Compiling udev with hwdb support

3 participants

Comments