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

nix: static build #5814

Merged
merged 11 commits into from
Mar 5, 2024
8 changes: 7 additions & 1 deletion .devops/nix/package.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
lib,
glibc,
config,
stdenv,
mkShell,
Expand Down Expand Up @@ -30,6 +31,7 @@
useRocm ? config.rocmSupport,
useVulkan ? false,
llamaVersion ? "0.0.0", # Arbitrary version, substituted by the flake
buildStatic ? false,
hutli marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static? stdenv.hostPlatform.isStatic

}@inputs:

let
Expand Down Expand Up @@ -167,6 +169,9 @@ effectiveStdenv.mkDerivation (
# TODO: Replace with autoAddDriverRunpath
# once https://github.com/NixOS/nixpkgs/pull/275241 has been merged
cudaPackages.autoAddOpenGLRunpathHook
]
++ optionals buildStatic [
glibc.static
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
++ optionals buildStatic [
glibc.static
++ optionals (stdenv.hostPlatform.isGnu && stdenv.hostPlatform.isStatic) [
glibc.static

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't buildStatic (static if renamed) take precedence?

Copy link
Contributor Author

@hutli hutli Mar 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @SomeoneSerge is correct - or more specifically enableStatic going with @philiptaron suggestion. I have no idea how to do this in this smart GitHub interface though.

Copy link
Collaborator

@philiptaron philiptaron Mar 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that there are other static builds using other libc implementations -- musl being a great example -- that don't require adding glibc static edition. I agree that the test should include enableStatic rather than my proposal of stdenv.hostPlatform.isStatic.

The other approach, since you're hosting the stdenv, is that you add in glib.static in your hosting flake. That would work too, I think, and likely be closer to "right all the time."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. I agree that adding glib.static to the hosting flake would work but the problem I guess is then that anybody wanting a static build would have to know that they need to do so. It feels a bit more explicit to have it here too. I've implemented these changes in d12f239 and fixed some small issues so the branch now passes all tests on my end.

];

buildInputs =
Expand All @@ -181,7 +186,7 @@ effectiveStdenv.mkDerivation (
[
(cmakeBool "LLAMA_NATIVE" false)
(cmakeBool "LLAMA_BUILD_SERVER" true)
(cmakeBool "BUILD_SHARED_LIBS" true)
(cmakeBool "BUILD_SHARED_LIBS" (!buildStatic))
hutli marked this conversation as resolved.
Show resolved Hide resolved
(cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
(cmakeBool "LLAMA_BLAS" useBlas)
(cmakeBool "LLAMA_CLBLAST" useOpenCL)
Expand All @@ -190,6 +195,7 @@ effectiveStdenv.mkDerivation (
(cmakeBool "LLAMA_METAL" useMetalKit)
(cmakeBool "LLAMA_MPI" useMpi)
(cmakeBool "LLAMA_VULKAN" useVulkan)
(cmakeBool "LLAMA_STATIC" buildStatic)
hutli marked this conversation as resolved.
Show resolved Hide resolved
]
++ optionals useCuda [
(
Expand Down
Loading