purpleprotocol / mimalloc_rust

A Rust wrapper over Microsoft's MiMalloc memory allocator
MIT License
503 stars 41 forks source link

Error when building for musl target: can't find musl-g++ #8

Closed nerdrew closed 4 years ago

nerdrew commented 4 years ago
% cargo build --target=x86_64-unknown-linux-musl
...
Caused by:
  process didn't exit successfully: `target/release/build/libmimalloc-sys-eebdbef667752ca0/build-script-build` (exit code: 101)
--- stdout
running: "cmake" "cmake" "~/.cargo/registry/src/github.com-1ecc6299db9ec823/libmimalloc-sys-0.1.8/c_src/mimalloc" "-DMI_OVERRIDE=OFF" "-DMI_SECURE=OFF" "-DMI_SECURE_FULL=OFF" "-DMI_BUILD_TESTS=OFF" "-Dmi_defines=MI_DEBUG=0" "-DCMAKE_INSTALL_PREFIX=target/x86_64-unknown-linux-musl/release/build/libmimalloc-sys-5d740689cb365526/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=musl-g++" "-DCMAKE_BUILD_TYPE=Release"
-- The CXX compiler identification is unknown
-- Configuring incomplete, errors occurred!

It looks like cmake is looking for a c++ compiler. Does mimalloc require a c++ compiler?

nerdrew commented 4 years ago

note: I edited some of those paths to make them relative...

nerdrew commented 4 years ago

This is in the CMakeError.log:

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: musl-g++ 
Build flags: ;-ffunction-sections;-fdata-sections;-fPIC;-m64;-static
Id flags:  

The output was:
No such file or directory

Wonder if this is just a cmake problem...

octavonce commented 4 years ago

Hi @nerdrew!

We are using mimalloc on purple we are building on musl as well. The reason cmake is looking for a c++ compiler is because the mimalloc cmake file offers building mimalloc with a c++ compiler as well by passing a flag. It seems that if you don't pass the c++ flag it will not use the c++ compiler but it still needs it to be installed in order to run.

If you are building with docker, the solution seems to be to just run apk add g++ on the builder container and then copy the resulting binary to the final container.

I hope this helps you!