Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with --enable-shared=no #8143

Open
DieracDelta opened this issue Apr 1, 2023 · 0 comments
Open

Building with --enable-shared=no #8143

DieracDelta opened this issue Apr 1, 2023 · 0 comments
Labels
build-problem Nix fails to compile or test; also improvements to build process

Comments

@DieracDelta
Copy link
Member

Describe the bug

I'd like to build nix with --enable-shared=no on my aarch64-darwin so I can link against the static libs it generates. So I override the configure flags of the nix derivation.

                nix = inputs.nix.packages.aarch64-darwin.nix
                  .overrideAttrs (oldAttrs: {
                    LIBARCHIVE_LIBS = "${pkgs.libiconv.override {enableStatic = true; enableShared = false;}}/lib/libiconv.a";
                    configureFlags = oldAttrs.configureFlags ++ [ "--enable-shared=no" ];
                    buildInputs = oldAttrs.buildInputs ++ [
                      prev.darwin.apple_sdk.frameworks.Security
                      prev.darwin.apple_sdk.frameworks.SystemConfiguration
                      prev.gtest
                      prev.curl
                      prev.bzip2 prev.xz prev.brotli prev.editline
                      prev.openssl prev.sqlite
                      # prev.libarchive
                      prev.boost
                    ];

                    nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [
                      prev.darwin.apple_sdk.frameworks.Security
                      prev.darwin.apple_sdk.frameworks.SystemConfiguration
                    ];

                    propagatedBuildInputs = oldAttrs.propagatedBuildInputs ++ [
                      prev.darwin.apple_sdk.frameworks.Security
                      prev.darwin.apple_sdk.frameworks.SystemConfiguration
                    ];
                    postInstall = ''
                        cp src/libcmd/libnixcmd.a $out/lib/
                        cp src/libexpr/libnixexpr.a $out/lib/
                        cp src/libfetchers/libnixfetchers.a $out/lib/
                        cp src/libmain/libnixmain.a $out/lib/
                        cp src/libstore/libnixstore.a $out/lib/
                        cp src/libutil/libnixutil.a $out/lib/
                    '';
                  });
              }

Expected behavior

The overrides to successfully build the library. When I build the library in the same fashion outside nix (that is, with ./configure --enable-shared=no && make install from with nix develop .#native-clang11StdenvPackages), the build successfully finishes and I'm able to inspect the output binaries.

However, with these overrides from within the derivation, I get a lot of libarchive missing symbols. Errors like:

error: builder for '/nix/store/fj68rc8xjn7f0p2kyf4fa5rmxd2kqcm3-nix-2.15.0pre20230318_220aa8e.drv' failed with exit code 2;
       last 10 log lines:
       >       nix::ArchiveCompressionSink::ArchiveCompressionSink(nix::Sink&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, int) in libnixutil.a(libnixutil.o)
       >   "_archive_write_set_bytes_per_block", referenced from:
       >       nix::ArchiveCompressionSink::ArchiveCompressionSink(nix::Sink&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, int) in libnixutil.a(libnixutil.o)
       >   "_archive_write_set_filter_option", referenced from:
       >       nix::ArchiveCompressionSink::ArchiveCompressionSink(nix::Sink&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, int) in libnixutil.a(libnixutil.o)
       >   "_archive_write_set_format_raw", referenced from:
       >       nix::ArchiveCompressionSink::ArchiveCompressionSink(nix::Sink&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, int) in libnixutil.a(libnixutil.o)
       > ld: symbol(s) not found for architecture arm64

I believe this is because libarchive is a shared lib not a static lib. Any advice on (1) how to build libarchive as a static lib and (2) why this builds successfully in the nix shell but not a pure nix context would be appreciated!

nix-env --version output

nix-env --version output
nix-env (Nix) 2.13.3

Additional context

Priorities

@DieracDelta DieracDelta added the bug label Apr 1, 2023
@roberth roberth added build-problem Nix fails to compile or test; also improvements to build process and removed bug labels Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-problem Nix fails to compile or test; also improvements to build process
Projects
None yet
Development

No branches or pull requests

2 participants