Open VorpalBlade opened 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.
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)
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.
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.
I built with alpm/static but it doesn't seem to actually do anything:
If I build with my Arch Linux backend disabled I get:
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)