Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the error of making symlink in setupCompilerEnvironmentPhase. #84985

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/languages-frameworks/haskell.section.md
Expand Up @@ -101,10 +101,10 @@ to compile your Haskell packages with any GHC version you please. The following
command displays the complete list of available compilers:
```
$ nix-env -f "<nixpkgs>" -qaP -A haskell.compiler
haskell.compiler.ghc8101 ghc-8.10.0.20191210
haskell.compiler.integer-simple.ghc8101 ghc-8.10.0.20191210
haskell.compiler.ghcHEAD ghc-8.10.20191119
haskell.compiler.integer-simple.ghcHEAD ghc-8.10.20191119
haskell.compiler.ghc8101 ghc-8.10.1
haskell.compiler.integer-simple.ghc8101 ghc-8.10.1
haskell.compiler.ghcHEAD ghc-8.11.20200403
haskell.compiler.integer-simple.ghcHEAD ghc-8.11.20200403
haskell.compiler.ghc822Binary ghc-8.2.2-binary
haskell.compiler.ghc844 ghc-8.4.4
haskell.compiler.ghc863Binary ghc-8.6.3-binary
Expand Down
48 changes: 30 additions & 18 deletions pkgs/development/compilers/ghc/head.nix
Expand Up @@ -2,13 +2,17 @@

# build-tools
, bootPkgs
, autoconf, autoreconfHook, automake, coreutils, fetchgit, fetchpatch, perl, python3, m4, sphinx
, autoconf, autoreconfHook, automake, coreutils, fetchgit, perl, python3, m4, sphinx
, bash

, libiconv ? null, ncurses

, # GHC can be built with system libffi or a bundled one.
libffi ? null

, enableDwarf ? !stdenv.targetPlatform.isDarwin &&
!stdenv.targetPlatform.isWindows, elfutils # for DWARF support
!stdenv.targetPlatform.isWindows
, elfutils # for DWARF support

, useLLVM ? !stdenv.targetPlatform.isx86 || stdenv.targetPlatform.isiOS
, # LLVM is conceptually a run-time-only depedendency, but for
Expand All @@ -18,7 +22,8 @@

, # If enabled, GHC will be built with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
enableIntegerSimple ? !(stdenv.lib.any (stdenv.lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp
enableIntegerSimple ? !(stdenv.lib.any (stdenv.lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms)
, gmp

, # If enabled, use -fPIC when compiling static libs.
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
Expand All @@ -30,7 +35,7 @@
, # Whetherto build terminfo.
enableTerminfo ? !stdenv.targetPlatform.isWindows

, version ? "8.10.20191119"
, version ? "8.11.20200403"
, # What flavour to build. An empty string indicates no
# specific flavour and falls back to ghc default values.
ghcFlavour ? stdenv.lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
Expand Down Expand Up @@ -75,6 +80,7 @@ let

# Splicer will pull out correct variations
libDeps = platform: stdenv.lib.optional enableTerminfo ncurses
++ [libffi]
++ stdenv.lib.optional (!enableIntegerSimple) gmp
++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv
++ stdenv.lib.optional enableDwarf elfutils;
Expand All @@ -97,17 +103,14 @@ stdenv.mkDerivation (rec {

src = fetchgit {
url = "https://gitlab.haskell.org/ghc/ghc.git/";
rev = "0418c38d55c7a47967187dce2db5ea2ab1021b1e";
sha256 = "1d8g30ii0w4xh6fh61bxbalsqqyanny99nn3p727fx7favnhgvxi";
rev = "4291bddaea3148908c55f235ee8978e1d9aa6f20";
sha256 = "1gs3mxmsdpsgsp7vnawx8mys0qwg4x2zhfrbciy3wv8nv13ar1af";
};

enableParallelBuilding = true;

outputs = [ "out" "doc" ];

patches = [
];

postPatch = "patchShebangs .";

# GHC is a bit confused on its cross terminology.
Expand All @@ -130,8 +133,8 @@ stdenv.mkDerivation (rec {
export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"

echo -n "${buildMK}" > mk/build.mk
echo ${version} >VERSION
echo ${src.rev} >GIT_COMMIT_ID
echo ${version} > VERSION
echo ${src.rev} > GIT_COMMIT_ID
./boot
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
'' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
Expand Down Expand Up @@ -161,31 +164,40 @@ stdenv.mkDerivation (rec {
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ]
++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";

# `--with` flags for libraries needed for RTS linker
configureFlags = [
"--datadir=$doc/share/doc/ghc"
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
"--with-curses-libraries=${ncurses.out}/lib"
] ++ stdenv.lib.optionals (libffi != null) [
"--with-system-libffi"
"--with-ffi-includes=${targetPackages.libffi.dev}/include"
"--with-ffi-libraries=${targetPackages.libffi.out}/lib"
] ++ stdenv.lib.optionals (targetPlatform == hostPlatform && !enableIntegerSimple) [
"--with-gmp-includes=${targetPackages.gmp.dev}/include" "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
"--with-gmp-includes=${targetPackages.gmp.dev}/include"
"--with-gmp-libraries=${targetPackages.gmp.out}/lib"
] ++ stdenv.lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
"--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
"--with-iconv-includes=${libiconv}/include"
"--with-iconv-libraries=${libiconv}/lib"
] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
"--enable-bootstrap-with-devel-snapshot"
] ++ stdenv.lib.optionals useLdGold [
"CFLAGS=-fuse-ld=gold"
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
"--disable-large-address-space"
] ++ stdenv.lib.optionals enableDwarf [
] ++ stdenv.lib.optional disableLargeAddressSpace "--disable-large-address-space"
++ stdenv.lib.optionals enableDwarf [
"--enable-dwarf-unwind"
"--with-libdw-includes=${stdenv.lib.getDev elfutils}/include"
"--with-libdw-libraries=${stdenv.lib.getLib elfutils}/lib"
];

# Make sure we never relax`$PATH` and hooks support for compatability.
# Make sure we never relax`$PATH` and hooks support for compatibility.
strictDeps = true;

# Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
dontAddExtraLibs = true;

nativeBuildInputs = [
perl autoconf autoreconfHook automake m4 python3 sphinx
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
Expand Down
26 changes: 22 additions & 4 deletions pkgs/development/haskell-modules/generic-builder.nix
Expand Up @@ -383,11 +383,29 @@ stdenv.mkDerivation ({
mv tmp "$d"
done

for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
for lib in "$d/"*.{dylib,so}; do
ln -s "$lib" "$dynamicLinksDir"
makeDynamicLinks () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junjihashimoto Is there a reason for putting this in a function?

Also, could you add some more comments to this code? It is not clear what it is doing or why it is needed. (I know it didn't have any comments to start out with, but it would be nice to get some comments now, hopefully since you have a good idea of what it is doing.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Sorry for bothering you.

https://github.com/hasktorch/hasktorch/runs/578941364?check_suite_focus=true
This version using makeDynamicLinks fails.

https://github.com/hasktorch/hasktorch/runs/541868184
The test using ln -sf passes.

I seem to misunderstand the problem.

for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do
for lib in "$d/"*.{dylib,so} ; do
# When '*.{dylib,so}' does not match anything, '*.{dylib,so}' becomes '*.dylink or *.so' including '*'
# [ -f "$lib" ] checks if the matched path is available.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use shopt -s nullglob to prevent this from happening and needing this condition

if [ -f "$lib" ] ; then
local linkPath="$dynamicLinksDir/$(basename "$lib")"
if [ -e "$linkPath" ]; then
# link already exists! but maybe that's OK
if [ ! -L "$linkPath" ] || [ "$(readlink "$linkPath")" != "$lib" ]; then
echo >&2 "error: failed to create symbolic link $linkPath: file exists"
Copy link
Member

@infinisil infinisil May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest explicitly not making this error look like a standard file exists error, this only seems misleading. How about "Not attempting to link from <x> to <y> because <reason>" instead

exit 1
fi
else
ln -s "$lib" "$linkPath"
fi
fi
done
done
done
}

makeDynamicLinks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be a function, you can just inline it here


# Edit the local package DB to reference the links directory.
for f in "$packageConfDir/"*.conf; do
sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," "$f"
Expand Down
87 changes: 78 additions & 9 deletions pkgs/development/haskell-modules/hackage-packages.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pkgs/top-level/haskell-packages.nix
Expand Up @@ -81,10 +81,11 @@ in {
llvmPackages = pkgs.llvmPackages_9;
};
ghcHEAD = callPackage ../development/compilers/ghc/head.nix {
bootPkgs = packages.ghc865Binary;
bootPkgs = packages.ghc883; # no binary yet
inherit (buildPackages.python3Packages) sphinx;
buildLlvmPackages = buildPackages.llvmPackages_6;
llvmPackages = pkgs.llvmPackages_6;
buildLlvmPackages = buildPackages.llvmPackages_9;
llvmPackages = pkgs.llvmPackages_9;
libffi = pkgs.libffi;
};
ghcjs = compiler.ghcjs86;
ghcjs86 = callPackage ../development/compilers/ghcjs-ng {
Expand Down