-
Notifications
You must be signed in to change notification settings - Fork 102
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
build with musl #57
Comments
Oh. I have no idea. I've never tried this. Do you need to specify a |
Hello,
|
Hmmm. It seems to be choking on the build of the shared C libraries. Does the C lib not specify "-fPIC" for building the shared libs?!? We don't use or need the shared libraries for the Rust build, but there doesn't seem to be a way to turn off building them in the CMake. I wonder if you can modify
If that works, let me know. Maybe it's worth adding to the crate for everyone? Although, if that works it would be better for us to send a PR to the C library. |
Another option would be to see if you can build and install the Paho C libs independently, then tell cargo not to compile them when building the Rust crate (turn off the "bundled" feature). |
hello @fpagliughi , I tried to add the line, but still errors |
but it seems that I get less errors:
|
Oh, wait. Is it linking to a static MUSL library that won't relocate? Can you build the C library independently in your environment? If not, then the Rust wrapper certainly won't be able to build it either. If that's the case, then perhaps this is an issue to bring up in the Paho C repository. |
Hi @fpagliughi, I'm having a similiar problem. The error seems to be related to not being able to link dynamic libraries (using cross as compilation tool). $ cross build --release --target aarch64-unknown-linux-musl
Compiling paho-mqtt-sys v0.2.1 (https://github.com/eclipse/paho.mqtt.rust#f92e43a9)
error: failed to run custom build command for `paho-mqtt-sys v0.2.1 (https://github.com/eclipse/paho.mqtt.rust#f92e43a9)`
Caused by:
process didn't exit successfully: `/target/release/build/paho-mqtt-sys-0db00f74924c5f85/build-script-build` (exit code: 101)
--- stdout
debug:Running the bundled build for Paho C
cargo:rerun-if-changed=build.rs
running: "cmake" "/cargo/git/checkouts/paho.mqtt.rust-44b07fd42c95bba6/f92e43a/paho-mqtt-sys/paho.mqtt.c/" "-DPAHO_BUILD_STATIC=on" "-DPAHO_ENABLE_TESTING=off" "-DPAHO_WITH_SSL=off" "-DCMAKE_INSTALL_PREFIX=/target/aarch64-unknown-linux-musl/release/build/paho-mqtt-sys-6485bf04d813526d/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -static" "-DCMAKE_C_COMPILER=/usr/local/bin/aarch64-linux-musl-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -static" "-DCMAKE_CXX_COMPILER=/usr/local/bin/aarch64-linux-musl-g++" "-DCMAKE_BUILD_TYPE=Release"
-- CMake version: 3.16.2
-- CMake system name: Linux
-- Timestamp is 2020-03-19T16:16:33Z
-- Configuring done
-- Generating done
-- Build files have been written to: /target/aarch64-unknown-linux-musl/release/build/paho-mqtt-sys-6485bf04d813526d/out/build
running: "cmake" "--build" "." "--target" "install" "--config" "Release" "--"
[ 68%] Built target common_obj
Scanning dependencies of target paho-mqtt3c
Scanning dependencies of target paho-mqtt3c-static
Scanning dependencies of target paho-mqtt3a-static
Scanning dependencies of target paho-mqtt3a
[ 78%] Building C object src/CMakeFiles/paho-mqtt3a-static.dir/MQTTAsync.c.o
[ 81%] Building C object src/CMakeFiles/paho-mqtt3c-static.dir/MQTTClient.c.o
[ 81%] Building C object src/CMakeFiles/paho-mqtt3a.dir/MQTTAsync.c.o
[ 81%] Building C object src/CMakeFiles/paho-mqtt3c.dir/MQTTClient.c.o
[ 87%] Linking C shared library libpaho-mqtt3c.so
[ 87%] Linking C static library libpaho-mqtt3c-static.a
[ 87%] Built target paho-mqtt3c-static
[ 90%] Linking C shared library libpaho-mqtt3a.so
[ 93%] Linking C static library libpaho-mqtt3a-static.a
[ 93%] Built target paho-mqtt3a-static
[ 93%] Built target paho-mqtt3c
[ 93%] Built target paho-mqtt3a
[ 96%] Linking C executable MQTTVersion
src/CMakeFiles/MQTTVersion.dir/build.make:85: recipe for target 'src/MQTTVersion' failed
CMakeFiles/Makefile2:133: recipe for target 'src/CMakeFiles/MQTTVersion.dir/all' failed
Makefile:151: recipe for target 'all' failed
--- stderr
/usr/local/bin/../lib/gcc/aarch64-linux-musl/6.4.0/../../../../aarch64-linux-musl/bin/ld: attempted static link of dynamic object `libpaho-mqtt3a.so.1.3.1'
collect2: error: ld returned 1 exit status
make[2]: *** [src/MQTTVersion] Error 1
make[1]: *** [src/CMakeFiles/MQTTVersion.dir/all] Error 2
make: *** [all] Error 2
thread 'main' panicked at '
command did not execute successfully, got: exit code: 2
build script failed, must exit now', /cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.41/src/lib.rs:835:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Looking around I stumbled upon this PR on the C repo that allows to select only static building. Maybe it would be nice to add that to this repo? |
Yes, that's the plan. I'm trying to help get the new Paho C library tested and out the door, then I will update the Rust crate to use it, and finally get MQTT v5 support out the door! |
@fpagliughi hello, is there a progress on this? This is becoming critical when we would like to use the release binary in different version of linux distributions. (some has correct version of openssl, some not) |
My last questions went unanswered:
In the meantime, Paho Rust v0.7.x was released, using the static Paho C lib. Did that make a difference? Looking through the Paho C issues, it appears that the solution for #63 could fix this as well. If you want to test it out and report back, that would help. If it fixes the problem, let me know and I can get it right in. Basically, add the CMake flag PAHO_HIGH_PERFORMANCE to the C lib build in
|
@fpagliughi Thanks for yor quick reply and sorry that I was actually out of this topic during last months... So I just tried the latest one: 0.7.1, add added:
in paho-mqtt-sys Then I still ran into the same errors on my local machine and also in musl container...I suspect that something is missing in my environment, Could you have a look at the follow error messages to see If you can help?
|
To reproduce: step 1:
step 2:
step 3:
|
This error is something similar to :
|
Well it would be interesting to first see if this can all be built without SSL first. If that works, it would be a good sign, and then we can move on to figure out what can be done about OpenSSL |
@fpagliughi I tried to compile with
|
Sorry this is taking so long, but seems to be coming together. I got the non-SSL version working on Mint 19 (Ubuntu 18.04) using the code that's in the develop branch, and a minor tweak to the CMake file in the C lib. I'm hoping that #72/#74 will get the SSL version working as well. The result is this...
So the example apps run as fully-static executables. The underlying C library is now built statically by default. The dynamic C lib is not built at all. The new C release 1.3.2 allows us to do this. But, for some reason, v1.3.2 specified C++ support in the CMake file, which has since been removed. For this, I commented out the line in the bundled C lib CMakeLists.txt:34:
I added the Rust musl target for my platform:
I added the musl C compiler to my system:
Then I compiled the Rust crate and examples for the release build without SSL, using the modified, bundled C lib:
That worked. |
@fpagliughi It looks awesome, I haven't tested yet, I'll test recently this feature |
I also experienced problems building the crate with musl. I found out the Specifically, I found 2 issues:
I managed to build it, without SSL supports by manually building the v1.3.2/1.3.3/1.3.4 C Library & installing it on my system and then building with the Rust toolchain setup: rustup target add x86_64-unknown-linux-musl
rustup component add rustfmt --toolchain 1.44.0-x86_64-unknown-linux-gnu Building the C library & installing it to RUN curl -LO https://github.com/eclipse/paho.mqtt.c/archive/v1.3.2.tar.gz \
&& tar xzf v1.3.2.tar.gz && cd paho.mqtt.c-1.3.2/ \
&& sed -i '/ENABLE_LANGUAGE(CXX)/d' ./CMakeLists.txt \
&& cmake \
"-DPAHO_WITH_SSL=off" "-DPAHO_BUILD_DOCUMENTATION=off" "-DPAHO_BUILD_SAMPLES=off" \
"-DPAHO_BUILD_SHARED=off" "-DPAHO_ENABLE_TESTING=off" "-DPAHO_HIGH_PERFORMANCE=on" \
"-DPAHO_BUILD_STATIC=on" \
"-DCMAKE_C_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" \
"-DCMAKE_C_COMPILER=/usr/bin/musl-gcc" \
"-DCMAKE_ASM_COMPILER=/usr/bin/musl-gcc" "-DCMAKE_BUILD_TYPE=Release" \
. \
&& make && make install \
&& cd .. \
&& rm -rf v1.3.2.tar.gz paho.mqtt.c-1.3.2 (tested on Docker The library compiles & links fine, but when I try to build & run an executable with it, I face linking errors (missing references to C's standard library, such as On the other hand, I had no problem building & running with glibc. |
With v0.9, everything seems to be in place to do the musl builds, like I described above for the non-SSL version. That's pretty cool.
^ This works. Fully static executables. Now, with the
Has anyone had any luck with this? |
Sorry, I haven't made any progress with this. I'll push it off again to try and solve by the next release. But any new thoughts or ideas would be fully appreciated. |
I have the exact same problem and here is my workaround. Add
Somehow the linker doesn't pick up libc, so this script force adding -lc when the linker is invoked. |
I was also able to workaround this by adding
|
@FantomJAC 's solution worked for me too |
Do you think it would work to add the link instruction to the |
^ Nevermind, that didn't seem to work. Perhaps I should just document these two work-around options in the README? |
I just put the workarounds into the README. If anyone has a better idea, please reopen this or make a new issue or PR. |
Hello, I tried to compile some examples with rust-musl-builder but it seems to be not working.
is there a workaround?
The text was updated successfully, but these errors were encountered: