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 build on ubuntu 16.04 #8

Closed piaoger closed 7 years ago

piaoger commented 7 years ago

I can build one internal project successfully with cargo directly, but encounter error message with rust-musl-builder.

below are more details:

environment

('Ubuntu', '16.04', 'xenial')

Run:

alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder' rust-musl-builder cargo build --release

Error message

Compiling pkg-config v0.3.6 Compiling winapi-build v0.1.1 Compiling bitflags v0.1.1 Compiling clap v1.5.5 Compiling fnv v1.0.3 Compiling memchr v0.1.11 Compiling unicode-normalization v0.1.2 Compiling gcc v0.3.21 Compiling advapi32-sys v0.1.2 error: linking with cc failed: exit code: 1 | = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/rust/src/target/release/build/advapi32-sys-7ea5190fd4bcfa0c/build_script_build.0.o" "-o" "/home/rust/src/target/release/build/advapi32-sys-7ea5190fd4bcfa0c/build_script_build" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/rust/src/target/release/deps" "-L" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/rust/src/target/release/deps/libbuild-493a7b0628804707.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-5c6cf767.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt" = note: cc: error: /home/rust/src/target/release/build/advapi32-sys-7ea5190fd4bcfa0c/build_script_build.0.o: Permission denied cc: error: /home/rust/src/target/release/deps/libbuild-493a7b0628804707.rlib: Permission denied

error: aborting due to previous error

Compiling ws2_32-sys v0.2.1 Build failed, waiting for other jobs to finish... error: linking with cc failed: exit code: 1 | = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/rust/src/target/release/build/ws2_32-sys-fe7373db9ed2332c/build_script_build.0.o" "-o" "/home/rust/src/target/release/build/ws2_32-sys-fe7373db9ed2332c/build_script_build" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/rust/src/target/release/deps" "-L" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/rust/src/target/release/deps/libbuild-493a7b0628804707.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-5c6cf767.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt" = note: cc: error: /home/rust/src/target/release/build/ws2_32-sys-fe7373db9ed2332c/build_script_build.0.o: Permission denied cc: error: /home/rust/src/target/release/deps/libbuild-493a7b0628804707.rlib: Permission denied

error: aborting due to previous error

Build failed, waiting for other jobs to finish... error: Could not compile advapi32-sys.

piaoger commented 7 years ago

I also tried to create a new project "good" with cargo new, still repro:

administrator@linux64:~/good$ ./build-release app v1 Building static binaries using ekidd/rust-musl-builder Compiling good v0.1.0 (file:///home/rust/src) error: linking with cc failed: exit code: 1 | = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-nostdlib" "-static" "-Wl,--eh-frame-hdr" "-Wl,-(" "-m64" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crt1.o" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crti.o" "-L" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/good.0.o" "-o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/good" "-Wl,--gc-sections" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps" "-L" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librand-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcollections-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_unicode-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc_jemalloc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-5c6cf767.rlib" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-5c6cf767.rlib" "-l" "compiler-rt" "/home/rust/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crtn.o" "-Wl,-)" = note: cc: error: /home/rust/src/target/x86_64-unknown-linux-musl/release/good.0.o: Permission denied

error: aborting due to previous error

error: Could not compile good.

To learn more, run the command again with --verbose.

emk commented 7 years ago

Looks like a permission problem. To invoke rust-musl-builder that way, you usually need to have UID 1000. Try passing --user to docker—I'm not exactly sure how to do it but I know it's possible. Or build your source code into the image and get the binaries back out with docker cp.

Let me know whether you get it working! I'm happy to update the instructions if you find a good solution.

piaoger commented 7 years ago

thanks for you feedback. I will let you know if I find a way finally.,

piaoger commented 7 years ago

below blog might be helpful: https://denibertovic.com/posts/handling-permissions-with-docker-volumes/

I choose to copy source into container and docker cp back as you suggested..

emk commented 7 years ago

OK, it sounds like there's a workaround for this issue. Thank you for reporting it, and I'll see if I can't come up with a more general fix someday!