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: mac os x aarch64 sidecar compilation #4809

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@

### Fixed

- [#4809](https://github.com/ChainSafe/forest/issues/4777) the Mac OS X build on
Apple silicons works

## Forest 0.20.0 "Brexit"

Non-mandatory release including a number of new RPC methods, fixes, and other
Expand Down
18 changes: 9 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ fn main() {
if !is_docs_rs() && is_sidecar_ffi_enabled() {
println!("cargo:rustc-cfg=f3sidecar");
std::env::set_var("GOWORK", "off");
// `Netgo` is enabled for all the platforms to be consistent across different builds. It
// is using pure Go implementation for functionality like name resolution. In the case of
// sidecar it does not make much difference, but it does fix the Apple silicons builds.
// See <https://github.com/status-im/status-mobile/issues/20135#issuecomment-2137400475>
std::env::set_var("GOFLAGS", "-tags=netgo");
Copy link
Contributor

@hanabi1224 hanabi1224 Sep 26, 2024

Choose a reason for hiding this comment

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

What's the pros and cons of using netgo? Could you add some comments on why netgo is needed for macos/arm64 and is used for linux/amd64 and linux/arm64 as well when it's not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, the are no cons to this really, especially because the sidecar does not heavily rely on name resolution.

rust2go::Builder::default()
.with_go_src("./f3-sidecar")
// the generated Go file has been commited to the git repository,
Expand All @@ -30,14 +35,9 @@ fn is_docs_rs() -> bool {
}

fn is_sidecar_ffi_enabled() -> bool {
// Note: arm64 is disabled on MacOS for now as it's reported rust2go build does not work there
if cfg!(all(target_arch = "aarch64", target_os = "macos")) {
false
} else {
// Opt-out building the F3 sidecar staticlib
match std::env::var("FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT") {
Ok(value) => !matches!(value.to_lowercase().as_str(), "1" | "true"),
_ => true,
}
// Opt-out building the F3 sidecar staticlib
match std::env::var("FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT") {
Ok(value) => !matches!(value.to_lowercase().as_str(), "1" | "true"),
_ => true,
}
}
Loading