lol

Merge pull request #175317 from ncfavier/makeBinaryWrapper-cross

makeBinaryWrapper: fix cross-compilation and add test

authored by

Rick van Schijndel and committed by
GitHub
17e891b1 994a8a95

+58 -28
+3 -2
pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix
··· 1 1 { stdenv 2 + , targetPackages 2 3 , lib 3 4 , makeSetupHook 4 5 , dieHook 5 6 , writeShellScript 6 7 , tests 7 - , cc ? stdenv.cc 8 + , cc ? targetPackages.stdenv.cc 8 9 , sanitizers ? [] 9 10 }: 10 11 ··· 14 15 ++ lib.optional (stdenv.isDarwin && stdenv.isAarch64) cc; 15 16 16 17 substitutions = { 17 - cc = "${cc}/bin/cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}"; 18 + cc = "${cc}/bin/${cc.targetPrefix}cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}"; 18 19 19 20 # Extract the function call used to create a binary wrapper from its embedded docstring 20 21 passthru.extractCmd = writeShellScript "extract-binary-wrapper-cmd" ''
+23
pkgs/test/make-binary-wrapper/cross.nix
··· 1 + { stdenv 2 + , runCommand 3 + , makeBinaryWrapper 4 + , binutils 5 + , expectedArch ? stdenv.hostPlatform.parsed.cpu.name 6 + }: 7 + 8 + runCommand "make-binary-wrapper-test-cross" { 9 + nativeBuildInputs = [ 10 + makeBinaryWrapper 11 + binutils 12 + ]; 13 + inherit expectedArch; 14 + } '' 15 + touch prog 16 + chmod +x prog 17 + makeWrapper prog $out 18 + read -r _ arch < <($READELF --file-header $out | grep Machine:) 19 + if [[ ''${arch,,} != *"''${expectedArch,,}"* ]]; then 20 + echo "expected $expectedArch, got $arch" 21 + exit 1 22 + fi 23 + ''
+32 -26
pkgs/test/make-binary-wrapper/default.nix
··· 1 - { lib, coreutils, python3, gcc, writeText, writeScript, runCommand, makeBinaryWrapper }: 1 + { lib 2 + , stdenv 3 + , pkgsCross 4 + , makeBinaryWrapper 5 + , writeText 6 + , runCommand 7 + , runCommandCC 8 + }: 2 9 3 10 let 4 - env = { buildInputs = [ makeBinaryWrapper ]; }; 5 - envCheck = runCommand "envcheck" env '' 6 - ${gcc}/bin/cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c} 11 + env = { nativeBuildInputs = [ makeBinaryWrapper ]; }; 12 + envCheck = runCommandCC "envcheck" env '' 13 + cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c} 7 14 ''; 8 - makeGoldenTest = testname: runCommand "test-wrapper_${testname}" env '' 9 - mkdir -p ./tmp/foo 15 + makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env '' 16 + mkdir -p tmp/foo # for the chdir test 10 17 11 18 params=$(<"${./.}/${testname}.cmdline") 12 19 eval "makeCWrapper /send/me/flags $params" > wrapper.c ··· 32 39 33 40 cp wrapper.c $out 34 41 ''; 35 - tests = let 36 - names = [ 37 - "add-flags" 38 - "argv0" 39 - "basic" 40 - "chdir" 41 - "combination" 42 - "env" 43 - "inherit-argv0" 44 - "invalid-env" 45 - "prefix" 46 - "suffix" 47 - "overlength-strings" 48 - ]; 49 - f = name: lib.nameValuePair name (makeGoldenTest name); 50 - in builtins.listToAttrs (builtins.map f names); 51 - in writeText "make-binary-wrapper-test" '' 52 - ${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: '' 53 - "${test.name}" "${test}" 54 - '') tests)} 42 + tests = lib.genAttrs [ 43 + "add-flags" 44 + "argv0" 45 + "basic" 46 + "chdir" 47 + "combination" 48 + "env" 49 + "inherit-argv0" 50 + "invalid-env" 51 + "overlength-strings" 52 + "prefix" 53 + "suffix" 54 + ] makeGoldenTest // lib.optionalAttrs (! stdenv.isDarwin) { 55 + cross = pkgsCross.aarch64-multiplatform.callPackage ./cross.nix { }; 56 + }; 57 + in 58 + 59 + writeText "make-binary-wrapper-tests" '' 60 + ${lib.concatStringsSep "\n" (builtins.attrValues tests)} 55 61 '' // tests