Add initial basic support for cross-compiling to iOS
This commit is contained in:
parent
2ca507a2b8
commit
7df3d7446f
|
@ -1,4 +1,4 @@
|
|||
{ stdenv, fetchurl, fetchzip, pkgs }:
|
||||
{ stdenv, fetchurl, fetchzip, pkgs, fetchurlBoot }:
|
||||
|
||||
let
|
||||
# This attrset can in theory be computed automatically, but for that to work nicely we need
|
||||
|
@ -123,7 +123,14 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
fetchApple = version: sha256: name: fetchurl {
|
||||
fetchApple = version: sha256: name: let
|
||||
# When cross-compiling, fetchurl depends on libiconv, resulting
|
||||
# in an infinite recursion without this. It's not clear why this
|
||||
# worked fine when not cross-compiling
|
||||
fetch = if name == "libiconv"
|
||||
then fetchurlBoot
|
||||
else fetchurl;
|
||||
in fetch {
|
||||
url = "http://www.opensource.apple.com/tarballs/${name}/${name}-${versions.${version}.${name}}.tar.gz";
|
||||
inherit sha256;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
{ runCommand
|
||||
, lib
|
||||
, llvm
|
||||
, clang
|
||||
, binutils
|
||||
, stdenv
|
||||
, coreutils
|
||||
, gnugrep
|
||||
}: { prefix, arch, simulator ? false }: let
|
||||
sdkType = if simulator then "Simulator" else "OS";
|
||||
|
||||
sdk = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhone${sdkType}.platform/Developer/SDKs/iPhone${sdkType}10.0.sdk";
|
||||
|
||||
/* TODO: Properly integrate with gcc-cross-wrapper */
|
||||
wrapper = import ../../../build-support/cc-wrapper {
|
||||
inherit stdenv coreutils gnugrep;
|
||||
nativeTools = false;
|
||||
nativeLibc = false;
|
||||
inherit binutils;
|
||||
libc = runCommand "empty-libc" {} "mkdir -p $out/{lib,include}";
|
||||
cc = clang;
|
||||
extraBuildCommands = ''
|
||||
# ugh
|
||||
tr '\n' ' ' < $out/nix-support/cc-cflags > cc-cflags.tmp
|
||||
mv cc-cflags.tmp $out/nix-support/cc-cflags
|
||||
echo "-target ${prefix} -arch ${arch} -idirafter ${sdk}/usr/include ${if simulator then "-mios-simulator-version-min=7.0" else "-miphoneos-version-min=7.0"}" >> $out/nix-support/cc-cflags
|
||||
|
||||
# Purposefully overwrite libc-ldflags-before, cctools ld doesn't know dynamic-linker and cc-wrapper doesn't do cross-compilation well enough to adjust
|
||||
echo "-arch ${arch} -L${sdk}/usr/lib -L${sdk}/usr/lib/system" > $out/nix-support/libc-ldflags-before
|
||||
'';
|
||||
};
|
||||
in {
|
||||
cc = runCommand "${prefix}-cc" {} ''
|
||||
mkdir -p $out/bin
|
||||
ln -sv ${wrapper}/bin/clang $out/bin/${prefix}-cc
|
||||
mkdir -p $out/nix-support
|
||||
echo ${llvm} > $out/nix-support/propagated-native-build-inputs
|
||||
cat > $out/nix-support/setup-hook <<EOF
|
||||
if test "\$dontSetConfigureCross" != "1"; then
|
||||
configureFlags="\$configureFlags --host=${prefix}"
|
||||
fi
|
||||
EOF
|
||||
fixupPhase
|
||||
'';
|
||||
|
||||
binutils = runCommand "${prefix}-binutils" {} ''
|
||||
mkdir -p $out/bin
|
||||
ln -sv ${wrapper}/bin/ld $out/bin/${prefix}-ld
|
||||
for prog in ar nm ranlib; do
|
||||
ln -s ${binutils}/bin/$prog $out/bin/${prefix}-$prog
|
||||
done
|
||||
fixupPhase
|
||||
'';
|
||||
}
|
|
@ -26,4 +26,10 @@ rec {
|
|||
stdenvCross = buildPackages.makeStdenvCross
|
||||
buildPackages.stdenv crossSystem
|
||||
buildPackages.binutilsCross buildPackages.gccCrossStageFinal;
|
||||
|
||||
stdenvCrossiOS = let
|
||||
inherit (buildPackages.darwin.ios-cross { prefix = crossSystem.config; inherit (crossSystem) arch; simulator = crossSystem.isiPhoneSimulator or false; }) cc binutils;
|
||||
in buildPackages.makeStdenvCross
|
||||
buildPackages.stdenv crossSystem
|
||||
binutils cc;
|
||||
}
|
||||
|
|
|
@ -38,13 +38,15 @@ rec {
|
|||
|
||||
inherit (import ./darwin { inherit system allPackages platform config; }) stdenvDarwin;
|
||||
|
||||
inherit (import ./cross { inherit system allPackages platform crossSystem config lib; }) stdenvCross;
|
||||
inherit (import ./cross { inherit system allPackages platform crossSystem config lib; }) stdenvCross stdenvCrossiOS;
|
||||
|
||||
inherit (import ./custom { inherit system allPackages platform crossSystem config lib; }) stdenvCustom;
|
||||
|
||||
# Select the appropriate stdenv for the platform `system'.
|
||||
stdenv =
|
||||
if crossSystem != null then stdenvCross else
|
||||
if crossSystem != null then
|
||||
if crossSystem.useiOSCross or false then stdenvCrossiOS
|
||||
else stdenvCross else
|
||||
if config ? replaceStdenv then stdenvCustom else
|
||||
if system == "i686-linux" then stdenvLinux else
|
||||
if system == "x86_64-linux" then stdenvLinux else
|
||||
|
|
|
@ -10624,6 +10624,10 @@ in
|
|||
|
||||
swift-corefoundation = callPackage ../os-specific/darwin/swift-corefoundation {};
|
||||
|
||||
ios-cross = callPackage ../os-specific/darwin/ios-cross {
|
||||
inherit (darwin) binutils;
|
||||
};
|
||||
|
||||
xcode = callPackage ../os-specific/darwin/xcode {};
|
||||
|
||||
osx_sdk = callPackage ../os-specific/darwin/osx-sdk {};
|
||||
|
|
Loading…
Reference in New Issue