Loading pkgs/by-name/wi/wild/adapterTest.nix 0 → 100644 +151 −0 Original line number Diff line number Diff line { lib, stdenv, gccStdenv, clangStdenv, buildPackages, runCommandCC, makeBinaryWrapper, gcc, wild, binutils-unwrapped-all-targets, clang, lld, clang-tools, useWildLinker, hello, }: let # These wrappers are REQUIRED for the Wild test suite to pass # # Write a wrapper for GCC that passes -B to *unwrapped* binutils. # This ensures that if -fuse-ld=bfd is used, gcc picks up unwrapped ld.bfd # instead of the hardcoded wrapper search directory. # We pass it last because apparently gcc likes picking ld from the *first* -B, # which we want our wild target directory to be if passed. gccWrapper = stdenv.mkDerivation { inherit (gcc) name; dontUnpack = true; dontConfigure = true; dontInstall = true; buildInputs = [ makeBinaryWrapper ]; buildPhase = '' runHook preBuild makeWrapper ${lib.getExe gcc} $out/bin/gcc \ --append-flag -B${binutils-unwrapped-all-targets}/bin runHook postBuild ''; }; gppWrapper = stdenv.mkDerivation { dontUnpack = true; dontConfigure = true; dontInstall = true; name = "g++-wrapped"; buildInputs = [ makeBinaryWrapper ]; buildPhase = '' runHook preBuild makeWrapper ${lib.getExe' gcc "g++"} $out/bin/g++ \ --append-flag -B${binutils-unwrapped-all-targets}/bin runHook postBuild ''; }; # Test helper that takes in a binary and checks that it runs # and was built with Wild helloTest = name: helloWild: let command = "$READELF -p .comment ${lib.getExe helloWild}"; emulator = stdenv.hostPlatform.emulator buildPackages; in runCommandCC "wild-${name}-test" { passthru = { inherit helloWild; }; } '' echo "Testing running the 'hello' binary which should be linked with 'wild'" >&2 ${emulator} ${lib.getExe helloWild} echo "Checking for wild in the '.comment' section" >&2 if output=$(${command} 2>&1); then if grep -Fw -- "Wild" - <<< "$output"; then touch $out else echo "No mention of 'wild' detected in the '.comment' section" >&2 echo "The command was:" >&2 echo "${command}" >&2 echo "The output was:" >&2 echo "$output" >&2 exit 1 fi else echo -n "${command}" >&2 echo " returned a non-zero exit code." >&2 echo "$output" >&2 exit 1 fi ''; in { testWild = wild.overrideAttrs { pname = "wild-tests"; doCheck = true; doInstallCheck = false; dontBuild = true; buildType = "debug"; checkInputs = [ stdenv.cc.libc.out stdenv.cc.libc.static ]; # https://github.com/davidlattimore/wild/discussions/832#discussioncomment-14482948 checkFlags = lib.optionals stdenv.hostPlatform.isAarch64 [ "--skip=integration_test::program_name_71___unresolved_symbols_object_c__" ]; # wild's tests compare the outputs of several different linkers. nixpkgs's # patching and wrappers change the output behavior, so we must make sure # that their behavior is compatible. # # Does not work if they are put in nativeCheckInputs or checkInputs preCheck = '' export LD_LIBRARY_PATH=${ lib.makeLibraryPath [ stdenv.cc.cc.lib ] }:$LD_LIBRARY_PATH export PATH=${ lib.makeBinPath [ binutils-unwrapped-all-targets clang gccWrapper gppWrapper lld clang-tools ] }:$PATH ''; installPhase = "touch $out"; }; # Test that the adapter works with a gcc stdenv adapterGcc = helloTest "adapter-gcc" ( hello.override (_: { stdenv = useWildLinker gccStdenv; }) ); # Test the adapter works with a clang stdenv adapter-llvm = helloTest "adapter-llvm" ( hello.override (_: { stdenv = useWildLinker clangStdenv; }) ); } pkgs/by-name/wi/wild/package.nix 0 → 100644 +60 −0 Original line number Diff line number Diff line { lib, fetchFromGitHub, callPackage, versionCheckHook, rustPlatform, pkg-config, zstd, nix-update-script, }: rustPlatform.buildRustPackage (finalAttrs: { pname = "wild"; version = "0.7.0"; src = fetchFromGitHub { owner = "davidlattimore"; repo = "wild"; tag = finalAttrs.version; hash = "sha256-x0IZuWjj0LRMj4pu2FVaD8SENm/UVtE1e4rl0EOZZZM="; }; cargoHash = "sha256-5s0qS8y0+EH+R1tgN2W5/+t+GdjbQdRVLlcA2KjpHsE="; cargoBuildFlags = [ "-p wild-linker" ]; strictDeps = true; nativeBuildInputs = [ pkg-config ]; buildInputs = [ zstd ]; env.ZSTD_SYS_USE_PKG_CONFIG = true; doCheck = false; # Tests are ran in passthru tests doInstallCheck = true; nativeInstallCheckInputs = [ versionCheckHook ]; versionCheckProgramArg = "--version"; passthru = { updateScript = nix-update-script { }; tests = callPackage ./adapterTest.nix { wild = finalAttrs.finalPackage; }; }; meta = { description = "Very fast linker for Linux"; homepage = "https://github.com/davidlattimore/wild"; changelog = "https://github.com/davidlattimore/wild/blob/${finalAttrs.version}/CHANGELOG.md"; license = [ lib.licenses.asl20 # or lib.licenses.mit ]; mainProgram = "wild"; maintainers = with lib.maintainers; [ RossSmyth ]; platforms = lib.platforms.linux; }; }) pkgs/stdenv/adapters.nix +16 −0 Original line number Diff line number Diff line Loading @@ -335,6 +335,22 @@ rec { } ); useWildLinker = stdenv: if !stdenv.targetPlatform.isLinux then throw "Wild only supports building Linux ELF files from Linux hosts." else stdenv.override (prev: { allowedRequisites = null; cc = prev.cc.override { bintools = prev.cc.bintools.override { extraBuildCommands = '' ln -fs ${pkgs.buildPackages.wild-wrapped}/bin/* "$out/bin" ''; }; }; }); /* Modify a stdenv so that it builds binaries optimized specifically for the machine they are built on. Loading pkgs/top-level/all-packages.nix +14 −0 Original line number Diff line number Diff line Loading @@ -6867,6 +6867,20 @@ with pkgs; vcpkg-tool-unwrapped = vcpkg-tool.override { doWrap = false; }; wild-wrapped = let ldWrapper = ../build-support/bintools-wrapper/ld-wrapper.sh; in wrapBintoolsWith { bintools = wild; extraBuildCommands = '' wrap wild ${ldWrapper} ${lib.getExe buildPackages.wild} wrap ld.wild ${ldWrapper} ${lib.getExe buildPackages.wild} wrap ${stdenv.cc.bintools.targetPrefix}ld.wild ${ldWrapper} ${lib.getExe buildPackages.wild} wrap ${stdenv.cc.bintools.targetPrefix}ld ${ldWrapper} ${lib.getExe buildPackages.wild} ''; }; whatstyle = callPackage ../development/tools/misc/whatstyle { inherit (llvmPackages) clang-unwrapped; }; Loading Loading
pkgs/by-name/wi/wild/adapterTest.nix 0 → 100644 +151 −0 Original line number Diff line number Diff line { lib, stdenv, gccStdenv, clangStdenv, buildPackages, runCommandCC, makeBinaryWrapper, gcc, wild, binutils-unwrapped-all-targets, clang, lld, clang-tools, useWildLinker, hello, }: let # These wrappers are REQUIRED for the Wild test suite to pass # # Write a wrapper for GCC that passes -B to *unwrapped* binutils. # This ensures that if -fuse-ld=bfd is used, gcc picks up unwrapped ld.bfd # instead of the hardcoded wrapper search directory. # We pass it last because apparently gcc likes picking ld from the *first* -B, # which we want our wild target directory to be if passed. gccWrapper = stdenv.mkDerivation { inherit (gcc) name; dontUnpack = true; dontConfigure = true; dontInstall = true; buildInputs = [ makeBinaryWrapper ]; buildPhase = '' runHook preBuild makeWrapper ${lib.getExe gcc} $out/bin/gcc \ --append-flag -B${binutils-unwrapped-all-targets}/bin runHook postBuild ''; }; gppWrapper = stdenv.mkDerivation { dontUnpack = true; dontConfigure = true; dontInstall = true; name = "g++-wrapped"; buildInputs = [ makeBinaryWrapper ]; buildPhase = '' runHook preBuild makeWrapper ${lib.getExe' gcc "g++"} $out/bin/g++ \ --append-flag -B${binutils-unwrapped-all-targets}/bin runHook postBuild ''; }; # Test helper that takes in a binary and checks that it runs # and was built with Wild helloTest = name: helloWild: let command = "$READELF -p .comment ${lib.getExe helloWild}"; emulator = stdenv.hostPlatform.emulator buildPackages; in runCommandCC "wild-${name}-test" { passthru = { inherit helloWild; }; } '' echo "Testing running the 'hello' binary which should be linked with 'wild'" >&2 ${emulator} ${lib.getExe helloWild} echo "Checking for wild in the '.comment' section" >&2 if output=$(${command} 2>&1); then if grep -Fw -- "Wild" - <<< "$output"; then touch $out else echo "No mention of 'wild' detected in the '.comment' section" >&2 echo "The command was:" >&2 echo "${command}" >&2 echo "The output was:" >&2 echo "$output" >&2 exit 1 fi else echo -n "${command}" >&2 echo " returned a non-zero exit code." >&2 echo "$output" >&2 exit 1 fi ''; in { testWild = wild.overrideAttrs { pname = "wild-tests"; doCheck = true; doInstallCheck = false; dontBuild = true; buildType = "debug"; checkInputs = [ stdenv.cc.libc.out stdenv.cc.libc.static ]; # https://github.com/davidlattimore/wild/discussions/832#discussioncomment-14482948 checkFlags = lib.optionals stdenv.hostPlatform.isAarch64 [ "--skip=integration_test::program_name_71___unresolved_symbols_object_c__" ]; # wild's tests compare the outputs of several different linkers. nixpkgs's # patching and wrappers change the output behavior, so we must make sure # that their behavior is compatible. # # Does not work if they are put in nativeCheckInputs or checkInputs preCheck = '' export LD_LIBRARY_PATH=${ lib.makeLibraryPath [ stdenv.cc.cc.lib ] }:$LD_LIBRARY_PATH export PATH=${ lib.makeBinPath [ binutils-unwrapped-all-targets clang gccWrapper gppWrapper lld clang-tools ] }:$PATH ''; installPhase = "touch $out"; }; # Test that the adapter works with a gcc stdenv adapterGcc = helloTest "adapter-gcc" ( hello.override (_: { stdenv = useWildLinker gccStdenv; }) ); # Test the adapter works with a clang stdenv adapter-llvm = helloTest "adapter-llvm" ( hello.override (_: { stdenv = useWildLinker clangStdenv; }) ); }
pkgs/by-name/wi/wild/package.nix 0 → 100644 +60 −0 Original line number Diff line number Diff line { lib, fetchFromGitHub, callPackage, versionCheckHook, rustPlatform, pkg-config, zstd, nix-update-script, }: rustPlatform.buildRustPackage (finalAttrs: { pname = "wild"; version = "0.7.0"; src = fetchFromGitHub { owner = "davidlattimore"; repo = "wild"; tag = finalAttrs.version; hash = "sha256-x0IZuWjj0LRMj4pu2FVaD8SENm/UVtE1e4rl0EOZZZM="; }; cargoHash = "sha256-5s0qS8y0+EH+R1tgN2W5/+t+GdjbQdRVLlcA2KjpHsE="; cargoBuildFlags = [ "-p wild-linker" ]; strictDeps = true; nativeBuildInputs = [ pkg-config ]; buildInputs = [ zstd ]; env.ZSTD_SYS_USE_PKG_CONFIG = true; doCheck = false; # Tests are ran in passthru tests doInstallCheck = true; nativeInstallCheckInputs = [ versionCheckHook ]; versionCheckProgramArg = "--version"; passthru = { updateScript = nix-update-script { }; tests = callPackage ./adapterTest.nix { wild = finalAttrs.finalPackage; }; }; meta = { description = "Very fast linker for Linux"; homepage = "https://github.com/davidlattimore/wild"; changelog = "https://github.com/davidlattimore/wild/blob/${finalAttrs.version}/CHANGELOG.md"; license = [ lib.licenses.asl20 # or lib.licenses.mit ]; mainProgram = "wild"; maintainers = with lib.maintainers; [ RossSmyth ]; platforms = lib.platforms.linux; }; })
pkgs/stdenv/adapters.nix +16 −0 Original line number Diff line number Diff line Loading @@ -335,6 +335,22 @@ rec { } ); useWildLinker = stdenv: if !stdenv.targetPlatform.isLinux then throw "Wild only supports building Linux ELF files from Linux hosts." else stdenv.override (prev: { allowedRequisites = null; cc = prev.cc.override { bintools = prev.cc.bintools.override { extraBuildCommands = '' ln -fs ${pkgs.buildPackages.wild-wrapped}/bin/* "$out/bin" ''; }; }; }); /* Modify a stdenv so that it builds binaries optimized specifically for the machine they are built on. Loading
pkgs/top-level/all-packages.nix +14 −0 Original line number Diff line number Diff line Loading @@ -6867,6 +6867,20 @@ with pkgs; vcpkg-tool-unwrapped = vcpkg-tool.override { doWrap = false; }; wild-wrapped = let ldWrapper = ../build-support/bintools-wrapper/ld-wrapper.sh; in wrapBintoolsWith { bintools = wild; extraBuildCommands = '' wrap wild ${ldWrapper} ${lib.getExe buildPackages.wild} wrap ld.wild ${ldWrapper} ${lib.getExe buildPackages.wild} wrap ${stdenv.cc.bintools.targetPrefix}ld.wild ${ldWrapper} ${lib.getExe buildPackages.wild} wrap ${stdenv.cc.bintools.targetPrefix}ld ${ldWrapper} ${lib.getExe buildPackages.wild} ''; }; whatstyle = callPackage ../development/tools/misc/whatstyle { inherit (llvmPackages) clang-unwrapped; }; Loading