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

Add stdenv & CC support for Zig #318034

Merged
merged 8 commits into from
Jul 28, 2024
Merged

Add stdenv & CC support for Zig #318034

merged 8 commits into from
Jul 28, 2024

Conversation

RossComputerGuy
Copy link
Member

@RossComputerGuy RossComputerGuy commented Jun 7, 2024

Description of changes

Introduces the ability to compile programs in nixpkgs using Zig with its own zigStdenv and CC adapter. This is kinda broken at the moment but it does not break anything critical so rebuilds should be 0 (except patching things like meson). However, the only problem seems to be an issue with Zig trying to link glibc right now. It is linking the libc.so linker script instead of the shared library.

Things done

  • 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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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 6.topic: stdenv Standard environment 6.topic: zig labels Jun 7, 2024
@RossComputerGuy RossComputerGuy force-pushed the feat/zig-cc branch 3 times, most recently from 7ddaa09 to 769cc80 Compare June 7, 2024 16:46
@RossComputerGuy RossComputerGuy changed the base branch from master to staging June 7, 2024 17:13
@RossComputerGuy RossComputerGuy force-pushed the feat/zig-cc branch 3 times, most recently from e7af075 to d667241 Compare June 7, 2024 17:16
@RossComputerGuy RossComputerGuy force-pushed the feat/zig-cc branch 2 times, most recently from 516e37e to 9574baa Compare June 25, 2024 06:29
@RossComputerGuy
Copy link
Member Author

RossComputerGuy commented Jun 25, 2024

Close to this working, need to resolve a crash of produced binaries discovered that is being caused by the CC wrapper.

@RossComputerGuy RossComputerGuy force-pushed the feat/zig-cc branch 4 times, most recently from acd42a1 to ee2c990 Compare June 26, 2024 01:51
@RossComputerGuy
Copy link
Member Author

We're now producing binaries correctly. pkgsZig.hello builds.

@RossComputerGuy RossComputerGuy marked this pull request as ready for review June 26, 2024 01:53
@RossComputerGuy RossComputerGuy force-pushed the feat/zig-cc branch 2 times, most recently from 9f04d18 to a043f6a Compare June 26, 2024 02:00
@RossComputerGuy
Copy link
Member Author

Fixed eval and so this should work now properly.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4278

@tomberek
Copy link
Contributor

x86_64-unknown-linux-gnu-nolibc-gcc> ../../gcc-13.3.0/gcc/analyzer/diagnostic-manager.cc: In member function 'void ana::saved_diagnostic::dump_as_dot_node(pretty_printer*) const':
x86_64-unknown-linux-gnu-nolibc-gcc> ../../gcc-13.3.0/gcc/analyzer/diagnostic-manager.cc:802:28: warning: unknown conversion type character 'E' in format [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wformat=-Wformat=8;;]
x86_64-unknown-linux-gnu-nolibc-gcc>   802 |     pp_printf (pp, "var: %qE\n", m_var);
x86_64-unknown-linux-gnu-nolibc-gcc>       |                            ^
x86_64-unknown-linux-gnu-nolibc-gcc> ../../gcc-13.3.0/gcc/analyzer/diagnostic-manager.cc:802:20: warning: too many arguments for format [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wformat-extra-args-Wformat-extra-args8;;]
x86_64-unknown-linux-gnu-nolibc-gcc>   802 |     pp_printf (pp, "var: %qE\n", m_var);
x86_64-unknown-linux-gnu-nolibc-gcc>       |                    ^~~~~~~~~~~~
error: build of '/nix/store/yr237v031vhn8qwzivg4p2mjh6581nyk-llvm-18.1.8.drv' on 'ssh-ng://nixbld@fd7a:115c:a1e0::22' failed: builder for '/nix/store/yr237v031vhn8qwzivg4p2mjh6581nyk-llvm-18.1.8.drv' failed with exit code 1;
       last 25 log lines:
       > 0x87fcf9 cp_parser_declaration_seq_opt(cp_parser*)
       >         ???:0
       > 0x880196 cp_parser_namespace_definition(cp_parser*)
       >     ???:0
       > 0x880b44 cp_parser_declaration(cp_parser*, tree_node*)
       >  ???:0
       > 0x8812d9 c_parse_file()
       >         ???:0
       > 0x977021 c_common_parse_file()
       >  ???:0
       > Please submit a full bug report, with preprocessed source (by using -freport-bug).
       > Please include the complete backtrace with any bug report.
       > See <https://gcc.gnu.org/bugs/> for instructions.
       > [2359/4385] Building CXX object lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/AArch64A57FPLoadBalancing.cpp.o
       > [2360/4385] Building CXX object lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/GISel/AArch64PreLegalizerCombiner.cpp.o
       > [2361/4385] Building CXX object lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/GISel/AArch64PostLegalizerCombiner.cpp.o

