KarsMulder / evsieve

A utility for mapping events from Linux event devices.
GNU General Public License v2.0
199 stars 11 forks source link

Cross Build evsieve for Alpine #12

Closed aggo15 closed 2 years ago

aggo15 commented 2 years ago

I attempted to cross build evsieve for Alpine but I get this error instead.

These are the steps that I did for the build.

  1. apt-get install -y --no-install-recommends libevdev2 libevdev-dev wget musl-tools make g++ libc6-dev
  2. wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz
  3. tar -xzf evsieve-1.3.1.tar.gz && cd /evsieve-1.3.1
  4. rustup target add arm-unknown-linux-musleabihf
  5. cargo build -vv --target arm-unknown-linux-musleabihf --release

Here are the build logs. Error message is at the end


 Downloading crates ...
  Downloaded lazy_static v1.4.0
  Downloaded libc v0.2.82
   Compiling libc v0.2.82
   Compiling evsieve v1.3.1 (/evsieve-1.3.1)
   Compiling lazy_static v1.4.0
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' rustc --crate-name build_script_build /usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82/build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1e8fe370016abd8d -C extra-filename=-1e8fe370016abd8d --out-dir /evsieve-1.3.1/target/release/build/libc-1e8fe370016abd8d -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=lazy_static CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1285ae84e5963aae/lazy_static-1.4.0 CARGO_PKG_AUTHORS='Marvin Löbel <loebel.marvin@gmail.com>' CARGO_PKG_DESCRIPTION='A macro for declaring lazily evaluated statics in Rust.' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT/Apache-2.0 CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=lazy_static CARGO_PKG_REPOSITORY='https://github.com/rust-lang-nursery/lazy-static.rs' CARGO_PKG_VERSION=1.4.0 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' rustc --crate-name lazy_static /usr/local/cargo/registry/src/github.com-1285ae84e5963aae/lazy_static-1.4.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto -C metadata=3d9ce34e1f2a1704 -C extra-filename=-3d9ce34e1f2a1704 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C metadata=22c4863004204d9f -C extra-filename=-22c4863004204d9f --out-dir /evsieve-1.3.1/target/release/build/evsieve-22c4863004204d9f -L dependency=/evsieve-1.3.1/target/release/deps`
     Running `/evsieve-1.3.1/target/release/build/evsieve-22c4863004204d9f/build-script-build`
[evsieve 1.3.1] cargo:rustc-link-lib=dylib=evdev
     Running `/evsieve-1.3.1/target/release/build/libc-1e8fe370016abd8d/build-script-build`
[libc 0.2.82] cargo:rustc-cfg=freebsd11
[libc 0.2.82] cargo:rustc-cfg=libc_priv_mod_use
[libc 0.2.82] cargo:rustc-cfg=libc_union
[libc 0.2.82] cargo:rustc-cfg=libc_const_size_of
[libc 0.2.82] cargo:rustc-cfg=libc_align
[libc 0.2.82] cargo:rustc-cfg=libc_core_cvoid
[libc 0.2.82] cargo:rustc-cfg=libc_packedN
[libc 0.2.82] cargo:rustc-cfg=libc_cfg_target_vendor
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=libc CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/libc-f2c09ad6e5d550cb/out rustc --crate-name libc /usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=30c486c1ef1c22c6 -C extra-filename=-30c486c1ef1c22c6 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/evsieve-726638333db86f48/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=c790f64dca250c82 -C extra-filename=-c790f64dca250c82 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblazy_static-3d9ce34e1f2a1704.rlib --extern libc=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblibc-30c486c1ef1c22c6.rlib -l dylib=evdev`
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crt1.o" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crti.o" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crtbegin.o" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-c790f64dca250c82.evsieve.4fac1677-cgu.3.rcgu.o" "-Wl,--as-needed" "-L" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps" "-L" "/evsieve-1.3.1/target/release/deps" "-L" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib" "-levdev" "-Wl,--start-group" "-Wl,-Bstatic" "-lunwind" "-lc" "-Wl,--end-group" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/libcompiler_builtins-b85afa065dacb413.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-nostartfiles" "-L" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib" "-L" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained" "-o" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-c790f64dca250c82" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crtend.o" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crtn.o"
  = note: /usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/libevdev.a(libevdev-uinput.o): in function `fetch_device_node':
          (.text.fetch_device_node+0x5e): undefined reference to `__asprintf_chk'
          /usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/libevdev.a(libevdev-uinput.o): in function `libevdev_uinput_create_from_device':
          (.text.libevdev_uinput_create_from_device+0x226): undefined reference to `__snprintf_chk'
          /usr/bin/ld: (.text.libevdev_uinput_create_from_device+0x266): undefined reference to `__snprintf_chk'
          /usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/libevdev.a(libevdev.o): in function `libevdev_dflt_log_func':
          (.text.libevdev_dflt_log_func+0x36): undefined reference to `__fprintf_chk'
          /usr/bin/ld: (.text.libevdev_dflt_log_func+0x44): undefined reference to `__fprintf_chk'
          /usr/bin/ld: (.text.libevdev_dflt_log_func+0x66): undefined reference to `__fprintf_chk'
          /usr/bin/ld: (.text.libevdev_dflt_log_func+0x7e): undefined reference to `__fprintf_chk'
          /usr/bin/ld: (.text.libevdev_dflt_log_func+0x8e): undefined reference to `__fprintf_chk'
          /usr/bin/ld: (.text.libevdev_dflt_log_func+0x56): undefined reference to `__vfprintf_chk'
          collect2: error: ld returned 1 exit status

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `evsieve` due to previous error

Caused by:
  process didn't exit successfully: `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/evsieve-726638333db86f48/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=c790f64dca250c82 -C extra-filename=-c790f64dca250c82 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblazy_static-3d9ce34e1f2a1704.rlib --extern libc=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblibc-30c486c1ef1c22c6.rlib -l dylib=evdev` (exit status: 1)```

What did i miss?
KarsMulder commented 2 years ago

Sorry, I am not well versed in cross-compiling; in fact, I have never actually done it before. From what I gather from some quick searches, the most common way to do this is by compiling software in some kind of Alpine chroot/container, which does not seem to be what you're trying to do, so I suppose you know more about cross compilation than I do.

Looking at output, the linker is throwing an error when it tries to resolve __fprintf_chk (and similar) calls in functions belonging to libevdev. __fprintf_chk seems to be a function that belongs to glibc but is not part of the C standard, and therefore probably absent in musl libc.

Evsieve has requested to dynamically link with libevdev according to the cargo:rustc-link-lib=dylib=evdev line. The target arm-unknown-linux-musleabihf statically links against musl libc by default.

I am not well versed enough in linkeromancy to say why the linker even cares about what functions are being called in a dynamically linked library, but it seems that the core issue is that the libevdev library that you're trying to link against is not compiled to be compatible with musl libc.

I suppose the "easy" fix would be to compile evsieve in an Alpine chroot/container where the installed version of libevdev is a version that is actually compiled for Alpine and expects musl libc to be used?

aggo15 commented 2 years ago

Thanks for the feedback @KarsMulder. Here is what I tried out using docker image from rust Alpine to build evsieve and see what is the result. Unfortunately image for armv7/arm Alpine is not available so I'm using amd64 image to try out first.

Dockerfile I'm using:

FROM rust:1.59.0-alpine3.15
RUN apk add libevdev libevdev-dev wget alpine-sdk && \
    wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz && \
    tar -xzf evsieve-1.3.1.tar.gz

WORKDIR /evsieve-1.3.1
RUN cargo build -vv --release

However I'm getting this error. See build log below:

Sending build context to Docker daemon  8.704kB
Step 1/4 : FROM rust:1.59.0-alpine3.15
 ---> 4879d25cff70
Step 2/4 : RUN apk add libevdev libevdev-dev wget alpine-sdk &&     wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz &&     tar -xzf evsieve-1.3.1.tar.gz
 ---> Running in 9deee1b154e0
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/31) Installing fakeroot (1.25.3-r3)
(2/31) Installing openssl (1.1.1l-r8)
(3/31) Installing libattr (2.5.1-r1)
(4/31) Installing attr (2.5.1-r1)
(5/31) Installing libacl (2.2.53-r0)
(6/31) Installing tar (1.34-r0)
(7/31) Installing pkgconf (1.8.0-r0)
(8/31) Installing patch (2.7.6-r7)
(9/31) Installing lzip (1.22-r1)
(10/31) Installing brotli-libs (1.0.9-r5)
(11/31) Installing nghttp2-libs (1.46.0-r0)
(12/31) Installing libcurl (7.80.0-r0)
(13/31) Installing curl (7.80.0-r0)
(14/31) Installing abuild (3.9.0-r0)
Executing abuild-3.9.0-r0.pre-install
(15/31) Installing libmagic (5.41-r0)
(16/31) Installing file (5.41-r0)
(17/31) Installing musl-dev (1.2.2-r7)
(18/31) Installing libc-dev (0.7.2-r3)
(19/31) Installing g++ (10.3.1_git20211027-r0)
(20/31) Installing make (4.3-r0)
(21/31) Installing fortify-headers (1.1-r1)
(22/31) Installing build-base (0.5-r2)
(23/31) Installing expat (2.4.7-r0)
(24/31) Installing pcre2 (10.39-r0)
(25/31) Installing git (2.34.1-r0)
(26/31) Installing alpine-sdk (1.0-r1)
(27/31) Installing libevdev (1.12.0-r0)
(28/31) Installing libevdev-dev (1.12.0-r0)
(29/31) Installing libunistring (0.9.10-r1)
(30/31) Installing libidn2 (2.3.2-r0)
(31/31) Installing wget (1.21.2-r2)
Executing busybox-1.34.1-r3.trigger
OK: 214 MiB in 57 packages
--2022-03-10 03:46:51--  https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/KarsMulder/evsieve/tar.gz/refs/tags/v1.3.1 [following]
--2022-03-10 03:46:51--  https://codeload.github.com/KarsMulder/evsieve/tar.gz/refs/tags/v1.3.1
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: 'evsieve-1.3.1.tar.gz'

     0K .......... .......... .......... .......... .......... 2.73M
    50K .......... .......... .......... .......... .......... 9.30M
   100K .......... .........                                   24.6M=0.02s

2022-03-10 03:46:52 (4.90 MB/s) - 'evsieve-1.3.1.tar.gz' saved [122665]

Removing intermediate container 9deee1b154e0
 ---> 6d35bcd3cadb
Step 3/4 : WORKDIR /evsieve-1.3.1
 ---> Running in 68f5f3b4de60
Removing intermediate container 68f5f3b4de60
 ---> 9cd739246360
Step 4/4 : RUN cargo build -vv --release
 ---> Running in b1478f1c1c5f
    Updating crates.io index
 Downloading crates ...
  Downloaded lazy_static v1.4.0
  Downloaded libc v0.2.82
   Compiling libc v0.2.82
   Compiling evsieve v1.3.1 (/evsieve-1.3.1)
   Compiling lazy_static v1.4.0
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' rustc --crate-name build_script_build /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82/build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=a4b63ca1240f5920 -C extra-filename=-a4b63ca1240f5920 --out-dir /evsieve-1.3.1/target/release/build/libc-a4b63ca1240f5920 -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C metadata=05f53b5e62108660 -C extra-filename=-05f53b5e62108660 --out-dir /evsieve-1.3.1/target/release/build/evsieve-05f53b5e62108660 -L dependency=/evsieve-1.3.1/target/release/deps`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=lazy_static CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0 CARGO_PKG_AUTHORS='Marvin Löbel <loebel.marvin@gmail.com>' CARGO_PKG_DESCRIPTION='A macro for declaring lazily evaluated statics in Rust.' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT/Apache-2.0 CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=lazy_static CARGO_PKG_REPOSITORY='https://github.com/rust-lang-nursery/lazy-static.rs' CARGO_PKG_VERSION=1.4.0 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' rustc --crate-name lazy_static /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto -C metadata=e36632a20d3280ca -C extra-filename=-e36632a20d3280ca --out-dir /evsieve-1.3.1/target/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn`
     Running `/evsieve-1.3.1/target/release/build/evsieve-05f53b5e62108660/build-script-build`
[evsieve 1.3.1] cargo:rustc-link-lib=dylib=evdev
     Running `/evsieve-1.3.1/target/release/build/libc-a4b63ca1240f5920/build-script-build`
[libc 0.2.82] cargo:rustc-cfg=freebsd11
[libc 0.2.82] cargo:rustc-cfg=libc_priv_mod_use
[libc 0.2.82] cargo:rustc-cfg=libc_union
[libc 0.2.82] cargo:rustc-cfg=libc_const_size_of
[libc 0.2.82] cargo:rustc-cfg=libc_align
[libc 0.2.82] cargo:rustc-cfg=libc_core_cvoid
[libc 0.2.82] cargo:rustc-cfg=libc_packedN
[libc 0.2.82] cargo:rustc-cfg=libc_cfg_target_vendor
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=libc CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' OUT_DIR=/evsieve-1.3.1/target/release/build/libc-f254a8604bb83388/out rustc --crate-name libc /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=a723d2019d203a22 -C extra-filename=-a723d2019d203a22 --out-dir /evsieve-1.3.1/target/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' OUT_DIR=/evsieve-1.3.1/target/release/build/evsieve-91446c74927dd9a4/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=4836aae4103fb06e -C extra-filename=-4836aae4103fb06e --out-dir /evsieve-1.3.1/target/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/release/deps/liblazy_static-e36632a20d3280ca.rlib --extern libc=/evsieve-1.3.1/target/release/deps/liblibc-a723d2019d203a22.rlib -l dylib=evdev`
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/rcrt1.o" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbeginS.o" "/evsieve-1.3.1/target/release/deps/evsieve-4836aae4103fb06e.evsieve.93ffb939-cgu.3.rcgu.o" "-Wl,--as-needed" "-L" "/evsieve-1.3.1/target/release/deps" "-L" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-levdev" "-Wl,--start-group" "-Wl,-Bstatic" "-lunwind" "-lc" "-Wl,--end-group" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-71972cde1db06d51.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-nostartfiles" "-L" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-L" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "-o" "/evsieve-1.3.1/target/release/deps/evsieve-4836aae4103fb06e" "-Wl,--gc-sections" "-static-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -levdev
          collect2: error: ld returned 1 exit status

error: could not compile `evsieve` due to previous error

Caused by:
  process didn't exit successfully: `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' OUT_DIR=/evsieve-1.3.1/target/release/build/evsieve-91446c74927dd9a4/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=4836aae4103fb06e -C extra-filename=-4836aae4103fb06e --out-dir /evsieve-1.3.1/target/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/release/deps/liblazy_static-e36632a20d3280ca.rlib --extern libc=/evsieve-1.3.1/target/release/deps/liblibc-a723d2019d203a22.rlib -l dylib=evdev` (exit status: 1)
The command '/bin/sh -c cargo build -vv --release' returned a non-zero code: 101

Sounds like I'm missing some evdev related dependencies. Not sure if I'm installing correct packages for Alpine. Any idea?

aggo15 commented 2 years ago

I'm also turning my original post steps into docker image for replicating the build process easier. I made a little progress, now the __fprintf_chk error are gone but I'm greeted with another error arm-linux-gnueabihf-ld: //lib/arm-linux-gnueabihf/ld-linux-armhf.so.3: error adding symbols: DSO missing from command line. Please refer to below for steps to replicate the build.

Dockerfile:

FROM rust:1.59.0-slim-buster AS builder

RUN apt-get update && apt-get install -y --no-install-recommends \
      libc6-dev-armhf-cross \
      libc6-armhf-cross \
      musl-tools \
      libevdev2 \
      libevdev-dev \
      wget && \
    rustup target add arm-unknown-linux-musleabihf && \
    wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz && \
    tar -xzf evsieve-1.3.1.tar.gz

WORKDIR /evsieve-1.3.1

RUN CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-ld \
    REALGCC=arm-linux-gnueabihf-gcc-8 \
    TARGET_CC=musl-gcc \
    cargo build -vv --target=arm-unknown-linux-musleabihf --release

The build log:

Sending build context to Docker daemon  28.16kB
Step 1/4 : FROM rust:1.59.0-slim-buster AS builder
 ---> 6a11845a64b6
Step 2/4 : RUN apt-get update && apt-get install -y --no-install-recommends       libc6-dev-armhf-cross       libc6-armhf-cross       musl-tools       libevdev2       libevdev-dev       wget &&     rustup target add arm-unknown-linux-musleabihf &&     wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz &&     tar -xzf evsieve-1.3.1.tar.gz
 ---> Running in 02641e8a1fef
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main armhf Packages [315 kB]
Get:5 http://deb.debian.org/debian buster/main armhf Packages [7698 kB]
Get:6 http://deb.debian.org/debian buster-updates/main armhf Packages [8792 B]
Fetched 8260 kB in 7s (1114 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libpcre2-8-0 libpsl5 linux-libc-dev-armhf-cross musl musl-dev
Suggested packages:
  libevdev-doc
Recommended packages:
  publicsuffix linux-musl-dev
The following NEW packages will be installed:
  libc6-armhf-cross libc6-dev-armhf-cross libevdev-dev libevdev2 libpcre2-8-0
  libpsl5 linux-libc-dev-armhf-cross musl musl-dev musl-tools wget
0 upgraded, 11 newly installed, 0 to remove and 1 not upgraded.
Need to get 6665 kB of archives.
After this operation, 12.6 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main armhf libpcre2-8-0 armhf 10.32-5 [190 kB]
Get:2 http://deb.debian.org/debian buster/main armhf libpsl5 armhf 0.20.2-2 [52.4 kB]
Get:3 http://deb.debian.org/debian buster/main armhf wget armhf 1.20.1-1.1 [881 kB]
Get:4 http://deb.debian.org/debian buster/main armhf libc6-armhf-cross all 2.28-7cross1 [1170 kB]
Get:5 http://deb.debian.org/debian buster/main armhf linux-libc-dev-armhf-cross all 4.19.20-1cross1 [1212 kB]
Get:6 http://deb.debian.org/debian buster/main armhf libc6-dev-armhf-cross all 2.28-7cross1 [2148 kB]
Get:7 http://deb.debian.org/debian buster/main armhf libevdev2 armhf 1.6.0+dfsg-1 [25.3 kB]
Get:8 http://deb.debian.org/debian buster/main armhf libevdev-dev armhf 1.6.0+dfsg-1 [45.4 kB]
Get:9 http://deb.debian.org/debian buster/main armhf musl armhf 1.1.21-2 [367 kB]
Get:10 http://deb.debian.org/debian buster/main armhf musl-dev armhf 1.1.21-2 [536 kB]
Get:11 http://deb.debian.org/debian buster/main armhf musl-tools armhf 1.1.21-2 [37.4 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 6665 kB in 10s (670 kB/s)
Selecting previously unselected package libpcre2-8-0:armhf.
(Reading database ... 8676 files and directories currently installed.)
Preparing to unpack .../00-libpcre2-8-0_10.32-5_armhf.deb ...
Unpacking libpcre2-8-0:armhf (10.32-5) ...
Selecting previously unselected package libpsl5:armhf.
Preparing to unpack .../01-libpsl5_0.20.2-2_armhf.deb ...
Unpacking libpsl5:armhf (0.20.2-2) ...
Selecting previously unselected package wget.
Preparing to unpack .../02-wget_1.20.1-1.1_armhf.deb ...
Unpacking wget (1.20.1-1.1) ...
Selecting previously unselected package libc6-armhf-cross.
Preparing to unpack .../03-libc6-armhf-cross_2.28-7cross1_all.deb ...
Unpacking libc6-armhf-cross (2.28-7cross1) ...
Selecting previously unselected package linux-libc-dev-armhf-cross.
Preparing to unpack .../04-linux-libc-dev-armhf-cross_4.19.20-1cross1_all.deb ...
Unpacking linux-libc-dev-armhf-cross (4.19.20-1cross1) ...
Selecting previously unselected package libc6-dev-armhf-cross.
Preparing to unpack .../05-libc6-dev-armhf-cross_2.28-7cross1_all.deb ...
Unpacking libc6-dev-armhf-cross (2.28-7cross1) ...
Selecting previously unselected package libevdev2:armhf.
Preparing to unpack .../06-libevdev2_1.6.0+dfsg-1_armhf.deb ...
Unpacking libevdev2:armhf (1.6.0+dfsg-1) ...
Selecting previously unselected package libevdev-dev:armhf.
Preparing to unpack .../07-libevdev-dev_1.6.0+dfsg-1_armhf.deb ...
Unpacking libevdev-dev:armhf (1.6.0+dfsg-1) ...
Selecting previously unselected package musl:armhf.
Preparing to unpack .../08-musl_1.1.21-2_armhf.deb ...
Unpacking musl:armhf (1.1.21-2) ...
Selecting previously unselected package musl-dev:armhf.
Preparing to unpack .../09-musl-dev_1.1.21-2_armhf.deb ...
Unpacking musl-dev:armhf (1.1.21-2) ...
Selecting previously unselected package musl-tools.
Preparing to unpack .../10-musl-tools_1.1.21-2_armhf.deb ...
Unpacking musl-tools (1.1.21-2) ...
Setting up libpsl5:armhf (0.20.2-2) ...
Setting up libc6-armhf-cross (2.28-7cross1) ...
Setting up linux-libc-dev-armhf-cross (4.19.20-1cross1) ...
Setting up libpcre2-8-0:armhf (10.32-5) ...
Setting up musl:armhf (1.1.21-2) ...
Setting up libevdev2:armhf (1.6.0+dfsg-1) ...
Setting up wget (1.20.1-1.1) ...
Setting up libevdev-dev:armhf (1.6.0+dfsg-1) ...
Setting up libc6-dev-armhf-cross (2.28-7cross1) ...
Setting up musl-dev:armhf (1.1.21-2) ...
Setting up musl-tools (1.1.21-2) ...
Processing triggers for libc-bin (2.28-10) ...
info: downloading component 'rust-std' for 'arm-unknown-linux-musleabihf'
info: installing component 'rust-std' for 'arm-unknown-linux-musleabihf'
--2022-03-10 08:51:29--  https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/KarsMulder/evsieve/tar.gz/refs/tags/v1.3.1 [following]
--2022-03-10 08:51:29--  https://codeload.github.com/KarsMulder/evsieve/tar.gz/refs/tags/v1.3.1
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: 'evsieve-1.3.1.tar.gz'

     0K .......... .......... .......... .......... ..........  320K
    50K .......... .......... .......... .......... ..........  381K
   100K .......... .........                                   2.58M=0.3s

2022-03-10 08:51:30 (406 KB/s) - 'evsieve-1.3.1.tar.gz' saved [122665]

Removing intermediate container 02641e8a1fef
 ---> 0a27f5dbd8d3
Step 3/4 : WORKDIR /evsieve-1.3.1
 ---> Running in 633a3b8e7070
Removing intermediate container 633a3b8e7070
 ---> dff61ef425ad
Step 4/4 : RUN CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-ld     REALGCC=arm-linux-gnueabihf-gcc-8     TARGET_CC=musl-gcc     cargo build -vv --target=arm-unknown-linux-musleabihf --release
 ---> Running in e209b9e56bdf
    Updating crates.io index
 Downloading crates ...
  Downloaded lazy_static v1.4.0
  Downloaded libc v0.2.82
   Compiling libc v0.2.82
   Compiling evsieve v1.3.1 (/evsieve-1.3.1)
   Compiling lazy_static v1.4.0
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' rustc --crate-name build_script_build /usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82/build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1e8fe370016abd8d -C extra-filename=-1e8fe370016abd8d --out-dir /evsieve-1.3.1/target/release/build/libc-1e8fe370016abd8d -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C metadata=22c4863004204d9f -C extra-filename=-22c4863004204d9f --out-dir /evsieve-1.3.1/target/release/build/evsieve-22c4863004204d9f -L dependency=/evsieve-1.3.1/target/release/deps`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=lazy_static CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1285ae84e5963aae/lazy_static-1.4.0 CARGO_PKG_AUTHORS='Marvin Löbel <loebel.marvin@gmail.com>' CARGO_PKG_DESCRIPTION='A macro for declaring lazily evaluated statics in Rust.' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT/Apache-2.0 CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=lazy_static CARGO_PKG_REPOSITORY='https://github.com/rust-lang-nursery/lazy-static.rs' CARGO_PKG_VERSION=1.4.0 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' rustc --crate-name lazy_static /usr/local/cargo/registry/src/github.com-1285ae84e5963aae/lazy_static-1.4.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto -C metadata=3d9ce34e1f2a1704 -C extra-filename=-3d9ce34e1f2a1704 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -C linker=arm-linux-gnueabihf-ld -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn`
     Running `/evsieve-1.3.1/target/release/build/evsieve-22c4863004204d9f/build-script-build`
[evsieve 1.3.1] cargo:rustc-link-lib=dylib=evdev
     Running `/evsieve-1.3.1/target/release/build/libc-1e8fe370016abd8d/build-script-build`
[libc 0.2.82] cargo:rustc-cfg=freebsd11
[libc 0.2.82] cargo:rustc-cfg=libc_priv_mod_use
[libc 0.2.82] cargo:rustc-cfg=libc_union
[libc 0.2.82] cargo:rustc-cfg=libc_const_size_of
[libc 0.2.82] cargo:rustc-cfg=libc_align
[libc 0.2.82] cargo:rustc-cfg=libc_core_cvoid
[libc 0.2.82] cargo:rustc-cfg=libc_packedN
[libc 0.2.82] cargo:rustc-cfg=libc_cfg_target_vendor
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_CRATE_NAME=libc CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/libc-f2c09ad6e5d550cb/out rustc --crate-name libc /usr/local/cargo/registry/src/github.com-1285ae84e5963aae/libc-0.2.82/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=30c486c1ef1c22c6 -C extra-filename=-30c486c1ef1c22c6 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -C linker=arm-linux-gnueabihf-ld -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/evsieve-726638333db86f48/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=c790f64dca250c82 -C extra-filename=-c790f64dca250c82 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -C linker=arm-linux-gnueabihf-ld -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblazy_static-3d9ce34e1f2a1704.rlib --extern libc=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblibc-30c486c1ef1c22c6.rlib -l dylib=evdev`
error: linking with `arm-linux-gnueabihf-ld` failed: exit status: 1
  |
  = note: "arm-linux-gnueabihf-ld" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crt1.o" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crti.o" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crtbegin.o" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-c790f64dca250c82.evsieve.4fac1677-cgu.3.rcgu.o" "--as-needed" "-L" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps" "-L" "/evsieve-1.3.1/target/release/deps" "-L" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib" "-levdev" "--start-group" "-Bstatic" "-lunwind" "-lc" "--end-group" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/libcompiler_builtins-b85afa065dacb413.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib" "-L" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained" "-o" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-c790f64dca250c82" "--gc-sections" "-static" "-zrelro" "-znow" "-O1" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crtend.o" "/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/crtn.o"
  = note: arm-linux-gnueabihf-ld: /usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/libc.a(__stack_chk_fail.lo): undefined reference to symbol '__stack_chk_guard@@GLIBC_2.4'
          arm-linux-gnueabihf-ld: //lib/arm-linux-gnueabihf/ld-linux-armhf.so.3: error adding symbols: DSO missing from command line

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `evsieve` due to previous error

Caused by:
  process didn't exit successfully: `CARGO=/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib:/usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/evsieve-726638333db86f48/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=c790f64dca250c82 -C extra-filename=-c790f64dca250c82 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -C linker=arm-linux-gnueabihf-ld -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblazy_static-3d9ce34e1f2a1704.rlib --extern libc=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblibc-30c486c1ef1c22c6.rlib -l dylib=evdev` (exit status: 1)
The command '/bin/sh -c CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-ld     REALGCC=arm-linux-gnueabihf-gcc-8     TARGET_CC=musl-gcc     cargo build -vv --target=arm-unknown-linux-musleabihf --release' returned a non-zero code: 101

Any idea moving forward?

KarsMulder commented 2 years ago

I haven't found confirmation in the documentation on this, but I am getting the impression that when Rust tries to statically link against the C runtime, it also tries to statically link everything else, including libraries that were requested to be dynamically linked. Therefore, the linker in the Alpine docker fails to find libevdev because it is searching for a static object file libevdev.o whereas only a shared object libevdev.so is present.

Evsieve builds successfully if I ask the Rust compiler to dynamically link against the C runtime by specifying the following RUSTFLAGS environment variable:

FROM rust:1.59.0-alpine3.15
RUN apk add libevdev libevdev-dev wget alpine-sdk && \
    wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz && \
    tar -xzf evsieve-1.3.1.tar.gz

WORKDIR /evsieve-1.3.1
ENV RUSTFLAGS='-C target-feature=-crt-static' 
RUN cargo build -vv --release
aggo15 commented 2 years ago

@KarsMulder I can confirm from here that the build indeed success after adding the environment variable you mentioned.

Unfortunately, when I change the target to the one I needed arm-unknown-linux-musleabihf, the build failed. Please refer to below for the build log.

Modified Dockerfile

FROM rust:1.59.0-alpine3.15
RUN apk add libevdev libevdev-dev wget alpine-sdk && \
    wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz && \
    tar -xzf evsieve-1.3.1.tar.gz

WORKDIR /evsieve-1.3.1
ENV RUSTFLAGS='-C target-feature=-crt-static'
RUN rustup target add arm-unknown-linux-musleabihf && \
    cargo build -vv --target=arm-unknown-linux-musleabihf --release

The build log

Sending build context to Docker daemon  9.728kB
Step 1/5 : FROM rust:1.59.0-alpine3.15
 ---> 4879d25cff70
Step 2/5 : RUN apk add libevdev libevdev-dev wget alpine-sdk &&     wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz &&     tar -xzf evsieve-1.3.1.tar.gz
 ---> Running in 5c58b0b8f5fd
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/31) Installing fakeroot (1.25.3-r3)
(2/31) Installing openssl (1.1.1l-r8)
(3/31) Installing libattr (2.5.1-r1)
(4/31) Installing attr (2.5.1-r1)
(5/31) Installing libacl (2.2.53-r0)
(6/31) Installing tar (1.34-r0)
(7/31) Installing pkgconf (1.8.0-r0)
(8/31) Installing patch (2.7.6-r7)
(9/31) Installing lzip (1.22-r1)
(10/31) Installing brotli-libs (1.0.9-r5)
(11/31) Installing nghttp2-libs (1.46.0-r0)
(12/31) Installing libcurl (7.80.0-r0)
(13/31) Installing curl (7.80.0-r0)
(14/31) Installing abuild (3.9.0-r0)
Executing abuild-3.9.0-r0.pre-install
(15/31) Installing libmagic (5.41-r0)
(16/31) Installing file (5.41-r0)
(17/31) Installing musl-dev (1.2.2-r7)
(18/31) Installing libc-dev (0.7.2-r3)
(19/31) Installing g++ (10.3.1_git20211027-r0)
(20/31) Installing make (4.3-r0)
(21/31) Installing fortify-headers (1.1-r1)
(22/31) Installing build-base (0.5-r2)
(23/31) Installing expat (2.4.7-r0)
(24/31) Installing pcre2 (10.39-r0)
(25/31) Installing git (2.34.1-r0)
(26/31) Installing alpine-sdk (1.0-r1)
(27/31) Installing libevdev (1.12.0-r0)
(28/31) Installing libevdev-dev (1.12.0-r0)
(29/31) Installing libunistring (0.9.10-r1)
(30/31) Installing libidn2 (2.3.2-r0)
(31/31) Installing wget (1.21.2-r2)
Executing busybox-1.34.1-r3.trigger
OK: 214 MiB in 57 packages
--2022-03-10 10:47:16--  https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/KarsMulder/evsieve/tar.gz/refs/tags/v1.3.1 [following]
--2022-03-10 10:47:17--  https://codeload.github.com/KarsMulder/evsieve/tar.gz/refs/tags/v1.3.1
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: 'evsieve-1.3.1.tar.gz'

     0K .......... .......... .......... .......... ..........  109K
    50K .......... .......... .......... .......... ..........  369K
   100K .......... .........                                    211K=0.7s

2022-03-10 10:47:18 (174 KB/s) - 'evsieve-1.3.1.tar.gz' saved [122665]

Removing intermediate container 5c58b0b8f5fd
 ---> d3d36e93c465
Step 3/5 : WORKDIR /evsieve-1.3.1
 ---> Running in 4076f26d3c13
Removing intermediate container 4076f26d3c13
 ---> bf369d268cbb
Step 4/5 : ENV RUSTFLAGS='-C target-feature=-crt-static'
 ---> Running in b7312c3f61e3
Removing intermediate container b7312c3f61e3
 ---> 098a85b87d6e
Step 5/5 : RUN rustup target add arm-unknown-linux-musleabihf &&     cargo build -vv --target=arm-unknown-linux-musleabihf --release
 ---> Running in 30f9ec59f82e
info: downloading component 'rust-std' for 'arm-unknown-linux-musleabihf'
info: installing component 'rust-std' for 'arm-unknown-linux-musleabihf'
    Updating crates.io index
 Downloading crates ...
  Downloaded libc v0.2.82
  Downloaded lazy_static v1.4.0
   Compiling libc v0.2.82
   Compiling evsieve v1.3.1 (/evsieve-1.3.1)
   Compiling lazy_static v1.4.0
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' rustc --crate-name build_script_build /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82/build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=a4b63ca1240f5920 -C extra-filename=-a4b63ca1240f5920 --out-dir /evsieve-1.3.1/target/release/build/libc-a4b63ca1240f5920 -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=lazy_static CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0 CARGO_PKG_AUTHORS='Marvin Löbel <loebel.marvin@gmail.com>' CARGO_PKG_DESCRIPTION='A macro for declaring lazily evaluated statics in Rust.' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT/Apache-2.0 CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=lazy_static CARGO_PKG_REPOSITORY='https://github.com/rust-lang-nursery/lazy-static.rs' CARGO_PKG_VERSION=1.4.0 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' rustc --crate-name lazy_static /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto -C metadata=8f6091ab58b85073 -C extra-filename=-8f6091ab58b85073 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn -C target-feature=-crt-static`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off -C metadata=05f53b5e62108660 -C extra-filename=-05f53b5e62108660 --out-dir /evsieve-1.3.1/target/release/build/evsieve-05f53b5e62108660 -L dependency=/evsieve-1.3.1/target/release/deps`
     Running `/evsieve-1.3.1/target/release/build/evsieve-05f53b5e62108660/build-script-build`
[evsieve 1.3.1] cargo:rustc-link-lib=dylib=evdev
     Running `/evsieve-1.3.1/target/release/build/libc-a4b63ca1240f5920/build-script-build`
[libc 0.2.82] cargo:rustc-cfg=freebsd11
[libc 0.2.82] cargo:rustc-cfg=libc_priv_mod_use
[libc 0.2.82] cargo:rustc-cfg=libc_union
[libc 0.2.82] cargo:rustc-cfg=libc_const_size_of
[libc 0.2.82] cargo:rustc-cfg=libc_align
[libc 0.2.82] cargo:rustc-cfg=libc_core_cvoid
[libc 0.2.82] cargo:rustc-cfg=libc_packedN
[libc 0.2.82] cargo:rustc-cfg=libc_cfg_target_vendor
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=libc CARGO_MANIFEST_DIR=/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.82 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=82 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/libc-06ab0236cec04274/out rustc --crate-name libc /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.82/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=f0502fe552095786 -C extra-filename=-f0502fe552095786 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --cap-lints warn -C target-feature=-crt-static --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor`
     Running `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/evsieve-e53f92bfcf2e379e/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=9aa53ca0ad89fcb5 -C extra-filename=-9aa53ca0ad89fcb5 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblazy_static-8f6091ab58b85073.rlib --extern libc=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblibc-f0502fe552095786.rlib -C target-feature=-crt-static -l dylib=evdev`
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-9aa53ca0ad89fcb5.evsieve.02fbeb62-cgu.3.rcgu.o" "-Wl,--as-needed" "-L" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps" "-L" "/evsieve-1.3.1/target/release/deps" "-L" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/arm-unknown-linux-musleabihf/lib" "-levdev" "-Wl,--start-group" "-Wl,--end-group" "-Wl,-Bstatic" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/arm-unknown-linux-musleabihf/lib/libcompiler_builtins-b85afa065dacb413.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib/rustlib/arm-unknown-linux-musleabihf/lib" "-o" "/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-9aa53ca0ad89fcb5" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs"
  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-9aa53ca0ad89fcb5.evsieve.02fbeb62-cgu.3.rcgu.o: relocations in generic ELF (EM: 40)
          /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-9aa53ca0ad89fcb5.evsieve.02fbeb62-cgu.3.rcgu.o: relocations in generic ELF (EM: 40)
 ###### omitted due to large number of similar log ########
          /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/evsieve-9aa53ca0ad89fcb5.evsieve.02fbeb62-cgu.3.rcgu.o: error adding symbols: file in wrong format
          collect2: error: ld returned 1 exit status

error: could not compile `evsieve` due to previous error

Caused by:
  process didn't exit successfully: `CARGO=/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/bin/cargo CARGO_BIN_NAME=evsieve CARGO_CRATE_NAME=evsieve CARGO_MANIFEST_DIR=/evsieve-1.3.1 CARGO_PKG_AUTHORS='Kars Mulder <devmail@karsmulder.nl>' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='GPL-2.0-or-later AND MIT AND GPL-2.0-only WITH Linux-syscall-note' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=evsieve CARGO_PKG_REPOSITORY='' CARGO_PKG_VERSION=1.3.1 CARGO_PKG_VERSION_MAJOR=1 CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION_PATCH=1 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/evsieve-1.3.1/target/release/deps:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib:/usr/local/rustup/toolchains/1.59.0-x86_64-unknown-linux-musl/lib' OUT_DIR=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/build/evsieve-e53f92bfcf2e379e/out rustc --crate-name evsieve --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C metadata=9aa53ca0ad89fcb5 -C extra-filename=-9aa53ca0ad89fcb5 --out-dir /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps --target arm-unknown-linux-musleabihf -L dependency=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps -L dependency=/evsieve-1.3.1/target/release/deps --extern lazy_static=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblazy_static-8f6091ab58b85073.rlib --extern libc=/evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/deps/liblibc-f0502fe552095786.rlib -C target-feature=-crt-static -l dylib=evdev` (exit status: 1)
The command '/bin/sh -c rustup target add arm-unknown-linux-musleabihf &&     cargo build -vv --target=arm-unknown-linux-musleabihf --release' returned a non-zero code: 101

Seems like something is missing yet again =(

KarsMulder commented 2 years ago

I am going to guess that the problem is that the libevdev.so files in your Docker container are compiled for the x86_64 architecture, and the linker needs shared objects that are compiled for the same architecture for which you're trying to compile your binary (i.e. ARM).

From a quick search, it is possible to run ARM Docker containers on a x86_64 host by using Qemu user mode emulation, so I would recommend using an replacing the x86_64 Docker container with an ARM Docker container and following some tutorial on the internet on how to use Qemu to run it on your system.

One issue with that approach is that it looks like there is no Alpine Rust build for ARMv7 (source), though there is an Alpine Rust build for ARMv8 (source); it looks like you're trying to build for ARMv7 according to your build logs, so that may complicate things a bit.

aggo15 commented 2 years ago

@KarsMulder The closest I get is this build where I run the container on an arm device (Raspberry Pi). I did not encounter error from libevdev in this case but it still failed with DSO missing from command line error. Can you have a look on this? Thanks a lot for going through this with me. =)

KarsMulder commented 2 years ago

The error seems to be /usr/local/rustup/toolchains/1.59.0-armv7-unknown-linux-gnueabihf/lib/rustlib/arm-unknown-linux-musleabihf/lib/self-contained/libc.a(__stack_chk_fail.lo): undefined reference to symbol '__stack_chk_guard@@GLIBC_2.4'.

It appears that the file .../arm-unknown-linux-musleabihf/lib/self-contained/libc.a contains a symbol '__stack_chk_guard@@GLIBC_2.4'. This symbol is used for a "stack protection" feature that GCC has, where it inserts some sentinel values at the start and end of the stack to detect when some kind of stack/buffer overflow occurs. As I would guess from the symbol's name, the symbol is available in glibc but not in musl libc. This is odd because one would expect a file called arm-unknown-linux-musleabihf/lib/self-contained/libc.a to take care to explicitly avoid including any glibc-specific symbols.

My best guess would be that by explicitly specifying the environment variable REALGCC=arm-linux-gnueabihf-gcc-8, the compiler that is in charge for generating said libc.a did something different than the Rust developers expected it to; there was never supposed to be a reference to a symbol __stack_chk_guard@@GLIBC_2.4 present in that file (i.e. stack protection was not supposed to be enabled), but by using a non-default compiler it showed up anyway, which caused issues later at the linking stage.

As such, I think that specifying REALGCC=arm-linux-gnueabihf-gcc-8 did not solve the issue of evsieve failing to link against libevdev, it just caused another issue of incorrectly compiling libc, which caused an error to occur in a stage before the linker even tried to link against libevdev.

This is of course outside of my area of expertise.

I've found an issue about similar to the one you're facing now, but no actual solution has been reached there either.

aggo15 commented 2 years ago

@KarsMulder sorry took me a while but I finally got time to come back on this issue. I think I managed to solve the build problem. However, when I attempt to run the evsieve binary on Alpine container, it gave me Error getting 240 bytes thread-local storage: No such file or directory error.

Here are some top level info on what I did.

  1. Looking back at my previous attempts, it's kind of weird I specified arm gnueabihf linker and gcc for an arm musleabihf build. That's probably what caused all those DSO missing and file in wrong format error.
  2. I suspect what I'm missing are musl related binaries and linkers. After some googling I found someone already published similar work on cross compiling tools for musl, on ubuntu image.
  3. What I did was I took out the part where it build the musl tool chain and run it on rust armv7 image.
  4. After that, when I build evsieve again, I encountered yet another error where rust complained it cannot find evdev. On top my head I suspect I needed libevdev.so and libevdev.a file for Alpine to make the build run successfully. So I created another container for Alpine and installed libevdev and libevdev-dev package. Copy out the mentioned files to the build container and instruct rust to refer to those files for the build.
  5. Once the build completed successfully, copy out the binary to Alpine container and execute it, but as I mentioned it failed with Error getting 240 bytes thread-local storage: No such file or directory error.

My Dockerfile become like this. I'm running the build on Raspberry Pi 4. Here is the config.mak that I will use in Dockerfile below.

### This is the builder for evsieve
FROM rust:1.59.0-slim-buster AS builder

# Install necessary dependencies, libc6-dev-armhf-cross libc6-armhf-cross I think are not necessary at this point, 
# so you can remove it if you want
RUN apt-get update && apt-get install -y --no-install-recommends \
      build-essential \
      libc6-dev-armhf-cross \
      libc6-armhf-cross \
      musl-tools \
      libevdev2 \
      libevdev-dev \
      unzip \
      curl \
      wget && \
    rustup target add arm-unknown-linux-musleabihf && \
    wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz && \
    tar -xzf evsieve-1.3.1.tar.gz && rm -rf /evsieve-1.3.1.tar.gz

# Build tool configuration file from richfelker (Refer to link above)
COPY ./config.mak /musl-cross-make-0.9.9/config.mak

# Copy out the build tool and install in container. This will take a while to complete depends on your machine.
# PS: Thanks richfelker, you really save my day.
RUN wget https://github.com/richfelker/musl-cross-make/archive/v0.9.9.zip && \
    unzip -q v0.9.9.zip && \
    rm -rf v0.9.9.zip && \
    cd /musl-cross-make-0.9.9 && \
    export TARGET=arm-linux-musleabihf && \
    make install

### This is another builder stage just to copy out the necessary libevdev.a and libevdev.so.2.2.0 file for the build
FROM arm32v6/alpine:3.10 AS alpine-libevdev

RUN apk add libevdev libevdev-dev

### Coming back to the builder stage, 
FROM builder AS builder-evsieve

# Copy the necessary files from alpine-libevdev builder stage into this container
COPY --from=alpine-libevdev /usr/lib/libevdev.a /usr/lib/arm-linux-musleabihf/libevdev.a
COPY --from=alpine-libevdev /usr/lib/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0

WORKDIR /evsieve-1.3.1

# I run this update first for docker to cache this layer as it is annoying to perform update everytime I run the build.
RUN cargo update

# Create the similar soft link following the builder stage alpine-libevdev
# Specifying the musl linker, binary and libevdev directory through rust environment variables
# Start the build
RUN ln -s /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so && \
    ln -s /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so.2 && \
    CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=/usr/local/musl/bin/arm-linux-musleabihf-ld \
    REALGCC=/usr/local/musl/bin/arm-linux-musleabihf-gcc-9.2.0 \
    TARGET_CC=/usr/bin/musl-gcc \
    RUSTFLAGS='-L /usr/lib/arm-linux-musleabihf' \
    cargo build -vv --target=arm-unknown-linux-musleabihf --release

# The target container to run evsieve
FROM arm32v6/alpine:3.10

COPY --from=builder-evsieve /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/evsieve /bin/evsieve

RUN apk add --no-cache libevdev && ln -s /lib/ld-musl-armhf.so.1 /usr/lib/ld.so.1

The above build completed successfully.

Here is the command I use to test run the container.

pi@raspberry:~ $ sudo docker run -it --rm --entrypoint evsieve evsieve-test:1.0 --help
evsieve: Error getting 240 bytes thread-local storage: No such file or directory

Do you know what might be the problem that cause this error?

aggo15 commented 2 years ago

Ok I finally managed to build a working binary for Alpine armv7 only. On armv6, I'm not sure why but I'm getting a segmentation fault error from the container. Well, I'm going to call it a day and investigate next time.

Here is the working Dockerfile running on Raspberry Pi 4, I just want to document the changes I made here for future reference.

### This build stage use to copy out the necessary libevdev.a and libevdev.so.2.2.0 file for the build
FROM arm32v6/alpine:3.10 AS alpine-libevdev

RUN apk add libevdev libevdev-dev

### This is the builder for evsieve
FROM rust:1.59.0-slim-buster AS builder

COPY --from=alpine-libevdev /usr/lib/libevdev.a /usr/lib/arm-linux-musleabihf/libevdev.a
COPY --from=alpine-libevdev /usr/lib/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0

RUN apt-get update && apt-get install -y --no-install-recommends \
      build-essential \
      musl-tools \
      libevdev2 \
      libevdev-dev \
      unzip \
      curl \
      wget && \
    rustup target add arm-unknown-linux-musleabihf && \
    wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz && \
    tar -xzf evsieve-1.3.1.tar.gz && rm -rf /evsieve-1.3.1.tar.gz

WORKDIR /evsieve-1.3.1

RUN cargo update

RUN ln -s /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so && \
    ln -s /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so.2 && \
    RUSTFLAGS="-L/usr/lib/arm-linux-musleabihf -Clinker=musl-gcc -Ctarget-feature=-crt-static" cargo build -vv --target=arm-unknown-linux-musleabihf --release

# The target container to run evsieve
FROM arm32v6/alpine:3.10

COPY --from=builder /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/evsieve /bin/evsieve

RUN apk add --no-cache libevdev libc6-compat libgcc && \
    ln -s /lib/ld-musl-armhf.so.1 /usr/lib/ld.so.1

On other note, turns out I don't have to download and build entire musl binaries which save a lot of time on build process.

aggo15 commented 2 years ago

I found out the root cause why the binary built on previous post didn't work in Pi Zero. I found out the musl-gcc on the build container is not running with the architecture required for Pi Zero. Here is what the query on musl-gcc looked like.

# this is within builder container
root@511f6e0d92ec:/evsieve-1.3.1# /usr/bin/musl-gcc -Q --help=target
The following options are target specific:
  -mabi=                                aapcs-linux
  -mabort-on-noreturn                   [disabled]
  -mandroid                             [disabled]
  -mapcs                                [disabled]
  -mapcs-frame                          [disabled]
  -mapcs-reentrant                      [disabled]
  -mapcs-stack-check                    [disabled]
  -march=                               armv7-a+fp
  -marm                                 [disabled]
  -masm-syntax-unified                  [enabled]
  -mbe32                                [enabled]
  -mbe8                                 [disabled]
  -mbig-endian                          [disabled]
  -mbionic                              [disabled]
  -mbranch-cost=                        -1
  -mcallee-super-interworking           [disabled]
  -mcaller-super-interworking           [disabled]
  -mcmse                                [disabled]
  -mcpu=
  -mfix-cortex-m3-ldrd                  [disabled]
  -mflip-thumb                          [disabled]
  -mfloat-abi=                          hard
  -mfp16-format=                        none
  -mfpu=                                vfpv3-d16
  -mglibc                               [enabled]
  -mhard-float
  -mlittle-endian                       [enabled]
  -mlong-calls                          [disabled]
  -mmusl                                [disabled]
  -mneon-for-64bits                     [disabled]
  -mpic-data-is-text-relative           [enabled]
  -mpic-register=
  -mpoke-function-name                  [disabled]
  -mprint-tune-info                     [disabled]
  -mpure-code                           [disabled]
  -mrestrict-it                         [disabled]
  -msched-prolog                        [enabled]
  -msingle-pic-base                     [disabled]
  -mslow-flash-data                     [disabled]
  -msoft-float
  -mstructure-size-boundary=            8
  -mthumb                               [enabled]
  -mthumb-interwork                     [disabled]
  -mtls-dialect=                        gnu
  -mtp=                                 cp15
  -mtpcs-frame                          [disabled]
  -mtpcs-leaf-frame                     [disabled]
  -mtune=
  -muclibc                              [disabled]
  -munaligned-access                    [enabled]
  -mvectorize-with-neon-double          [disabled]
  -mvectorize-with-neon-quad            [enabled]
  -mword-relocations                    [disabled]

...

Noticed the part -march=armv7-a+fp, -marm=[disabled] and -mfpu=vfpv3-d16. I suspect this is the culprit.

Fortunately I've got another musl gcc binary that I built previously in this post. Manually checked the musl gcc and confirm the gcc is with the correct architecture -march=armv5te+fp.

root@c35fc4772115:/usr/local/musl/bin# ./arm-linux-musleabihf-gcc-9.2.0 -Q --help=target
The following options are target specific:
  -mabi=                                aapcs-linux
  -mabort-on-noreturn                   [disabled]
  -mandroid                             [disabled]
  -mapcs                                [disabled]
  -mapcs-frame                          [disabled]
  -mapcs-reentrant                      [disabled]
  -mapcs-stack-check                    [disabled]
  -march=                               armv5te+fp
  -marm                                 [enabled]
  -masm-syntax-unified                  [disabled]
  -mbe32                                [enabled]
  -mbe8                                 [disabled]
  -mbig-endian                          [disabled]
  -mbionic                              [disabled]
  -mbranch-cost=                        -1
  -mcallee-super-interworking           [disabled]
  -mcaller-super-interworking           [disabled]
  -mcmse                                [disabled]
  -mcpu=                                arm10e
  -mfix-cortex-m3-ldrd                  [disabled]
  -mflip-thumb                          [disabled]
  -mfloat-abi=                          hard
  -mfp16-format=                        none
  -mfpu=                                auto
  -mgeneral-regs-only                   [disabled]
  -mglibc                               [disabled]
  -mhard-float
  -mlittle-endian                       [enabled]
  -mlong-calls                          [disabled]
  -mmusl                                [enabled]
  -mneon-for-64bits                     [disabled]
  -mpic-data-is-text-relative           [enabled]
  -mpic-register=
  -mpoke-function-name                  [disabled]
  -mprint-tune-info                     [disabled]
  -mpure-code                           [disabled]
  -mrestrict-it                         [disabled]
  -msched-prolog                        [enabled]
  -msingle-pic-base                     [disabled]
  -mslow-flash-data                     [disabled]
  -msoft-float
  -mstructure-size-boundary=            8
  -mthumb                               [disabled]
  -mthumb-interwork                     [disabled]
  -mtls-dialect=                        gnu
  -mtp=                                 soft
  -mtpcs-frame                          [disabled]
  -mtpcs-leaf-frame                     [disabled]
  -mtune=
  -muclibc                              [disabled]
  -munaligned-access                    [disabled]
  -mvectorize-with-neon-double          [disabled]
  -mvectorize-with-neon-quad            [enabled]
  -mword-relocations                    [enabled]

...

So in the Dockerfile I shared in this post. I just need to change the build command from this:

RUSTFLAGS="-L/usr/lib/arm-linux-musleabihf -Clinker=musl-gcc -Ctarget-feature=-crt-static" cargo build -vv --target=arm-unknown-linux-musleabihf --release

to this:

RUSTFLAGS="-L/usr/lib/arm-linux-musleabihf -Clinker=/usr/local/musl/bin/arm-linux-musleabihf-gcc-9.2.0 -Ctarget-feature=-crt-static" \
cargo build -vv --target=arm-unknown-linux-musleabihf --release

After that I rebuilt the binary and test run it in Pi zero. Seems like everything is working fine.

pi@raspberry:~ $ uname -a
Linux monitor1 5.10.63+ #1459 Wed Oct 6 16:40:27 BST 2021 armv6l GNU/Linux
pi@raspberry:~ $ sudo docker run -it --rm --entrypoint sh --privileged evsieve-test:1.0
/ # evsieve
Usage: evsieve [--input PATH... [domain=DOMAIN] [grab[=auto|force]] [persist=reopen|none]]...
               [--map SOURCE [DEST...] [yield]]...
               [--copy SOURCE [DEST...] [yield]]...
               [--block [SOURCE...]]...
               [--toggle SOURCE DEST... [id=ID] [mode=consistent|passive]]...
               [--hook KEY... [exec-shell=COMMAND]... [toggle[=[ID][:INDEX]]]...]...
               [--merge [EVENTS...]]...
               [--print [EVENTS...] [format=default|direct]]...
               [--output [EVENTS...] [create-link=PATH] [name=NAME] [repeat[=MODE]]]...
/ # evsieve --input /dev/input/event0 --print
Event:  type:code = msc:scan       value = 458782      domain = /dev/input/event0
Event:  type:code = key:1          value = 1 (down)    domain = /dev/input/event0
Event:  type:code = msc:scan       value = 458782      domain = /dev/input/event0
Event:  type:code = key:1          value = 0 (up)      domain = /dev/input/event0
Event:  type:code = msc:scan       value = 458783      domain = /dev/input/event0
Event:  type:code = key:2          value = 1 (down)    domain = /dev/input/event0

Hopefully this will help someone in the future if they want to cross build evsieve to Pi Zero or similar architecture.

aggo15 commented 2 years ago

I'm closing this issue by sharing the Dockerfile I used for cross building evsieve binary for Alpine armv6 on a armv7 machine (Raspberry Pi 4). I embedded the config.mak content in Dockerfile so we don't have to create another config.mak file while building using docker. Hopefully this will help someone else with similar requirement in future.

### This build stage is use for copy out the necessary libevdev.a and libevdev.so.2.2.0 file for the build
FROM arm32v6/alpine:3.10 AS alpine-libevdev

RUN apk add libevdev libevdev-dev

### This is the cross builder for evsieve (armv7 to armv6)
FROM rust:1.59.0-slim-buster AS builder

COPY --from=alpine-libevdev /usr/lib/libevdev.a /usr/lib/arm-linux-musleabihf/libevdev.a
COPY --from=alpine-libevdev /usr/lib/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0

RUN apt-get update && apt-get install -y --no-install-recommends \
      build-essential \
      libevdev2 \
      libevdev-dev \
      unzip \
      wget && \
    rustup target add arm-unknown-linux-musleabihf && \
    wget https://github.com/KarsMulder/evsieve/archive/v1.3.1.tar.gz -O evsieve-1.3.1.tar.gz && \
    tar -xzf evsieve-1.3.1.tar.gz && rm -rf /evsieve-1.3.1.tar.gz && \
    wget https://github.com/richfelker/musl-cross-make/archive/v0.9.9.zip && \
    unzip -q v0.9.9.zip && \
    rm -rf v0.9.9.zip && \
    echo 'OUTPUT = /usr/local/musl' > /musl-cross-make-0.9.9/config.mak && \
    echo 'MUSL_VER = 1.1.22' >> /musl-cross-make-0.9.9/config.mak && \
    echo 'COMMON_CONFIG += --disable-nls' >> /musl-cross-make-0.9.9/config.mak && \
    echo 'GCC_CONFIG += --enable-languages=c,c++' >> /musl-cross-make-0.9.9/config.mak && \
    echo 'GCC_CONFIG += --disable-libquadmath --disable-decimal-float' >> /musl-cross-make-0.9.9/config.mak && \
    echo 'GCC_CONFIG += --disable-multilib' >> /musl-cross-make-0.9.9/config.mak && \
    echo 'COMMON_CONFIG += --with-debug-prefix-map=$(CURDIR)=' >> /musl-cross-make-0.9.9/config.mak && \
    cd /musl-cross-make-0.9.9 && \
    export TARGET=arm-linux-musleabihf && \
    make install

WORKDIR /evsieve-1.3.1

RUN cargo update

RUN ln -s /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so && \
    ln -s /usr/lib/arm-linux-musleabihf/libevdev.so.2.2.0 /usr/lib/arm-linux-musleabihf/libevdev.so.2 && \
    RUSTFLAGS="-L/usr/lib/arm-linux-musleabihf -Clinker=/usr/local/musl/bin/arm-linux-musleabihf-gcc-9.2.0 -Ctarget-feature=-crt-static" \
    cargo build -vv --target=arm-unknown-linux-musleabihf --release

### The target container to run evsieve
FROM arm32v6/alpine:3.10

COPY --from=builder /evsieve-1.3.1/target/arm-unknown-linux-musleabihf/release/evsieve /bin/evsieve

RUN apk add --no-cache libevdev libc6-compat libgcc && \
    ln -s /lib/ld-musl-armhf.so.1 /usr/lib/ld.so.1

You can build the image using command below using docker. This will take a while as it require to build the arm musleabihf gcc binary to use in cargo.

pi@raspberry:~ $ sudo docker build . -t evsieve-test:1.0

After build complete. You can run the docker container interactively using command below and test out evsieve command.

pi@raspberry:~ $ sudo docker run -it --rm --entrypoint sh --privileged evsieve-test:1.0
/ # evsieve
Usage: evsieve [--input PATH... [domain=DOMAIN] [grab[=auto|force]] [persist=reopen|none]]...
               [--map SOURCE [DEST...] [yield]]...
               [--copy SOURCE [DEST...] [yield]]...
               [--block [SOURCE...]]...
               [--toggle SOURCE DEST... [id=ID] [mode=consistent|passive]]...
               [--hook KEY... [exec-shell=COMMAND]... [toggle[=[ID][:INDEX]]]...]...
               [--merge [EVENTS...]]...
               [--print [EVENTS...] [format=default|direct]]...
               [--output [EVENTS...] [create-link=PATH] [name=NAME] [repeat[=MODE]]]...
/ # evsieve --input /dev/input/event0 --print
Event:  type:code = msc:scan       value = 458782      domain = /dev/input/event0
Event:  type:code = key:1          value = 1 (down)    domain = /dev/input/event0
Event:  type:code = msc:scan       value = 458782      domain = /dev/input/event0
Event:  type:code = key:1          value = 0 (up)      domain = /dev/input/event0
Event:  type:code = msc:scan       value = 458783      domain = /dev/input/event0
Event:  type:code = key:2          value = 1 (down)    domain = /dev/input/event0

Thank you.

ryukinix commented 1 year ago

Very nice solution with dockerfile. I think this issue could be linked in the README.md, @aggo15.