git.iko.soy/typeable/nixpkgs
on master help sign in
Merge PR #27536
commit8ba6012dfdc1214f5df7dc90955973be3f7562e3 authorJohn Ericson <John.Ericson@Obsidian.Systems> dateThu 3 Aug 2017, 17:25 (9 years ago) parent264d664cd6c452
6 files changed+221−3
pkgs/build-support/cc-wrapper/default.nix+13−2 pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash+106 pkgs/stdenv/darwin/default.nix+1−1 pkgs/test/macos-sierra-shared/default.nix+89 pkgs/top-level/all-packages.nix+11 pkgs/top-level/release.nix+1
pkgs/build-support/cc-wrapper/default.nix+13−2
@@ -12,6 +12,7 @@
1212, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
1313, buildPackages ? {}, hostPlatform, targetPlatform
1414, runCommand ? null
15+, useMacosReexportHack ? false
1516}:
1617
1718with stdenv.lib;
@@ -278,7 +279,15 @@ stdenv.mkDerivation {
278279 ln -s $ldPath/${prefix}as $out/bin/${prefix}as
279280 fi
280281
281− wrap ${prefix}ld ${preWrap ./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
282+ '' + (if !useMacosReexportHack then ''
283+ wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
284+ '' else ''
285+ export binPrefix=${prefix}
286+ ldInner="${prefix}ld-reexport-delegate"
287+ wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld}
288+ wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner"
289+ unset ldInner
290+ '') + ''
282291
283292 if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then
284293 wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
@@ -386,5 +395,7 @@ stdenv.mkDerivation {
386395 { description =
387396 stdenv.lib.attrByPath ["meta" "description"] "System C compiler" cc_
388397 + " (wrapper script)";
389− };
398+ } // optionalAttrs useMacosReexportHack {
399+ platforms = stdenv.lib.platforms.darwin;
400+ };
390401}
pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bashnew file+106
@@ -0,0 +1,106 @@
1+#! @shell@
2+
3+set -eu -o pipefail
4+
5+path_backup="$PATH"
6+if [ -n "@coreutils_bin@" ]; then
7+ PATH="@coreutils_bin@/bin"
8+fi
9+
10+declare -r recurThreshold=300
11+
12+declare overflowCount=0
13+for ((n=0; n < $#; ++n)); do
14+ case "${!n}" in
15+ -l*) let overflowCount+=1 ;;
16+ -reexport-l*) let overflowCount+=1 ;;
17+ *) ;;
18+ esac
19+done
20+
21+declare -a allArgs=()
22+
23+if (( "$overflowCount" <= "$recurThreshold" )); then
24+ allArgs=("$@")
25+else
26+ declare -a childrenLookup=() childrenLink=()
27+
28+ while (( $# )); do
29+ case "$1" in
30+ -L/*)
31+ childrenLookup+=("$1")
32+ allArgs+=("$1")
33+ ;;
34+ -L)
35+ echo "cctools LD does not support '-L foo' or '-l foo'" >&2
36+ exit 1
37+ ;;
38+ -l)
39+ echo "cctools LD does not support '-L foo' or '-l foo'" >&2
40+ exit 1
41+ ;;
42+ -lazy_library | -lazy_framework | -lto_library)
43+ # We aren't linking any "azy_library", "to_library", etc.
44+ allArgs+=("$1")
45+ ;;
46+ -lazy-l | -weak-l) allArgs+=("$1") ;;
47+ # We can't so easily prevent header issues from these.
48+ -lSystem) allArgs+=("$1") ;;
49+ # Special case as indirection seems like a bad idea for something
50+ # so fundamental. Can be removed for simplicity.
51+ -l?* | -reexport-l?*) childrenLink+=("$1") ;;
52+ *) allArgs+=("$1") ;;
53+ esac
54+
55+ shift
56+ done
57+
58+ declare n=0
59+ while (( $n < "${#childrenLink[@]}" )); do
60+ if [[ "${childrenLink[n]}" = -l* ]]; then
61+ childrenLink[n]="-reexport${childrenLink[n]}"
62+ fi
63+ let ++n
64+ done
65+ unset n
66+
67+ declare -r outputNameLibless=$(basename $( \
68+ if [[ -z "${outputName:+isUndefined}" ]]; then
69+ echo unnamed
70+ elif [[ "${outputName:0:3}" = lib ]]; then
71+ echo "${outputName:3}"
72+ else
73+ echo "${outputName}"
74+ fi))
75+ declare -ra children=("$outputNameLibless-reexport-delegate-0" \
76+ "$outputNameLibless-reexport-delegate-1")
77+
78+ mkdir -p "$out/lib"
79+
80+ PATH="$PATH:@out@/bin"
81+
82+ symbolBloatObject=$outputNameLibless-symbol-hack.o
83+ if [[ ! -e $symbolBloatObject ]]; then
84+ printf '.private_extern _______child_hack_foo\nchild_hack_foo:\n' \
85+ | @binPrefix@as -- -o $symbolBloatObject
86+ fi
87+
88+ # first half of libs
89+ @binPrefix@ld -macosx_version_min $MACOSX_DEPLOYMENT_TARGET -arch x86_64 -dylib \
90+ -o "$out/lib/lib${children[0]}.dylib" \
91+ -install_name "$out/lib/lib${children[0]}.dylib" \
92+ "${childrenLookup[@]}" "$symbolBloatObject" \
93+ "${childrenLink[@]:0:$((${#childrenLink[@]} / 2 ))}"
94+
95+ # second half of libs
96+ @binPrefix@ld -macosx_version_min $MACOSX_DEPLOYMENT_TARGET -arch x86_64 -dylib \
97+ -o "$out/lib/lib${children[1]}.dylib" \
98+ -install_name "$out/lib/lib${children[1]}.dylib" \
99+ "${childrenLookup[@]}" "$symbolBloatObject" \
100+ "${childrenLink[@]:$((${#childrenLink[@]} / 2 ))}"
101+
102+ allArgs+=("-L$out/lib" "-l${children[0]}" "-l${children[1]}")
103+fi
104+
105+PATH="$path_backup"
106+exec @prog@ "${allArgs[@]}"
pkgs/stdenv/darwin/default.nix+1−1
@@ -305,7 +305,7 @@ in rec {
305305 initialPath = import ../common-path.nix { inherit pkgs; };
306306 shell = "${pkgs.bash}/bin/bash";
307307
308− cc = import ../../build-support/cc-wrapper {
308+ cc = lib.callPackageWith {} ../../build-support/cc-wrapper {
309309 inherit (pkgs) stdenv;
310310 inherit shell;
311311 nativeTools = false;
pkgs/test/macos-sierra-shared/default.nixnew file+89
@@ -0,0 +1,89 @@
1+{ lib, clangStdenv, clang-sierraHack-stdenv, stdenvNoCC }:
2+
3+let
4+ makeBigExe = stdenv: prefix: rec {
5+
6+ count = 500;
7+
8+ sillyLibs = lib.genList (i: stdenv.mkDerivation rec {
9+ name = "${prefix}-fluff-${toString i}";
10+ unpackPhase = ''
11+ src=$PWD
12+ cat << 'EOF' > ${name}.c
13+ unsigned int asdf_${toString i}(void) {
14+ return ${toString i};
15+ }
16+ EOF
17+ '';
18+ buildPhase = ''
19+ $CC -std=c99 -shared ${name}.c -o lib${name}.dylib -Wl,-install_name,$out/lib/lib${name}.dylib
20+ '';
21+ installPhase = ''
22+ mkdir -p "$out/lib"
23+ mv lib${name}.dylib "$out/lib"
24+ '';
25+ meta.platforms = lib.platforms.darwin;
26+ }) count;
27+
28+ finalExe = stdenv.mkDerivation rec {
29+ name = "${prefix}-final-asdf";
30+ unpackPhase = ''
31+ src=$PWD
32+ cat << 'EOF' > main.cxx
33+
34+ #include <cstdlib>
35+ #include <iostream>
36+
37+ ${toString (lib.genList (i: "extern \"C\" unsigned int asdf_${toString i}(void); ") count)}
38+
39+ unsigned int (*funs[])(void) = {
40+ ${toString (lib.genList (i: "asdf_${toString i},") count)}
41+ };
42+
43+ int main(int argc, char **argv) {
44+ bool ret;
45+ unsigned int i = 0;
46+ for (auto f : funs) {
47+ if (f() != i++) {
48+ std::cerr << "Failed to get expected response from function #" << i << std::endl;
49+ return EXIT_FAILURE;
50+ }
51+ }
52+ return EXIT_SUCCESS;
53+ }
54+ EOF
55+ '';
56+ buildPhase = ''
57+ $CXX -std=c++11 main.cxx ${toString (map (x: "-l${x.name}") sillyLibs)} -o ${prefix}-asdf
58+ '';
59+ buildInputs = sillyLibs;
60+ installPhase = ''
61+ mkdir -p "$out/bin"
62+ mv ${prefix}-asdf "$out/bin"
63+ '';
64+ meta.platforms = lib.platforms.darwin;
65+ };
66+
67+ };
68+
69+ good = makeBigExe clang-sierraHack-stdenv "good";
70+
71+ bad = makeBigExe clangStdenv "bad";
72+
73+in stdenvNoCC.mkDerivation {
74+ name = "macos-sierra-shared-test";
75+ buildInputs = [ good.finalExe bad.finalExe ];
76+ # TODO(@Ericson2314): Be impure or require exact MacOS version of builder?
77+ buildCommand = ''
78+ if bad-asdf
79+ then echo "bad-asdf can succeed on non-sierra, OK" >&2
80+ else echo "bad-asdf should fail on sierra, OK" >&2
81+ fi
82+
83+ # Must succeed on all supported MacOS versions
84+ good-asdf
85+
86+ touch $out
87+ '';
88+ meta.platforms = lib.platforms.darwin;
89+}
pkgs/top-level/all-packages.nix+11
@@ -5184,6 +5184,11 @@ with pkgs;
51845184
51855185 clang = llvmPackages.clang;
51865186
5187+ clang-sierraHack = clang.override {
5188+ name = "clang-wrapper-with-reexport-hack";
5189+ useMacosReexportHack = true;
5190+ };
5191+
51875192 clang_4 = llvmPackages_4.clang;
51885193 clang_39 = llvmPackages_39.clang;
51895194 clang_38 = llvmPackages_38.clang;
@@ -5211,6 +5216,7 @@ with pkgs;
52115216
52125217 #Use this instead of stdenv to build with clang
52135218 clangStdenv = if stdenv.isDarwin then stdenv else lowPrio llvmPackages.stdenv;
5219+ clang-sierraHack-stdenv = overrideCC stdenv clang-sierraHack;
52145220 libcxxStdenv = lowPrio llvmPackages.libcxxStdenv;
52155221
52165222 clean = callPackage ../development/compilers/clean { };
@@ -19254,4 +19260,9 @@ with pkgs;
1925419260 houdini = callPackage ../applications/misc/houdini {};
1925519261
1925619262 xtermcontrol = callPackage ../applications/misc/xtermcontrol {};
19263+
19264+ # No `recurseIntoAttrs` because there's no need to nix-env these.
19265+ tests = {
19266+ macOSSierraShared = callPackage ../test/macos-sierra-shared {};
19267+ };
1925719268}
pkgs/top-level/release.nix+1
@@ -42,6 +42,7 @@ let
4242 jobs.python.x86_64-darwin
4343 jobs.rustc.x86_64-darwin
4444 jobs.go.x86_64-darwin
45+ jobs.tests.macOSSierraShared
4546 ];
4647 };
4748