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

llvmPackages.libc: init at 20.0.0-unstable-2024-12-08 #363449

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

RossComputerGuy
Copy link
Member

Things done

Adds LLVM libc, we've got the overlay building but full is still kinda borked. We're only going to support from >= LLVM 20 because it requires a lot of patching in previous versions. We're hoping the inclusion of LLVM libc at the point it is right now could help further its development and we can figure out how to package it better early on.

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label Dec 9, 2024
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Dec 9, 2024
@alyssais
Copy link
Member

The non-full variant doesn't seem to be used?

@RossComputerGuy
Copy link
Member Author

As of this time, the overlay build isn't a dependency for anything.

@alyssais
Copy link
Member

What is "the overlay build"? I don't see it explained anywhere here.

@RossComputerGuy
Copy link
Member Author

The overlay build is the non full build of LLVM libc.

@alyssais
Copy link
Member

What's the point of it?

@RossComputerGuy
Copy link
Member Author

I asked the LLVM libc team on their Discord server:

Statically link a few libc dependencies, it's mostly a concession to make it usable until we can provide a complete C library

@alyssais
Copy link
Member

What does "kinda borked" mean?

@RossComputerGuy
Copy link
Member Author

The full build has some problems still needing to be worked out. There's some odd C++ errors preventing compiling. Overlay builds work.

@alyssais
Copy link
Member

So then why add two attributes, one that works and one that doesn't? Why not just one libc attribute that builds as much as we can?

Is this actually useful for anything yet? If not, maybe we should just wait until we can at least build it properly.

@RossComputerGuy
Copy link
Member Author

I was recommended to have both as an option since it'll allow for flexibility if things are broken. I'm going to be working on fixing the full build soon, just haven't gotten time. I've got some PR's merged upstream and some other might've flown under my radar so it could be working.

@alyssais
Copy link
Member

For flexibility, wouldn't a single attribute with an option we could flip be better? Otherwise, we'd have to change everything that referred to the attribute all at once if we wanted to go from full to overlay.

@RossComputerGuy
Copy link
Member Author

My thinking was to probably have 3, two are the actual builds and one is an alias. I think other parts of LLVM does this already in nixpkgs.

@alyssais
Copy link
Member

But if the full build is working, why would we ever need the alias? Why does it need an attribute too?

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 18, 2024
@RossComputerGuy
Copy link
Member Author

We already have to set a boolean anyways for full builds. The dependencies are different too. Providing both makes it easier to test if both work and for people to experiment with.

@alyssais
Copy link
Member

If full is building, why would I want to test with overlay?

@RossComputerGuy
Copy link
Member Author

I was meaning people who write software using nix could try it out. I know some people who would want to try it out.

@alyssais
Copy link
Member

Yes, but is there a reason they'd specifically want to test out the non-full version, even if full is available and building?

@alyssais
Copy link
Member

alyssais commented Dec 19, 2024

LLVM libc doesn't implement every libc function yet so overlay mode is a compromise which it overlays on top the existing libc.

Got it. In that case, we should probably support both in libcCrossChooser, so people can easily switch between them, right? The reason this looked wrong to me at the start was that there was no way to really use one of them.

@RossComputerGuy
Copy link
Member Author

We'd need some sort of stub libc in the overlay one to pull in both since the overlay uses a different library name.

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 19, 2024
@alyssais
Copy link
Member

Oh, it's not called libc? That's weird — how is it supposed to be used then?

@RossComputerGuy
Copy link
Member Author

Oh, it's not called libc?

libllvmlibc.a

That's weird — how is it supposed to be used then?

-llvmlibc

@alyssais
Copy link
Member

Oh, it's not called libc?

libllvmlibc.a

That's weird — how is it supposed to be used then?

-llvmlibc

With -nostdlib I guess?

@RossComputerGuy
Copy link
Member Author

No, you need a libc to overlay on top of. So you'd have both.

pkgs/development/compilers/llvm/common/libc/default.nix Outdated Show resolved Hide resolved
pkgs/development/compilers/llvm/common/libc/default.nix Outdated Show resolved Hide resolved
pkgs/development/compilers/llvm/common/libc/default.nix Outdated Show resolved Hide resolved
);
};
}
libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay;
Copy link
Member

Choose a reason for hiding this comment

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

I think this attribute being for two different things depending on the platform is going to be confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tbf, we already have attributes which confuse people. clangUseLLVM, compiler-rt, stdenv.

Copy link
Member

Choose a reason for hiding this comment

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

And that's justification to make things more confusing??

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I think it's not that confusing, it'll cause some accidents until someone realizes which one they should use if they need it. The lib names are different between the two so someone could easily tell when things go wrong when an error happens. Also, documenting the attributes better would help a lot.

Copy link
Member

Choose a reason for hiding this comment

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

So why not make it explicit whether full or overlay is being used? As we've established, they're used completely differently, so there isn't a situation where you'd want an attribute that was sometimes the overlay and sometimes full.

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking was having a shim which adds in both inside the overlay mode. Then the function which selects the libc cross could detect when to use the overlay mode. That could allow for mixing LLVM libc and glibc or LLVM libc and musl.

Copy link
Member Author

Choose a reason for hiding this comment

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

From what I know, a shim can be made by writing a linker script into libc.so.

Copy link
Member

Choose a reason for hiding this comment

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

Then how about we hold off on this attribute until that's ready to go? It's not really useful as it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the shim.

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 23, 2024
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 25, 2024
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Dec 25, 2024
@github-actions github-actions bot added 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Dec 25, 2024
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1 labels Dec 25, 2024
@@ -91,7 +91,7 @@ let
&& final.parsed.kernel == platform.parsed.kernel;
isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details";
# Derived meta-data
useLLVM = final.isFreeBSD || final.isOpenBSD;
useLLVM = final.isFreeBSD || final.isOpenBSD || final.isLLVMLibc;
Copy link
Member

Choose a reason for hiding this comment

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

OOC does it make sense to ever use LLVM libc with GCC?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hard to say based on whether GCC supports the naked attribute for specific targets. I was thinking the LLVM abi which means to use the libc that it'd make sense to use the entire toolchain. That's what the team upstream thinks as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: lib The Nixpkgs function library 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 10.rebuild-darwin: 1 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants