Skip to content

Commit

Permalink
ci: Fix builds for aarch64 Macs
Browse files Browse the repository at this point in the history
This requires passing `--host` when cross-compiling, and making a few
small changes to the `libpostal` `configure.ac` and `Makefile.am`
files.
  • Loading branch information
emk committed Feb 17, 2022
1 parent 784b5cd commit c3162af
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ jobs:
host: x86_64-apple-darwin
cargo: cargo
os: macos-latest
# - target: aarch64-apple-darwin
# host: x86_64-apple-darwin
# cargo: cargo
# os: macos-latest
- target: aarch64-apple-darwin
host: x86_64-apple-darwin
cargo: cargo
os: macos-latest

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geocode-csv"
version = "1.1.0-alpha.2"
version = "1.1.0-ci.6"
authors = ["Eric Kidd <[email protected]>"]
edition = "2018"

Expand Down
29 changes: 29 additions & 0 deletions crates/libpostal-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! version, because this is a fairly obscure library and it's not availble even
//! as an Ubuntu PPE.
use std::env;

/// The main entry point to our build script.
fn main() {
build_libpostal();
Expand All @@ -24,6 +26,33 @@ fn build_libpostal() {
// config.reconf("-fi");
// }

// Get our Rust target and host.
let rust_target = env::var("TARGET").expect("cargo should always define TARGET");
let rust_host = env::var("HOST").expect("cargo should always define HOST");

// When cross-compiling for M1 Macs, set `--host` appropriately. Keep in
// mind that:
//
// - Rust `TARGET` is `./configure --host=`.
// - Rust `HOST` is `./configure --build=`.
// - `./configure --target=` is only used when building a compiler on
// `--build` that will run on `--host` and generate code for `--target`.
// But Rust _always_ supports generating code for multiple targets, so it
// doesn't think like this.
//
// I'm not sure why we need to set this manually, but it seems to be
// necessary. We might need to do this for other combinations, but let's add
// them as we discover them.
if rust_target == "aarch64-apple-darwin" && rust_host != "aarch64-apple-darwin" {
config.config_option("host", Some(&rust_target));
}

// If we're not on Intel, don't try to use Intel processor extensions. We
// need to disable this manually, apparently.
if !rust_target.starts_with("x86_64-") {
config.disable("sse2", None);
}

let dst = config
// You'll need to edit any `-Wall` out of the source tree,
// unfortunately.
Expand Down
2 changes: 1 addition & 1 deletion crates/libpostal-sys/libpostal

0 comments on commit c3162af

Please sign in to comment.