@RossComputerGuy
Copy link
Member Author

@tomberek That's a strange failure, could you post the nix log of /nix/store/yr237v031vhn8qwzivg4p2mjh6581nyk-llvm-18.1.8.drv? It looks almost like clang panicked.

@tomberek
Copy link
Contributor

/nix/store/yr237v031vhn8qwzivg4p2mjh6581nyk-llvm-18.1.8.drv

https://dpaste.com/5MM6CN38C

@tomberek
Copy link
Contributor

Not sure why yet, but the Zig stdenv seems to perform classical ./configure operations very slowly.

@RossComputerGuy
Copy link
Member Author

Well @tomberek, I have your answer to that https://github.com/NixOS/nixpkgs/pull/318034/files#diff-145f2d578ddec955b3b15a9c780b174bceb9959f496e404185bb2dd63506af6dR16

We need to set the cache or it just doesn't build. Probably could make it a static path inside the build top.

@tomberek
Copy link
Contributor

  • builds: hello, zlib, nasm, sqlite, brotli, m4, automake
  • fails: libpng, libjpeg

@RossComputerGuy
Copy link
Member Author

Rebased to fix conflicts

@tomberek
Copy link
Contributor

Still works, same success/fail as before.

@tomberek tomberek merged commit cc7b011 into NixOS:staging Jul 28, 2024
33 of 35 checks passed
@RossComputerGuy RossComputerGuy deleted the feat/zig-cc branch July 29, 2024 01:43
# https://github.com/mesonbuild/meson/pull/12293
(fetchpatch {
name = "linker-support-zig-cc.patch";
url = "https://github.com/mesonbuild/meson/pull/12293/commits/2baae244c995794d9addfe6ed924dfa72f01be82.patch";
Copy link
Member

Choose a reason for hiding this comment

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

Random commits in unmerged pull requests are not stable URLs. If you must use a non-upstream patch like this, it has to be vendored to ensure it can still be built in future.

Copy link
Member

Choose a reason for hiding this comment

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

This also doesn't look like it's going to be upstream any time soon. I think this might have been a bit premature…

Copy link
Member Author

@RossComputerGuy RossComputerGuy Jul 30, 2024

Choose a reason for hiding this comment

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

Yeah, will pull this patch into it's own file in #331011

@trofi
Copy link
Contributor

trofi commented Jul 30, 2024

This exposed a bunch of eval failures like pkgsArocc.ArchiSteamFarm:

$ nix build --no-link -f. pkgsArocc.ArchiSteamFarm
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:9:12:
            8|
            9|   strict = derivationStrict drvAttrs;
             |            ^
           10|

       … while evaluating derivation 'ArchiSteamFarm-6.0.4.4'
         whose name attribute is located at /home/slyfox/dev/git/nixpkgs-staging/pkgs/stdenv/generic/make-derivation.nix:336:7

       … while evaluating attribute 'nativeBuildInputs' of derivation 'ArchiSteamFarm-6.0.4.4'
         at pkgs/stdenv/generic/make-derivation.nix:380:7:
          379|       depsBuildBuild              = elemAt (elemAt dependencies 0) 0;
          380|       nativeBuildInputs           = elemAt (elemAt dependencies 0) 1;
             |       ^
          381|       depsBuildTarget             = elemAt (elemAt dependencies 0) 2;

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'lib' missing
       at pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix:24:11:
           23|         libPath = lib.makeLibraryPath [
           24|           stdenv.cc.cc.lib
             |           ^
           25|           stdenv.cc.libc
       Did you mean zig?

@RossComputerGuy
Copy link
Member Author

Yeah, not surprised a new stdenv has this. Will be fixing this in #331011.

@trofi
Copy link
Contributor

trofi commented Jul 31, 2024

pkgsZig seems to have a similar problem:

$ nix build --no-link -f. pkgsZig.ccacheWrapper
error:
       … while calling a functor (an attribute set with a '__functor' attribute)
         at pkgs/top-level/all-packages.nix:17992:19:
        17991|   # should be owned by user root, group nixbld with permissions 0770.
        17992|   ccacheWrapper = makeOverridable ({ extraConfig, cc }:
             |                   ^
        17993|     cc.override {

       … while evaluating a branch condition
         at lib/customisation.nix:148:7:
          147|     in
          148|       if isAttrs result then
             |       ^
          149|         result // {

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: function 'anonymous lambda' called with unexpected argument 'cc'
       at pkgs/development/compilers/zig/cc.nix:1:1:
            1| {
             | ^
            2|   lib,

@RossComputerGuy
Copy link
Member Author

Already been fixed in #331011.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants