lix/src
Matthew Bauer 4b9acf4e21 Use posix_spawn_setbinpref_np to advise which architecture to run
When running universal binaries like /bin/bash, Darwin XNU will choose
which architecture of the binary to use based on "binary preferences".
This change sets that to the current platform for aarch64 and x86_64
builds. In addition it now uses posix_spawn instead of the usual
execve. Note, that this does not prevent the other architecture from
being run, just advises which to use.

Unfortunately, posix_spawnattr_setbinpref_np does not appear to be
inherited by child processes in x86_64 Rosetta 2 translations, meaning
that this will not always work as expected.

For example:

  {
    arm = derivation {
      name = "test";
      system = "aarch64-darwin";
      builder = "/bin/bash";
      args = [ "-e" (builtins.toFile "test" ''
        set -x
        /usr/sbin/sysctl sysctl.proc_translated
        /usr/sbin/sysctl sysctl.proc_native
        [ "$(/usr/bin/arch)" = arm64 ]
        /usr/bin/touch $out
      '') ];
    };
    rosetta = derivation {
      name = "test";
      system = "x86_64-darwin";
      builder = "/bin/bash";
      args = [ "-e" (builtins.toFile "test" ''
        set -x
        /usr/sbin/sysctl sysctl.proc_translated
        /usr/sbin/sysctl sysctl.proc_native
        [ "$(/usr/bin/arch)" = i386 ]
        echo It works!
        /usr/bin/touch $out
      '') ];
    };
  }

`arm' fails on x86_64-compiled Nix, but `arm' and `rosetta' succeed on
aarch64-compiled Nix. I suspect there is a way to fix this since:

  $ /usr/bin/arch -arch x86_64 /bin/bash \
    -c '/usr/bin/arch -arch arm64e /bin/bash -c /usr/bin/arch'
  arm64

seems to work correctly. We may need to wait for Apple to update
system_cmds in opensource.apple.com to find out how though.
2020-12-03 15:41:59 -06:00
..
build-remote Lower verbosity for 'Failed to find a machine' message 2020-12-01 13:43:36 +01:00
cpptoml Revert the enum struct change 2020-06-18 22:11:26 +00:00
libexpr Remove an unknown pragma gcc warning 2020-12-02 14:33:20 +01:00
libfetchers fetchMercurial: set HGPLAIN when invoking hg 2020-11-23 16:12:33 +00:00
libmain Ask for confirmation before allowing flake Nix configuration settings 2020-11-26 12:37:23 +01:00
libstore Use posix_spawn_setbinpref_np to advise which architecture to run 2020-12-03 15:41:59 -06:00
libutil Add forgotten override annotation 2020-12-02 14:23:38 +01:00
nix Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
nix-build nix-build: Fix #4197 output order regression 2020-11-13 17:49:27 +01:00
nix-channel Remove static variable name clashes 2020-10-06 13:49:20 +02:00
nix-collect-garbage Remove static variable name clashes 2020-10-06 13:49:20 +02:00
nix-copy-closure Remove static variable name clashes 2020-10-06 13:49:20 +02:00
nix-daemon Remove static variable name clashes 2020-10-06 13:49:20 +02:00
nix-env Split out local-fs-store.hh 2020-10-09 20:18:08 +00:00
nix-instantiate Split out local-fs-store.hh 2020-10-09 20:18:08 +00:00
nix-prefetch-url Remove static variable name clashes 2020-10-06 13:49:20 +02:00
nix-store Allow substituting paths when building remotely using ssh-ng:// 2020-11-05 20:12:37 +01:00
resolve-system-dependencies lstat() cleanup 2020-09-23 19:17:28 +02:00