Skip to content

feat: make build script more generalΒ #7

@josibake

Description

@josibake

Currently, the build script sets stdc++ as the C++ standard library if using gcc as a compiler, and libc++ if using clang. This is based on the assumption that a user is building the crate on linux if using a gnu style compiler and building on macos if using clang.

However, if using clang on linux, the build will fail due since stdc++ is used but the build script assumes libc++.

steps to reproduce

# use clang on linux
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

cargo test

Result:

error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustc6De2yx/symbols.o" "<6 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib64/rustlib/x86_64-unknown-linux-gnu/lib/{libtest-*,libgetopts-*,libunicode_width-*,librustc_std_workspace_std-*}.rlib" "/root/rust-bitcoinkernel/target/debug/deps/{liblibbitcoinkernel_sys-fa55f36743b3a8c6.rlib}.rlib" "<sysroot>/lib64/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lc++" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/root/rust-bitcoinkernel/target/debug/build/secp256k1-sys-fe87fd57724954db/out" "-L" "/root/rust-bitcoinkernel/target/debug/build/libbitcoinkernel-sys-f9af07807abfaa57/out/install/lib" "-L" "<sysroot>/lib64/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/root/rust-bitcoinkernel/target/debug/deps/bitcoinkernel-dda3e1a9baf10ae0" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /usr/bin/ld: cannot find -lc++: No such file or directory
          collect2: error: ld returned 1 exit status


error: could not compile `bitcoinkernel` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

Ideas going forward

#6 improves on this by only using libc++ if we using clang on macos. This works for now, but I wanted to open this issue to track alternatives and iterate on the idea a bit more. One idea to explore further is leveraging the cc crate more to infer the tool chain on the system "automagically." Another idea would be explicitly setting sane defaults for the platforms we expect, while allow the user to override these if they are in a non-typical set up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions