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

Can not build Rust Project with paho-mqtt-sys library on Mac os Apple M1 Pro #174

Closed
burak0206 opened this issue Nov 20, 2022 · 10 comments
Closed

Comments

@burak0206
Copy link

Hi all,
I am developing a rust web project using the M1 pro chipset. I installed mosquitto with brew and paho.mqtt.c with macports. I added paho-mqtt-sys and paho-mqtt. Before that, application can be built. However if I add paho-mqtt libraries, It gives an error when I call cargo build --target x86_64-apple-darwin.

What should I do to fix the error?

Error:

Ekran Resmi 2022-11-20 18 27 11

@appelgriebsch
Copy link

Interestingly the generated libpaho-mqtt3as.a is a fat binary already....

target/release/build/paho-mqtt-sys-78ae08bf9e76abb2/out/lib/libpaho-mqtt3as.a: Mach-O universal binary with 2 architectures: [x86_64:current ar archive random librarycurrent ar archive random library] [arm64:current ar archive random librarycurrent ar archive random library]
target/release/build/paho-mqtt-sys-78ae08bf9e76abb2/out/lib/libpaho-mqtt3as.a (for architecture x86_64):	current ar archive random library
target/release/build/paho-mqtt-sys-78ae08bf9e76abb2/out/lib/libpaho-mqtt3as.a (for architecture arm64):	current ar archive random library

Could that be the issue?

@appelgriebsch
Copy link

appelgriebsch commented Nov 29, 2022

there was a recent PR merged in rust... rust-lang/rust#98736. Looks like it is targeted for the 1.66 release of the rust toolchain

@appelgriebsch
Copy link

checked it with the beta toolchain just now. it builds for both architectures on my M1 :)

@burak0206
Copy link
Author

good news!, I will try it @appelgriebsch

@burak0206
Copy link
Author

I tried to these instructions set and I can compile. thank you @appelgriebsch

  1. rustup update && rustup update beta && rustup install beta
  2. rustup default beta-aarch64-apple-darwin
  3. rustup target add x86_64-apple-darwin
  4. cargo clean && cargo build --target x86_64-apple-darwin

@appelgriebsch
Copy link

I tried to these instructions set and I can compile. thank you @appelgriebsch

1. rustup update && rustup update beta && rustup install beta

2. rustup default beta-aarch64-apple-darwin

3. rustup target add x86_64-apple-darwin

4. cargo clean && cargo build --target x86_64-apple-darwin

instead of making the beta channel the default one you can also prefix the cargo commands with the channel to be used:

cargo +beta target add x86_64-apple-darwin
cargo +beta build --target x86_64-apple-darwin

@appelgriebsch
Copy link

You can then use the lipo command to combine both binaries into a single universal (fat) binary like so:

lipo -create -arch arm64 <path-to-aarch64-apple-darwin-binary> -arch x86_64 <path-to-x86_64-apple-darwin-binary> -o <path-to-universal-binary>

Benefit: this universal binary works for both architectures.

@fpagliughi
Copy link
Contributor

Hey! Thanks for the work on this. I don't have access to an M1 to help or try any of it out, but do you think there is something here we should add to the README.md? Maybe make a Mac/M1 section?

@burak0206
Copy link
Author

Hi @fpagliughi ,

yes it can be nice, I can add if you want. but I don't know which one is the best. I think @appelgriebsch knows better than me.

@appelgriebsch
Copy link

Sorry for radio silence. Was a bit busy lately. Will provide a PR for the README update on the coming weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants