archlinux / alpm.rs

Rust bindings for libalpm
GNU General Public License v3.0
112 stars 21 forks source link

Static feature flag doesn't actually work #38

Open VorpalBlade opened 6 months ago

VorpalBlade commented 6 months ago

I built with alpm/static but it doesn't seem to actually do anything:

$ ldd target/release/unnamed_project
        linux-vdso.so.1 (0x00007ffe29feb000)
        libalpm.so.13 => /usr/lib/libalpm.so.13 (0x00007dc3617c3000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007dc36179e000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007dc3615bc000)
        libcrypto.so.3 => /usr/lib/libcrypto.so.3 (0x00007dc361000000)
        libarchive.so.13 => /usr/lib/libarchive.so.13 (0x00007dc360f36000)
        libcurl.so.4 => /usr/lib/libcurl.so.4 (0x00007dc360e72000)
        libgpgme.so.11 => /usr/lib/libgpgme.so.11 (0x00007dc361566000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007dc361a76000)
        libacl.so.1 => /usr/lib/libacl.so.1 (0x00007dc361a23000)
        libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007dc36153b000)
        liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007dc360e3f000)
        libzstd.so.1 => /usr/lib/libzstd.so.1 (0x00007dc360d6c000)
        liblz4.so.1 => /usr/lib/liblz4.so.1 (0x00007dc360d47000)
        libbz2.so.1.0 => /usr/lib/libbz2.so.1.0 (0x00007dc361a0e000)
        libz.so.1 => /usr/lib/libz.so.1 (0x00007dc360d2d000)
        libnghttp3.so.9 => /usr/lib/libnghttp3.so.9 (0x00007dc360d09000)
        libnghttp2.so.14 => /usr/lib/libnghttp2.so.14 (0x00007dc360cde000)
        libidn2.so.0 => /usr/lib/libidn2.so.0 (0x00007dc360cbc000)
        libssh2.so.1 => /usr/lib/libssh2.so.1 (0x00007dc360c73000)
        libpsl.so.5 => /usr/lib/libpsl.so.5 (0x00007dc360c5f000)
        libssl.so.3 => /usr/lib/libssl.so.3 (0x00007dc360b7f000)
        libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x00007dc360b2b000)
        libbrotlidec.so.1 => /usr/lib/libbrotlidec.so.1 (0x00007dc360b1c000)
        libassuan.so.0 => /usr/lib/libassuan.so.0 (0x00007dc360b07000)
        libgpg-error.so.0 => /usr/lib/libgpg-error.so.0 (0x00007dc360ae1000)
        libunistring.so.5 => /usr/lib/libunistring.so.5 (0x00007dc360927000)
        libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x00007dc36084f000)
        libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x00007dc360821000)
        libcom_err.so.2 => /usr/lib/libcom_err.so.2 (0x00007dc361535000)
        libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0x00007dc360813000)
        libkeyutils.so.1 => /usr/lib/libkeyutils.so.1 (0x00007dc36080c000)
        libresolv.so.2 => /usr/lib/libresolv.so.2 (0x00007dc3607fb000)
        libbrotlicommon.so.1 => /usr/lib/libbrotlicommon.so.1 (0x00007dc3607d8000)

If I build with my Arch Linux backend disabled I get:

        linux-vdso.so.1 (0x00007ffeccfe0000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x000074a149e8a000)
        libc.so.6 => /usr/lib/libc.so.6 (0x000074a149ca8000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x000074a14a0b0000)

This is unfortunate as my plans involve making a cross platform binary that you can run on any (supported) distro and will set up your preferred packages and configs (I'm tired of having to remember what I need to install on new systems)

Morganamilo commented 6 months ago

You need to actually have a static lib to link against. Ideally it would fail if not found, not sure if I can make cargo do that though.

VorpalBlade commented 6 months ago

Ah, doesn't Arch Linux provide a static one by default? Perhaps just documenting this somewhere might be good enough? (I sure hope this hasn't already been done and I just missed it)

Morganamilo commented 6 months ago

Yeah if that's not mentioned it should be. pacman-static from the aur has one and alpm.rs will know to look for it if installed.

VorpalBlade commented 6 months ago

I gave it a try today with pacman-static from AUR, but I ran into two different errors. First when using mold as a linker

[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-C", "link-arg=--ld-path=/usr/bin/mold"]

Then I got this error

error: linking with `/usr/bin/clang` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/arvid/.pyenv/shims:/home/arvid/bin:/home/arvid/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/arvid/.cache/zsh4humans/v5/fzf/bin" VSLANG="1033" "/usr/bin/clang" "-m64" "/tmp/rustcVcJZct/symbols.o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d.build_script_build.b34e9b745356e6a8-cgu.0.rcgu.o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d.build_script_build.b34e9b745356e6a8-cgu.1.rcgu.o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d.vibwxncysng7mjj.rcgu.o" "-Wl,--as-needed" "-L" "/home/arvid/src/project_config/paketkoll/target/release/deps" "-L" "/usr/lib/pacman/lib" "-L" "/usr/lib/pacman/lib" "-L" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/arvid/src/project_config/paketkoll/target/release/deps/libalpm_sys-3473383a3492e82b.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-66d8041607d2929b.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-a57e2388c0aea9b1.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-dcd9be90ae2cb505.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-516789932d161b4e.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-1ff34b0cf871cb60.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-0c110dd0650d6cb7.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-a6e97aae2681ad8f.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-b93dac2525ec4d1e.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-ce1d65fb391ae98b.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-8933a2fb54d88492.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-306712ebb1ee1a3f.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-349c574f342b0d30.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-65c422a3ad95273d.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-7e6330a6c0cb9441.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-39c59240bfdfab27.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-e9d126c51bb8b2bb.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-5af394d9b1f07bdc.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-693a8f23970c5917.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-13fc9d1ed9c7a2bc.rlib" "-Wl,-Bdynamic" "-lalpm" "-larchive" "-llzma" "-lbz2" "-lcurl" "-lcares" "-lnghttp2" "-lssl" "-lzstd" "-lz" "-lgpgme" "-lcrypto" "-ldl" "-lassuan" "-lgpg-error" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "--ld-path=/usr/bin/mold"
  = note: mold: fatal: src_common_ini.c.o: don't know how to handle this LTO object file because no -plugin option was given. Please make sure you added -flto not only for creating object files but also for creating the final executable.
          clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

When I commented out that config I got:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/arvid/.pyenv/shims:/home/arvid/bin:/home/arvid/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/arvid/.cache/zsh4humans/v5/fzf/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustc3Kad4H/symbols.o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d.build_script_build.b34e9b745356e6a8-cgu.0.rcgu.o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d.build_script_build.b34e9b745356e6a8-cgu.1.rcgu.o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d.vibwxncysng7mjj.rcgu.o" "-Wl,--as-needed" "-L" "/home/arvid/src/project_config/paketkoll/target/release/deps" "-L" "/usr/lib/pacman/lib" "-L" "/usr/lib/pacman/lib" "-L" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/arvid/src/project_config/paketkoll/target/release/deps/libalpm_sys-3473383a3492e82b.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-66d8041607d2929b.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-a57e2388c0aea9b1.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-dcd9be90ae2cb505.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-516789932d161b4e.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-1ff34b0cf871cb60.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-0c110dd0650d6cb7.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-a6e97aae2681ad8f.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-b93dac2525ec4d1e.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-ce1d65fb391ae98b.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-8933a2fb54d88492.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-306712ebb1ee1a3f.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-349c574f342b0d30.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-65c422a3ad95273d.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-7e6330a6c0cb9441.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-39c59240bfdfab27.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-e9d126c51bb8b2bb.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-5af394d9b1f07bdc.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-693a8f23970c5917.rlib" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-13fc9d1ed9c7a2bc.rlib" "-Wl,-Bdynamic" "-lalpm" "-larchive" "-llzma" "-lbz2" "-lcurl" "-lcares" "-lnghttp2" "-lssl" "-lzstd" "-lz" "-lgpgme" "-lcrypto" "-ldl" "-lassuan" "-lgpg-error" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/arvid/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/arvid/src/project_config/paketkoll/target/release/build/alpm-9cbc9ee39e92908d/build_script_build-9cbc9ee39e92908d.build_script_build.b34e9b745356e6a8-cgu.1.rcgu.o: in function `build_script_build::main':
          build_script_build.b34e9b745356e6a8-cgu.1:(.text._ZN18build_script_build4main17hb1f27a95d6a78e9eE+0x9): undefined reference to `alpm_version'
          collect2: error: ld returned 1 exit status

  = note: 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)

I'm building with --release. I tried turning of the normal lto = "fat" that I use for release builds in my workspace to no avail.

This can also be reproduced with a simple:

cargo new reproducer
cd reproducer
cargo add alpm --features=static
cargo build
cargo build

So maybe this needs musl (since pacman-static is linked with musl), but I don't seem to have a sysroot for that:

❯ cargo build --target x86_64-unknown-linux-musl                           
   Compiling pkg-config v0.3.30
   Compiling bitflags v1.3.2
   Compiling alpm-sys v2.1.3
error: failed to run custom build command for `alpm-sys v2.1.3`

Caused by:
  process didn't exit successfully: `/home/arvid/src/reproducer/target/debug/build/alpm-sys-561eb9a709c484ac/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=/usr/lib/pacman/lib/pkgconfig
  cargo:rerun-if-env-changed=ALPM_LIB_DIR
  cargo:rerun-if-env-changed=LIBALPM_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at /home/arvid/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alpm-sys-2.1.3/build.rs:26:10:
  called `Result::unwrap()` on an `Err` value: pkg-config has not been configured to support cross-compilation.

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

I normally cross compile using cross-rs but that uses Debian based docker containers, not Arch. So that won't work here.

I do believe that the docs need to be improved on how to actually use the static flag. It probably needs a dedicated section in the README.