emk / rust-musl-builder

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static versions of useful C libraries. Supports openssl and diesel crates.
Apache License 2.0
1.54k stars 193 forks source link

failed to buld paho.mqtt.rust #85

Closed GopherJ closed 4 years ago

GopherJ commented 4 years ago

What did you try to do? build a static binary using paho.mqtt.rust

Please include the steps you took, including the commands you ran in your terminal.

git clone https://github.com/eclipse/paho.mqtt.rust
cd paho.mqtt.rust && rust-musl-builder cargo build --example futures_consume --release

What happened?

    Updating crates.io index
  Downloaded futures-timer v0.1.1
  Downloaded log v0.4.8
  Downloaded cmake v0.1.42
  Downloaded env_logger v0.6.2
  Downloaded futures v0.1.29
  Downloaded libc v0.2.66
  Downloaded cfg-if v0.1.10
  Downloaded regex v1.3.1
  Downloaded humantime v1.3.0
  Downloaded cc v1.0.47
  Downloaded aho-corasick v0.7.6
  Downloaded regex-syntax v0.6.12
  Downloaded termcolor v1.0.5
  Downloaded atty v0.2.13
  Downloaded thread_local v0.3.6
  Downloaded memchr v2.2.1
  Downloaded quick-error v1.2.2
  Downloaded lazy_static v1.4.0
   Compiling memchr v2.2.1
   Compiling libc v0.2.66
   Compiling cc v1.0.47
   Compiling lazy_static v1.4.0
   Compiling log v0.4.8
   Compiling cfg-if v0.1.10
   Compiling regex-syntax v0.6.12
   Compiling quick-error v1.2.2
   Compiling termcolor v1.0.5
   Compiling futures v0.1.29
   Compiling humantime v1.3.0
   Compiling thread_local v0.3.6
   Compiling aho-corasick v0.7.6
   Compiling atty v0.2.13
   Compiling futures-timer v0.1.1
   Compiling cmake v0.1.42
   Compiling regex v1.3.1
   Compiling paho-mqtt-sys v0.2.1 (/home/rust/src/paho-mqtt-sys)
error: failed to run custom build command for `paho-mqtt-sys v0.2.1 (/home/rust/src/paho-mqtt-sys)`
process didn't exit successfully: `/home/rust/src/target/release/build/paho-mqtt-sys-e87ed646c81d4087/build-script-build` (exit code: 101)
--- stdout
debug:Running the bundled build for Paho C
cargo:rerun-if-changed=build.rs
running: "cmake" "/home/rust/src/paho-mqtt-sys/paho.mqtt.c/" "-DPAHO_BUILD_STATIC=on" "-DPAHO_ENABLE_TESTING=off" "-DPAHO_WITH_SSL=on" "-DCMAKE_INSTALL_PREFIX=/home/rust/src/target/x86_64-unknown-linux-musl/release/build/paho-mqtt-sys-8d156c5b0c0125c7/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -static" "-DCMAKE_C_COMPILER=/usr/bin/musl-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -static" "-DCMAKE_CXX_COMPILER=/usr/bin/musl-g++" "-DCMAKE_BUILD_TYPE=Release"
-- The C compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/musl-gcc
-- Check for working C compiler: /usr/bin/musl-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- CMake version: 3.5.1
-- CMake system name: Linux
-- Timestamp is 2019-12-02T15:45:50Z
-- OpenSSL hints: 
-- OpenSSL headers found at /usr/local/musl/include
-- OpenSSL library found at /usr/local/musl/lib/libssl.a
-- OpenSSL Crypto library found at /usr/local/musl/lib/libcrypto.a
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rust/src/target/x86_64-unknown-linux-musl/release/build/paho-mqtt-sys-8d156c5b0c0125c7/out/build
running: "cmake" "--build" "." "--target" "install" "--config" "Release" "--"
Scanning dependencies of target common_ssl_obj
Scanning dependencies of target common_obj
[  9%] Building C object src/CMakeFiles/common_obj.dir/MQTTProtocolClient.c.o
[  9%] Building C object src/CMakeFiles/common_obj.dir/MQTTPacket.c.o
[  9%] Building C object src/CMakeFiles/common_obj.dir/Clients.c.o
[  9%] Building C object src/CMakeFiles/common_obj.dir/MQTTPacketOut.c.o
[  9%] Building C object src/CMakeFiles/common_obj.dir/StackTrace.c.o
[  9%] Building C object src/CMakeFiles/common_obj.dir/utf-8.c.o
[ 10%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTProtocolClient.c.o
[ 12%] Building C object src/CMakeFiles/common_obj.dir/Messages.c.o
[ 13%] Building C object src/CMakeFiles/common_obj.dir/Tree.c.o
[ 15%] Building C object src/CMakeFiles/common_obj.dir/Socket.c.o
[ 16%] Building C object src/CMakeFiles/common_obj.dir/Log.c.o
[ 18%] Building C object src/CMakeFiles/common_obj.dir/MQTTPersistence.c.o
[ 19%] Building C object src/CMakeFiles/common_obj.dir/Thread.c.o
[ 21%] Building C object src/CMakeFiles/common_obj.dir/MQTTProtocolOut.c.o
[ 22%] Building C object src/CMakeFiles/common_obj.dir/MQTTPersistenceDefault.c.o
[ 24%] Building C object src/CMakeFiles/common_ssl_obj.dir/Clients.c.o
[ 25%] Building C object src/CMakeFiles/common_obj.dir/SocketBuffer.c.o
[ 27%] Building C object src/CMakeFiles/common_obj.dir/Heap.c.o
[ 28%] Building C object src/CMakeFiles/common_obj.dir/LinkedList.c.o
[ 30%] Building C object src/CMakeFiles/common_ssl_obj.dir/utf-8.c.o
[ 31%] Building C object src/CMakeFiles/common_obj.dir/MQTTProperties.c.o
[ 33%] Building C object src/CMakeFiles/common_obj.dir/MQTTReasonCodes.c.o
[ 34%] Building C object src/CMakeFiles/common_obj.dir/Base64.c.o
[ 36%] Building C object src/CMakeFiles/common_obj.dir/SHA1.c.o
[ 37%] Building C object src/CMakeFiles/common_obj.dir/WebSocket.c.o
[ 39%] Building C object src/CMakeFiles/common_ssl_obj.dir/StackTrace.c.o
[ 40%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTPacket.c.o
[ 42%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTPacketOut.c.o
[ 43%] Building C object src/CMakeFiles/common_ssl_obj.dir/Messages.c.o
[ 45%] Building C object src/CMakeFiles/common_ssl_obj.dir/Tree.c.o
[ 46%] Building C object src/CMakeFiles/common_ssl_obj.dir/Socket.c.o
[ 48%] Building C object src/CMakeFiles/common_ssl_obj.dir/Log.c.o
[ 50%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTPersistence.c.o
[ 51%] Building C object src/CMakeFiles/common_ssl_obj.dir/Thread.c.o
[ 53%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTProtocolOut.c.o
[ 53%] Built target common_obj
[ 54%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTPersistenceDefault.c.o
Scanning dependencies of target paho-mqtt3c-static
[ 57%] Building C object src/CMakeFiles/paho-mqtt3c-static.dir/MQTTClient.c.o
[ 57%] Building C object src/CMakeFiles/common_ssl_obj.dir/SocketBuffer.c.o
[ 59%] Building C object src/CMakeFiles/common_ssl_obj.dir/Heap.c.o
[ 60%] Building C object src/CMakeFiles/common_ssl_obj.dir/LinkedList.c.o
[ 62%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTProperties.c.o
[ 63%] Building C object src/CMakeFiles/common_ssl_obj.dir/MQTTReasonCodes.c.o
[ 65%] Building C object src/CMakeFiles/common_ssl_obj.dir/Base64.c.o
Scanning dependencies of target paho-mqtt3a-static
[ 66%] Building C object src/CMakeFiles/paho-mqtt3a-static.dir/MQTTAsync.c.o
[ 68%] Building C object src/CMakeFiles/common_ssl_obj.dir/SHA1.c.o
[ 69%] Building C object src/CMakeFiles/common_ssl_obj.dir/WebSocket.c.o
Scanning dependencies of target paho-mqtt3a
[ 71%] Building C object src/CMakeFiles/paho-mqtt3a.dir/MQTTAsync.c.o
Scanning dependencies of target paho-mqtt3c
[ 72%] Building C object src/CMakeFiles/paho-mqtt3c.dir/MQTTClient.c.o
[ 72%] Built target common_ssl_obj
Scanning dependencies of target paho-mqtt3as-static
[ 74%] Building C object src/CMakeFiles/paho-mqtt3as-static.dir/MQTTAsync.c.o
[ 75%] Linking C static library libpaho-mqtt3c-static.a
[ 75%] Built target paho-mqtt3c-static
Scanning dependencies of target paho-mqtt3cs-static
[ 77%] Building C object src/CMakeFiles/paho-mqtt3cs-static.dir/MQTTClient.c.o
[ 78%] Linking C shared library libpaho-mqtt3c.so
src/CMakeFiles/paho-mqtt3c.dir/build.make:138: recipe for target 'src/libpaho-mqtt3c.so.1.3.1' failed
CMakeFiles/Makefile2:475: recipe for target 'src/CMakeFiles/paho-mqtt3c.dir/all' failed
[ 80%] Building C object src/CMakeFiles/paho-mqtt3cs-static.dir/SSLSocket.c.o
[ 81%] Building C object src/CMakeFiles/paho-mqtt3as-static.dir/SSLSocket.c.o
[ 83%] Linking C static library libpaho-mqtt3a-static.a
[ 84%] Linking C shared library libpaho-mqtt3a.so
src/CMakeFiles/paho-mqtt3a.dir/build.make:138: recipe for target 'src/libpaho-mqtt3a.so.1.3.1' failed
CMakeFiles/Makefile2:544: recipe for target 'src/CMakeFiles/paho-mqtt3a.dir/all' failed
[ 84%] Built target paho-mqtt3a-static
[ 86%] Linking C static library libpaho-mqtt3cs-static.a
[ 86%] Built target paho-mqtt3cs-static
[ 87%] Linking C static library libpaho-mqtt3as-static.a
[ 87%] Built target paho-mqtt3as-static
Makefile:149: recipe for target 'all' failed

--- stderr
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_CXX_COMPILER
    CMAKE_CXX_FLAGS

/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c: In function 'StackTrace_entry':
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c:110:34: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   Log_stackTrace(trace_level, 9, (int)my_thread->id, my_thread->current_depth, name, line, NULL);
                                  ^
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c: In function 'StackTrace_exit':
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c:134:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    Log_stackTrace(trace_level, 10, (int)my_thread->id, my_thread->current_depth, name, line, NULL);
                                    ^
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c:136:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    Log_stackTrace(trace_level, 11, (int)my_thread->id, my_thread->current_depth, name, line, (int*)rc);
                                    ^
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c: In function 'StackTrace_entry':
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c:110:34: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   Log_stackTrace(trace_level, 9, (int)my_thread->id, my_thread->current_depth, name, line, NULL);
                                  ^
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c: In function 'StackTrace_exit':
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c:134:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    Log_stackTrace(trace_level, 10, (int)my_thread->id, my_thread->current_depth, name, line, NULL);
                                    ^
/home/rust/src/paho-mqtt-sys/paho.mqtt.c/src/StackTrace.c:136:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    Log_stackTrace(trace_level, 11, (int)my_thread->id, my_thread->current_depth, name, line, (int*)rc);
                                    ^
/usr/bin/ld: /usr/lib/x86_64-linux-musl/libc.a(__stack_chk_fail.o): relocation R_X86_64_32 against `__stack_chk_guard' can not be used when making a shared object; recompile with -fPIC
/usr/lib/x86_64-linux-musl/libc.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/libpaho-mqtt3c.so.1.3.1] Error 1
make[1]: *** [src/CMakeFiles/paho-mqtt3c.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: /usr/lib/x86_64-linux-musl/libc.a(__stack_chk_fail.o): relocation R_X86_64_32 against `__stack_chk_guard' can not be used when making a shared object; recompile with -fPIC
/usr/lib/x86_64-linux-musl/libc.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/libpaho-mqtt3a.so.1.3.1] Error 1
make[1]: *** [src/CMakeFiles/paho-mqtt3a.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', /home/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.42/src/lib.rs:861:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed

What did you hope to happen? build a static binary with mqtt successfully

Does ./test-image work? N/A

Additional information N/A

Is there anything else that we should know? N/A

emk commented 4 years ago

Thank you for your bug report!

The key error here is:

/usr/bin/ld: /usr/lib/x86_64-linux-musl/libc.a(__stack_chk_fail.o): relocation R_X86_64_32 against `__stack_chk_guard' can not be used when making a shared object; recompile with -fPIC

It looks like the paho-mqtt-sys crate does not support compiling against a musl-libc target, unfortunately. Adding support to paho-mqtt-sys is likely to require several hours of experimenting with build flags. This would need to be done as part of the paho-mqtt-sys project, since it includes the C code for Paho MQTT.

Thank you for the bug report!