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

fix #62

Merged
merged 5 commits into from
May 24, 2022
Merged

fix #62

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ expected by Android, and then the ordinary flags to be passed to `cargo`.

* [cargo-lipo](https://github.com/TimNN/cargo-lipo) - for building iOS universal Rust libraries

## Doing local modifications

git clone and then install the local modifications you did:

```bash
cargo install --path .
```

## License

This project is licensed under either of
Expand Down
32 changes: 26 additions & 6 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub(crate) fn run(
let cc_key = format!("CC_{}", &triple);
let ar_key = format!("AR_{}", &triple);
let cxx_key = format!("CXX_{}", &triple);
let bindgen_clang_args_key = format!("BINDGEN_EXTRA_CLANG_ARGS_{}", &triple);
let bindgen_clang_args_key = format!("BINDGEN_EXTRA_CLANG_ARGS_{}", &triple.replace("-", "_"));
let cargo_bin = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into());

log::debug!("cargo: {}", &cargo_bin);
Expand All @@ -116,7 +116,11 @@ pub(crate) fn run(
cargo_env_target_cfg(&triple, "linker"),
&target_linker.display()
);
log::debug!("{}={}", &bindgen_clang_args_key, &target_sysroot.display());
log::debug!(
"{}={}",
&bindgen_clang_args_key,
std::env::var(bindgen_clang_args_key.clone()).unwrap_or("".into())
);
log::debug!("Args: {:?}", &cargo_args);

let mut cargo_cmd = Command::new(cargo_bin);
Expand All @@ -129,11 +133,22 @@ pub(crate) fn run(
.env(cargo_env_target_cfg(triple, "linker"), &target_linker)
.args(cargo_args);

let extra_include = format!("{}/usr/include/{}", &target_sysroot.display(), triple);
if bindgen {
cargo_cmd.env(
bindgen_clang_args_key,
format!("--sysroot={}", &target_sysroot.display()),
let bindgen_args = format!(
"--sysroot={} -I{}",
&target_sysroot.display(),
extra_include
);
cargo_cmd.env(bindgen_clang_args_key, bindgen_args.clone());
log::debug!("bindgen_args={}", bindgen_args);
} else {
let bindgen_args = format!(
"-I{}",
extra_include
);
cargo_cmd.env(bindgen_clang_args_key, bindgen_args.clone());
log::debug!("bindgen_args={}", bindgen_args);
}

match dir.parent() {
Expand All @@ -155,7 +170,12 @@ pub(crate) fn run(
.expect("cargo crashed")
}

pub(crate) fn strip(ndk_home: &Path, triple: &str, bin_path: &Path, version: Version) -> std::process::ExitStatus {
pub(crate) fn strip(
ndk_home: &Path,
triple: &str,
bin_path: &Path,
version: Version,
) -> std::process::ExitStatus {
let target_strip = if version.major >= 23 {
Path::new(&ndk_home).join(ndk23_tool(ARCH, "llvm-strip"))
} else {
Expand Down