-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
[wip] Statically built Nix #56281
[wip] Statically built Nix #56281
Changes from all commits
b5c6080
9b92e6e
a44937b
d932883
3cb7e9f
634b049
f1a5fb8
350f3d0
78bd45b
f2290fb
dccd9e3
3afa626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,17 @@ stdenv.mkDerivation rec { | |
export NIX_CFLAGS_COMPILE+=" -D_GNU_SOURCE -DUSE_MMAP -DHAVE_DL_ITERATE_PHDR" | ||
''; | ||
|
||
patches = | ||
patches = [ (fetchpatch { | ||
name = "boehm-gc-7.6.0-sys_select.patch"; | ||
url = "https://gitweb.gentoo.org/proj/musl.git/plain/dev-libs/boehm-gc/files/boehm-gc-7.6.0-sys_select.patch?id=85b6a600996bdd71162b357e9ba93d8559342432"; | ||
sha256 = "1gydwlklvci30f5dpp5ccw2p2qpph5y41r55wx9idamjlq66fbb3"; | ||
}) ] ++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still needed? It was explicitly removed in a recent-ish PR with the idea that this didn't hurt but didn't help, IIRC. Might be good to check. |
||
# https://github.com/ivmai/bdwgc/pull/208 | ||
lib.optional stdenv.hostPlatform.isRiscV ./riscv.patch; | ||
|
||
configureFlags = | ||
[ "--enable-cplusplus" ] | ||
++ lib.optional enableLargeConfig "--enable-large-config" | ||
++ lib.optional (stdenv.hostPlatform.libc == "musl") "--disable-static" | ||
# Configure script can't detect whether C11 atomic intrinsics are available | ||
# when cross-compiling, so it links to libatomic_ops, which has to be | ||
# propagated to all dependencies. To avoid this, assume that the intrinsics | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ rec { | |
then throw "Cannot build fully static binaries on Darwin/macOS" | ||
else stdenv'.mkDerivation (args // { | ||
NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -static"; | ||
separateDebugInfo = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem right, why must this be disabled for static adapter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah maybe not... I was getting an issue that I thought was due to this but it might have been unrelated. |
||
configureFlags = (args.configureFlags or []) ++ [ | ||
"--disable-shared" # brrr... | ||
]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
diff --git a/Makefile.config.in b/Makefile.config.in | ||
index b01a4afb..59730b64 100644 | ||
--- a/Makefile.config.in | ||
+++ b/Makefile.config.in | ||
@@ -1,4 +1,6 @@ | ||
+AR = @AR@ | ||
BDW_GC_LIBS = @BDW_GC_LIBS@ | ||
+BUILD_SHARED_LIBS = @BUILD_SHARED_LIBS@ | ||
CC = @CC@ | ||
CFLAGS = @CFLAGS@ | ||
CXX = @CXX@ | ||
diff --git a/configure.ac b/configure.ac | ||
index 5a252667..410b2097 100644 | ||
--- a/configure.ac | ||
+++ b/configure.ac | ||
@@ -64,6 +64,7 @@ AC_PROG_CXX | ||
AC_PROG_CPP | ||
AX_CXX_COMPILE_STDCXX_14 | ||
|
||
+AC_CHECK_TOOL([AR], [ar]) | ||
|
||
# Use 64-bit file system calls so that we can support files > 2 GiB. | ||
AC_SYS_LARGEFILE | ||
@@ -267,6 +268,15 @@ AC_ARG_WITH(sandbox-shell, AC_HELP_STRING([--with-sandbox-shell=PATH], | ||
sandbox_shell=$withval) | ||
AC_SUBST(sandbox_shell) | ||
|
||
+AC_ARG_ENABLE(shared, AC_HELP_STRING([--enable-shared], | ||
+ [Build shared libraries for Nix [default=yes]]), | ||
+ shared=$enableval, shared=yes) | ||
+if test "$shared" = yes; then | ||
+ AC_SUBST(BUILD_SHARED_LIBS, 1, [Whether to build shared libraries.]) | ||
+else | ||
+ AC_SUBST(BUILD_SHARED_LIBS, 0, [Whether to build shared libraries.]) | ||
+fi | ||
+ | ||
|
||
# Expand all variables in config.status. | ||
test "$prefix" = NONE && prefix=$ac_default_prefix | ||
diff --git a/mk/libraries.mk b/mk/libraries.mk | ||
index 14c95fa9..28173629 100644 | ||
--- a/mk/libraries.mk | ||
+++ b/mk/libraries.mk | ||
@@ -125,9 +125,9 @@ define build-library | ||
$(1)_PATH := $$(_d)/$$($(1)_NAME).a | ||
|
||
$$($(1)_PATH): $$($(1)_OBJS) | $$(_d)/ | ||
- $(trace-ar) ar crs $$@ $$? | ||
+ $(trace-ar) $(AR) crs $$@ $$? | ||
|
||
- $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) | ||
+ $(1)_LDFLAGS_USE += -Wl,--whole-archive $$($(1)_PATH) -Wl,--no-whole-archive $$($(1)_LDFLAGS) | ||
|
||
$(1)_INSTALL_PATH := $$(libdir)/$$($(1)_NAME).a | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,10 @@ in { | |
boost = super.boost.override { | ||
enableStatic = true; | ||
enableShared = false; | ||
|
||
# Don’t use new stdenv for boost because it doesn’t like the | ||
# --disable-shared flag | ||
stdenv = super.stdenv; | ||
}; | ||
gmp = super.gmp.override { | ||
withStatic = true; | ||
|
@@ -148,4 +152,15 @@ in { | |
}; | ||
}; | ||
|
||
brotli = super.brotli.override { | ||
staticOnly = true; | ||
}; | ||
|
||
curl = super.curl.override { | ||
gssSupport = false; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would imagine your target audience for this is users who are running and deploying on rootless "enterprise" environments such a RHEL or CentOS. It's worth noting that in many of these setups, kerberos is used extensively for all HTTP and git authentication, so if you could get it working in this static variant it'd probably be worthwhile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is an issue. libkrb5 doesn't have good way to link statically, however: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439039 kerberos heimdal might support it though. |
||
|
||
nix = (super.nix.override { withAWS = false; }).overrideAttrs (o: { | ||
NIX_LDFLAGS = "-lssl -lbrotlicommon -lssh2 -lz -lnghttp2 -lcrypto -latomic"; | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary I assume?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe... binutils and musl seemed to get stuck. I don't think anyone supports i686 very well any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that combination or in isolation?
with targetPlatform.isx86_32 && targetPlatform.isMusl
I'd be more comfortable with that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #62817