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

Set --host flag for autotools to support cross compilation #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions webrtc-audio-processing-sys/README.md
@@ -1,4 +1,5 @@
# webrtc-audio-processing-sys

[![Crates.io](https://img.shields.io/crates/v/webrtc-audio-processing-sys.svg)](https://crates.io/crates/webrtc-audio-processing-sys)
[![Docs.rs](https://docs.rs/webrtc-audio-processing-sys/badge.svg)](https://docs.rs/webrtc-audio-processing-sys)
[![Build Status](https://travis-ci.org/tonarino/webrtc-audio-processing.svg?branch=master)](https://travis-ci.org/tonarino/webrtc-audio-processing)
Expand All @@ -21,11 +22,20 @@ sudo apt install webrtc-audio-processing-dev # Ubuntu/Debian
sudo pacman -S webrtc-audio-processing # Arch
```

### Cross compilation

When cross-compiling make sure you have the corresponding rust toolchain installed
with `rustup target add <target>` and then run

```sh
PKG_CONFIG_SYSROOT_DIR=/ cargo build --target <target>
```

### Static linking

Static linking can be enabled with the `bundled` feature flag.

The following tools are needed in order to use the `bundled` feature flag:

* libtool (`$ sudo apt install libtool`)
* autotools (`$ sudo apt install autotools-dev`)
- libtool (`$ sudo apt install libtool`)
- autotools (`$ sudo apt install autotools-dev`)
goodhoko marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions webrtc-audio-processing-sys/build.rs
Expand Up @@ -63,6 +63,16 @@ mod webrtc {
Ok((include_path, lib_path))
}

fn get_target() -> String {
let target = std::env::var("TARGET").unwrap();
let mut target_tuple = target.split("-").collect::<Vec<_>>();
// Remove the vendor component.
target_tuple.remove(1);

assert_eq!(3, target_tuple.len());
Copy link
Member

@bschwind bschwind Dec 6, 2023

Choose a reason for hiding this comment

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

I think this is an incorrect assumption, as some targets can have 3 components, some can have 4, etc.

When testing it's important to pass the --features "bundled" flag so the C++ code is built from source.

brian webrtc-audio-processing-sys $ PKG_CONFIG_SYSROOT_DIR=/ cargo build --features "bundled" --target aarch64-apple-ios
   Compiling webrtc-audio-processing-sys v0.3.0 (/Users/brian/projects/tonari/webrtc-audio-processing/webrtc-audio-processing-sys)
error: failed to run custom build command for `webrtc-audio-processing-sys v0.3.0 (/Users/brian/projects/tonari/webrtc-audio-processing/webrtc-audio-processing-sys)`

Caused by:
  process didn't exit successfully: `/Users/brian/projects/tonari/webrtc-audio-processing/webrtc-audio-processing-sys/target/debug/build/webrtc-audio-processing-sys-e044a990654280ee/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at build.rs:72:9:
  assertion `left == right` failed
    left: 3
   right: 2
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Copy link
Member

@goodhoko goodhoko Dec 7, 2023

Choose a reason for hiding this comment

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

Good point!

When I use the bundled feature and a 4-component target I get a configure errors like:


  --- stderr
  configure: error: in `/Users/jentak/workspace/tonari/webrtc-audio-processing/target/aarch64-unknown-linux-musl/debug/build/webrtc-audio-processing-sys-7f94f1d16145798d/out/build':
  configure: error: C compiler cannot create executables

When I comment out https://github.com/tonarino/webrtc-audio-processing/pull/19/files#diff-4038f237c46940dc12666050b832d77271ddb0171c9bc64700009de2a982a403R106 (i.e. essentially ignore changes from this PR) and cross-compile for eg. x86_64-apple-darwin the build finishes successfully.

PKG_CONFIG_SYSROOT_DIR=/ cargo -v build --target x86_64-apple-darwin --features "bundled"

So I'm not sure if this PR is even needed? See also my comment below.

target_tuple.join("-")
}

fn copy_source_to_out_dir() -> Result<PathBuf, Error> {
use fs_extra::dir::CopyOptions;

Expand Down Expand Up @@ -93,6 +103,7 @@ mod webrtc {
.cxxflag("-fPIC")
.disable_shared()
.enable_static()
.host(&get_target())
.build();

Ok(())
Expand Down