Skip to content

Commit

Permalink
binder_ndk_sys: Allow code to build inside a workspace
Browse files Browse the repository at this point in the history
When this file is generated into `target/`, it might still think it
belongs to a parent `[workspace]` crate and fail to compile:

       Compiling binder_ndk_sys v0.2.0 (binder_rs/binder_ndk_sys)
    error: failed to run custom build command for `binder_ndk_sys v0.2.0 (binder_rs/binder_ndk_sys)`

    Caused by:
      process didn't exit successfully: `my-hidl-crate/target/debug/build/binder_ndk_sys-a839da7d88e99ce9/build-script-build` (exit status: 101)
      --- stdout
      cargo:rerun-if-changed=src/BinderBindings.hpp
      cargo:rerun-if-changed=src/symbols.txt

      --- stderr
      error: current package believes it's in a workspace when it's not:
      current:   my-hidl-crate/target/aarch64-linux-android/debug/build/binder_ndk_sys-a3aef417509c2387/out/libbinder_ndk/Cargo.toml
      workspace: my-hidl-crate/Cargo.toml

      this may be fixable by ensuring that this crate is depended on by the workspace root: my-hidl-crate/Cargo.toml
      Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.

Follow the suggestion from `cargo` and turn the generated
`libbinder_ndk/Cargo.toml` crate into a new workspace root.

This would have previously gone unnoticed as the invocation of `cargo
build` did not check whether it had a nonzero exit code: this is now
asserted on too.

We also revert commit 6627342 ("Fix build failed when used in workspace
(#5)") which was working around the issue _within this repository
only_, but that doesn't apply to users/consumers of this crate via i.e.
crates.io.
  • Loading branch information
MarijnS95 committed Nov 5, 2024
1 parent 6627342 commit bf8a863
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ members = [
"tests",
]

exclude = ["target/*"]

[workspace.package]
edition = "2021"
version = "0.2.0"
Expand Down
8 changes: 6 additions & 2 deletions binder_ndk_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ rust-version = "1.67"
[lib]
crate-type = ["cdylib"]
[workspace]
"#;

fn build_stub() -> Result<()> {
Expand All @@ -42,7 +44,7 @@ fn build_stub() -> Result<()> {
f.flush()?;

let target = env::var("TARGET")?;
Command::new("cargo")
let s = Command::new("cargo")
.arg("build")
.arg("--target")
.arg(&target)
Expand All @@ -53,10 +55,12 @@ fn build_stub() -> Result<()> {
.current_dir(&project_path)
.status()?;

assert!(s.success(), "{s:?}");

// we always use debug build for stub due to speed!
println!(
"cargo:rustc-link-search={}",
format!("{}/{}/{}", outdir, target, "debug")
format_args!("{}/{}/{}", outdir, target, "debug")
);
println!("cargo:rustc-link-lib=binder_ndk");

Expand Down

0 comments on commit bf8a863

Please sign in to comment.