From 88e58a4fa208a967c4e4bde5beda86e44eca9c12 Mon Sep 17 00:00:00 2001 From: Florian Friesdorf Date: Tue, 26 May 2015 15:18:49 +0200 Subject: [PATCH] cygwin: stdenv --- maintainers/scripts/hydra_eval_check | 1 + .../cygwin/all-buildinputs-as-runtimedep.sh | 16 ++++ pkgs/stdenv/cygwin/rebase-i686.sh | 21 ++++++ pkgs/stdenv/cygwin/rebase-x86_64.sh | 21 ++++++ pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh | 74 +++++++++++++++++++ pkgs/stdenv/default.nix | 2 + pkgs/stdenv/generic/default.nix | 3 + pkgs/stdenv/native/default.nix | 23 ++++-- pkgs/top-level/release-lib.nix | 2 + 9 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh create mode 100644 pkgs/stdenv/cygwin/rebase-i686.sh create mode 100644 pkgs/stdenv/cygwin/rebase-x86_64.sh create mode 100644 pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh diff --git a/maintainers/scripts/hydra_eval_check b/maintainers/scripts/hydra_eval_check index e16a40455a3..c8e03424f32 100755 --- a/maintainers/scripts/hydra_eval_check +++ b/maintainers/scripts/hydra_eval_check @@ -6,6 +6,7 @@ hydra_eval_jobs \ --argstr system i686-linux \ --argstr system x86_64-darwin \ --argstr system i686-cygwin \ + --argstr system x86_64-cygwin \ --argstr system i686-freebsd \ --arg officialRelease false \ --arg nixpkgs "{ outPath = builtins.storePath ./. ; rev = 1234; }" \ diff --git a/pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh b/pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh new file mode 100644 index 00000000000..7cb6a58f180 --- /dev/null +++ b/pkgs/stdenv/cygwin/all-buildinputs-as-runtimedep.sh @@ -0,0 +1,16 @@ +# On cygwin, automatic runtime dependency detection does not work +# because the binaries do not contain absolute references to store +# locations (yet) +postFixupHooks+=(_cygwinAllBuildInputsAsRuntimeDep) + +_cygwinAllBuildInputsAsRuntimeDep() { + if [ -n "$buildInputs" ]; then + mkdir -p "$out/nix-support" + echo "$buildInputs" >> "$out/nix-support/cygwin-buildinputs-as-runtime-deps" + fi + + if [ -n "$nativeBuildInputs" ]; then + mkdir -p "$out/nix-support" + echo "$nativeBuildInputs" >> "$out/nix-support/cygwin-buildinputs-as-runtime-deps" + fi +} diff --git a/pkgs/stdenv/cygwin/rebase-i686.sh b/pkgs/stdenv/cygwin/rebase-i686.sh new file mode 100644 index 00000000000..e5695c75a96 --- /dev/null +++ b/pkgs/stdenv/cygwin/rebase-i686.sh @@ -0,0 +1,21 @@ +postFixupHooks+=(_cygwinFixAutoImageBase) + +_cygwinFixAutoImageBase() { + find $out -name "*.dll" | while read DLL; do + if [ -f /etc/rebasenix.nextbase ]; then + NEXTBASE="$(>16)+1)<<16)) + + echo "REBASE FIX: $DLL $BASE -> $NEXTBASE" + /bin/rebase -b $NEXTBASE $DLL + NEXTBASE="0x`printf %x $(($NEXTBASE+$SKIP))`" + + echo $NEXTBASE > /etc/rebasenix.nextbase + done +} diff --git a/pkgs/stdenv/cygwin/rebase-x86_64.sh b/pkgs/stdenv/cygwin/rebase-x86_64.sh new file mode 100644 index 00000000000..f782f18dfd1 --- /dev/null +++ b/pkgs/stdenv/cygwin/rebase-x86_64.sh @@ -0,0 +1,21 @@ +postFixupHooks+=(_cygwinFixAutoImageBase) + +_cygwinFixAutoImageBase() { + find $out -name "*.dll" | while read DLL; do + if [ -f /etc/rebasenix.nextbase ]; then + NEXTBASE="$(>16)+1)<<16)) + + echo "REBASE FIX: $DLL $BASE -> $NEXTBASE" + /bin/rebase -b $NEXTBASE $DLL + NEXTBASE="0x`printf %x $(($NEXTBASE+$SKIP))`" + + echo $NEXTBASE > /etc/rebasenix.nextbase + done +} diff --git a/pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh b/pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh new file mode 100644 index 00000000000..d0da8c1b65c --- /dev/null +++ b/pkgs/stdenv/cygwin/wrap-exes-to-find-dlls.sh @@ -0,0 +1,74 @@ +postFixupHooks+=(_cygwinWrapExesToFindDlls) + +_cygwinWrapExesToFindDlls() { + find $out -type l | while read LINK; do + TARGET="$(readlink "${LINK}")" + + # fix all non .exe links that link explicitly to a .exe + if [[ ${TARGET} == *.exe ]] && [[ ${LINK} != *.exe ]]; then + mv "${LINK}" "${LINK}.exe" + LINK="${LINK}.exe" + fi + + # generate complementary filenames + if [[ ${LINK} == *.exe ]]; then + _LINK="${LINK%.exe}" + _TARGET="${TARGET%.exe}" + else + _LINK="${LINK}.exe" + _TARGET="${TARGET}.exe" + fi + + # check if sould create complementary link + DOLINK=1 + if [[ ${_TARGET} == *.exe ]]; then + # the canonical target has to be a .exe + CTARGET="$(readlink -f "${LINK}")" + if [[ ${CTARGET} != *.exe ]]; then + CTARGET="${CTARGET}.exe" + fi + + if [ ! -e "${CTARGET}" ]; then + unset DOLINK + fi + fi + + if [ -e "${_LINK}" ]; then + # complementary link seems to exist + # but could be cygwin smoke and mirrors + INO=$(stat -c%i "${LINK}") + _INO=$(stat -c%i "${_LINK}") + if [ "${INO}" -ne "${_INO}" ]; then + unset DOLINK + fi + fi + + # create complementary link + if [ -n "${DOLINK}" ]; then + ln -s "${_TARGET}" "${_LINK}.tmp" + mv "${_LINK}.tmp" "${_LINK}" + fi + done + + find $out -type f -name "*.exe" | while read EXE; do + WRAPPER="${EXE%.exe}" + if [ -e "${WRAPPER}" ]; then + # check if really exists or cygwin smoke and mirrors + INO=$(stat -c%i "${EXE}") + _INO=$(stat -c%i "${WRAPPER}") + if [ "${INO}" -ne "${_INO}" ]; then + continue + fi + fi + + mv "${EXE}" "${EXE}.tmp" + + cat >"${WRAPPER}" <