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

Build failure: limine #304746

Open
T-O-R-U-S opened this issue Apr 17, 2024 · 8 comments
Open

Build failure: limine #304746

T-O-R-U-S opened this issue Apr 17, 2024 · 8 comments

Comments

@T-O-R-U-S
Copy link

T-O-R-U-S commented Apr 17, 2024

Steps To Reproduce

Steps to reproduce the behavior:

  1. nix-build https://github.com/NixOS/nixpkgs/archive/master.tar.gz --attr limine (behaviour is the same when trying to nix-shell -p limine)
  2. Fails finding a riscv64 cross compiler toolchain.

Build log

https://gist.github.com/T-O-R-U-S/0ed1610aeb91216fd688153d67799940

Additional context

It asks for a RISC-V compiler because the package is configured with the --enable-all flag, so it fails to compile if any architecture is missing. Can be worked around by just enabling it for the platform that you are targeting, so long as that isn't RISC-V...

P.S: I only tried with the --enable-x86_64 flag, and it seems to compile alright with that, but not with RISC-V.

Notify maintainers

@48cf
@phip1611

Thank you.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.0.0, macOS 14.0`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.21.1`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Add a 👍 reaction to issues you find important.

@48cf
Copy link

48cf commented Apr 17, 2024

I can't reproduce the failure by running nix-build https://github.com/NixOS/nixpkgs/archive/master.tar.gz --attr limine on my x86-64 Linux virtual machine and I currently don't have an aarch64/risc-v Linux virtual machine set up to test it on. Perhaps it is related to you trying to build it on macOS? I can't test that very easily as I don't use Nix on macOS, but I will try building Limine manually. Could you also post the full output of nix-store -l /nix/store/gf6cml15s4qqvm2j59pimda9ir727jgm-limine-7.3.1.drv as suggested by the log?

edit: I have no issues building Limine from a release tarball manually on my M1 MBA running macOS 14.0, llvm 17.0.6, nasm 2.16.02, GNU mtools 4.0.43 and GNU make 4.4.1

@T-O-R-U-S
Copy link
Author

@surfaceflinger
Copy link
Member

surfaceflinger commented Apr 17, 2024

nat@blahaj [~] $ nix shell nixpkgs#pkgsCross.riscv64.limine
error: builder for '/nix/store/4zryy3f1xv67xlzflar4dasa5cvasr82-limine-riscv64-unknown-linux-gnu-7.3.1.drv' failed with exit code 1;
       last 25 log lines:
       > checking for inttypes.h... yes
       > checking for stdint.h... yes
       > checking for strings.h... yes
       > checking for sys/stat.h... yes
       > checking for sys/types.h... yes
       > checking for unistd.h... yes
       > checking for stdint.h... (cached) yes
       > checking for stddef.h... yes
       > checking for stdbool.h... yes
       > checking for limits.h... yes
       > checking for inttypes.h... (cached) yes
       > checking for stdio.h... (cached) yes
       > checking for stdlib.h... (cached) yes
       > checking for string.h... (cached) yes
       > checking for clang (i686)... yes
       > checking for ld.lld (i686)... yes
       > checking for llvm-objcopy (i686)... no
       > checking for i686-elf-gcc (i686)... no
       > checking for riscv64-unknown-linux-gnu-gcc (i686)... yes
       > checking for riscv64-unknown-linux-gnu-ld (i686)... yes
       > checking for riscv64-unknown-linux-gnu-objcopy (i686)... yes
       > checking for riscv64-unknown-linux-gnu-objdump (i686)... yes
       > checking for riscv64-unknown-linux-gnu-readelf (i686)... yes
       > checking for gcc (i686)... no
       > error: could not find any valid toolchain for target 'i686'
       For full logs, run 'nix log /nix/store/4zryy3f1xv67xlzflar4dasa5cvasr82-limine-riscv64-unknown-linux-gnu-7.3.1.drv'.

yeah, so if --enable-all turns on ALL architectures according to the upstream then I don't think this is something desirable in nix.

the regular llvmPackages can target multiple triplets, while the one used in pkgsCross targets just one.

I guess the solution would be to build for just a single arch depending on target host

@T-O-R-U-S
Copy link
Author

T-O-R-U-S commented Apr 17, 2024

I did a bit more research into building Limine's tools, the --enable-* options enable UEFI or BIOS tooling, but are NOT responsible for architectures specifically. However, they do require it if trying to enable, e.g, uefi-x86-64, then you need the x86_64 toolchain. When trying to compile bios, that automatically pulls in i686. Weirdly enough, I get the same i686 error that @surfaceflinger got (that I wasn't getting before?) when building it using the nix develop env.

@T-O-R-U-S
Copy link
Author

T-O-R-U-S commented Apr 17, 2024

I made a modded version of the package for only x86_64 UEFI and x86 BIOS:

{
  pkgs ? import <nixpkgs> { },
  # Helpers
  stdenv ? pkgs.stdenv
, fetchurl ? pkgs.fetchurl
, lib ? pkgs.lib
, # Dependencies
  llvmPackages ? pkgs.llvmPackages
, mtools ? pkgs.mtools
, nasm ? pkgs.nasm
}:

let
  version = "7.3.1";
in
# The output of the derivation is a tool to create bootable images using Limine
# as bootloader for various platforms and corresponding binary and helper files.
stdenv.mkDerivation {
  inherit version;
  pname = "limine";
  # We don't use the Git source but the release tarball, as the source has a
  # `./bootstrap` script performing network access to download resources.
  # Packaging that in Nix is very cumbersome.
  src = fetchurl {
    url = "https://github.com/limine-bootloader/limine/releases/download/v${version}/limine-${version}.tar.gz";
    sha256 = "sha256-xlOBBb281W9QT5Fv2Hgw/eyh7K3oyaNY1yU6WktbFro=";
  };

  nativeBuildInputs = [
    llvmPackages.bintools
    # gcc is used for the host tool, while clang is used for the bootloader.
    llvmPackages.clang
    llvmPackages.lld
    mtools
    nasm
  ];

  configureFlags = [
    "--enable-bios-cd"
    "--enable-uefi-x86_64"
  ];

  installFlags = [ "destdir=$out" "manprefix=/share" ];

  outputs = [ "out" "doc" "dev" "man" ];

  meta = with lib; {
    homepage = "https://limine-bootloader.org/";
    description = "Limine Bootloader";
    # Caution. Some submodules have different licenses.
    license = [
      licenses.bsd2 # limine, flanterm
      licenses.bsd0 # freestanding-toolchain, freestanding-headers
      licenses.asl20 # cc-runtime
      licenses.mit # limine-efi, stb
      licenses.zlib # tinf
    ];
    # The platforms on that the Liminine binary and helper tools can run, not
    # necessarily the platforms for that bootable images can be created.
    platforms = platforms.unix;
    maintainers = [
      maintainers._48cf
      maintainers.phip1611
    ];
  };
}

Trying to build with this on macOS + Rosetta 2 (so x86_64 Nix packages are included as well as aarch64), and now I'm getting errors from lld about unknown arguments.

https://gist.github.com/T-O-R-U-S/51c181c1aacd2acc45759f3eee11929f

@phip1611
Copy link
Contributor

phip1611 commented Apr 17, 2024

When I added the derivation to nixpkgs, I decided to use --enable-all with the intention to create a Bootable image on a x86_64 platform that boots on all platforms.

I think this is a valid use case, especially if you are creating an EFI application with Rust that you easily can compile for x86, aarch64, and riscv. You can embed this into a Limine iso and add legacy boot capabilities additionally into that image.

Hence, I'd like to see the host tools being build for the host architecture but the bootloader files for all architectures.

Unfortunately, I don't have an aarch64 or riscv system to that the build..

We might could add a condition to the derivation: if x86_64 we build for all platforms, if we build on another architecture, we only build what the toolchain provides.

@T-O-R-U-S
Copy link
Author

I'd personally disagree and argue that we should try to keep nix packages as similar as possible across all platforms to keep with consumer expectation of replicability, so keeping --enable-all is probably a good call. I think we might need to change the nativeBuildInputs for darwin-aarch64 systems to fix this.

Here is a useful article section I found on the OSDev wiki, as it points out probably the exact problem we're having.

The macOS Xcode toolchain uses Mach-O binaries, and not the ELF binaries required for this Limine-compliant kernel. A solution is to build a GCC Cross-Compiler, or to obtain one from homebrew by installing the x86_64-elf-gcc package. After one of these is done, build using make CC=x86_64-elf-gcc LD=x86_64-elf-ld.

I think this is why I'm getting all the incorrect argument errors -- by default, the wrong linker is being used because Apple just loves replacing the standard solution with their own home-grown garbage. 🙃

@phip1611
Copy link
Contributor

FYI: In 26b947c someone removed darwin as platform.

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

No branches or pull requests

4 participants