From 606370d8539613b6698b47b39f828b886ddf82c2 Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Fri, 17 Apr 2020 16:51:01 +0200 Subject: [PATCH 1/5] crystal: use llvm 10 exclusively --- pkgs/top-level/all-packages.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 3cb27cf590e..4b6a2b77427 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8077,8 +8077,7 @@ in cryptol = haskell.lib.justStaticExecutables haskellPackages.cryptol; inherit (callPackages ../development/compilers/crystal { - stdenv = if stdenv.cc.isClang then llvmPackages.stdenv else stdenv; - inherit (llvmPackages) clang llvm; + inherit (llvmPackages_10) stdenv clang llvm; }) crystal_0_31 crystal_0_32 From fd1047a798d3e413472030a84afdba644dab4923 Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Fri, 17 Apr 2020 17:05:01 +0200 Subject: [PATCH 2/5] crystal: add LLVM_CONFIG --- pkgs/development/compilers/crystal/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/compilers/crystal/default.nix b/pkgs/development/compilers/crystal/default.nix index db22b668cf5..8f75692d883 100644 --- a/pkgs/development/compilers/crystal/default.nix +++ b/pkgs/development/compilers/crystal/default.nix @@ -108,6 +108,8 @@ let "all" "docs" ]; + LLVM_CONFIG = "${llvm}/bin/llvm-config"; + FLAGS = [ "--release" "--single-module" # needed for deterministic builds From 85897a44234a07941df7e402b800ba9e3cad0642 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Wed, 18 Mar 2020 10:47:24 +0800 Subject: [PATCH 3/5] crystal: build using Makefile or shards if available --- .../compilers/crystal/build-package.nix | 136 +++++++++++++----- 1 file changed, 98 insertions(+), 38 deletions(-) diff --git a/pkgs/development/compilers/crystal/build-package.nix b/pkgs/development/compilers/crystal/build-package.nix index 8ffa89a11b4..9cf5701d12f 100644 --- a/pkgs/development/compilers/crystal/build-package.nix +++ b/pkgs/development/compilers/crystal/build-package.nix @@ -1,6 +1,9 @@ -{ stdenv, lib, crystal, linkFarm, fetchFromGitHub }: -{ # Generate shards.nix with `nix-shell -p crystal2nix --run crystal2nix` in the projects root - shardsFile ? null +{ stdenv, lib, crystal, shards, git, pkgconfig, which, linkFarm, fetchFromGitHub }: +{ + # Some projects do not include a lock file, so you can pass one + lockFile ? null + # Generate shards.nix with `nix-shell -p crystal2nix --run crystal2nix` in the projects root +, shardsFile ? null # Specify binaries to build in the form { foo.src = "src/foo.cr"; } # The default `crystal build` options can be overridden with { foo.options = [ "--no-debug" ]; } , crystalBinaries ? {} @@ -9,45 +12,102 @@ let mkDerivationArgs = builtins.removeAttrs args [ "shardsFile" "crystalBinaries" ]; - crystalLib = linkFarm "crystal-lib" (lib.mapAttrsToList (name: value: { - inherit name; - path = fetchFromGitHub value; - }) (import shardsFile)); + crystalLib = linkFarm "crystal-lib" ( + lib.mapAttrsToList ( + name: value: { + inherit name; + path = fetchFromGitHub value; + } + ) (import shardsFile) + ); - defaultOptions = [ "--release" "--progress" "--no-debug" "--verbose" ]; + # we previously had --no-debug here but that is not recommended by upstream + defaultOptions = [ "--release" "--progress" "--verbose" ]; -in stdenv.mkDerivation (mkDerivationArgs // { + buildDirectly = shardsFile == null || crystalBinaries != {}; +in +stdenv.mkDerivation ( + mkDerivationArgs // { - configurePhase = args.configurePhase or '' - runHook preConfigure - ${lib.optionalString (shardsFile != null) "ln -s ${crystalLib} lib"} - runHook postConfigure - ''; + configurePhase = args.configurePhase or '' + runHook preConfigure - buildInputs = args.buildInputs or [] ++ [ crystal ]; + ${lib.optionalString (lockFile != null) "ln -s ${lockFile} ./shard.lock"} + ${lib.optionalString (shardsFile != null) "ln -s ${crystalLib} lib"} - buildPhase = args.buildPhase or '' - runHook preBuild - ${lib.concatStringsSep "\n" (lib.mapAttrsToList (bin: attrs: '' - crystal ${lib.escapeShellArgs ([ - "build" - "-o" bin - (attrs.src or (throw "No source file for crystal binary ${bin} provided")) - ] ++ attrs.options or defaultOptions)} - '') crystalBinaries)} - runHook postBuild - ''; + runHook postConfigure + ''; - installPhase = args.installPhase or '' - runHook preInstall - mkdir -p "$out/bin" - ${lib.concatMapStringsSep "\n" (bin: '' - mv ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]} - '') (lib.attrNames crystalBinaries)} - runHook postInstall - ''; + CRFLAGS = lib.concatStringsSep " " defaultOptions; - meta = args.meta or {} // { - platforms = args.meta.platforms or crystal.meta.platforms; - }; -}) + buildInputs = args.buildInputs or [] ++ [ crystal shards ]; + + nativeBuildInputs = args.nativeBuildInputs or [] ++ [ git pkgconfig which ]; + + buildPhase = args.buildPhase or ( + '' + runHook preBuild + + if [ -e Makefile ]; then + echo " ** building with make" + + make ''${buildTargets:-build} $buildFlags + else + '' + ( + if buildDirectly then '' + echo " ** building with crystal" + + ${lib.concatStringsSep "\n" ( + lib.mapAttrsToList ( + bin: attrs: '' + crystal ${lib.escapeShellArgs ( + [ + "build" + "-o" + bin + (attrs.src or (throw "No source file for crystal binary ${bin} provided")) + ] ++ attrs.options or defaultOptions + )} + '' + ) crystalBinaries + )} + '' else '' + echo " ** building with shards" + shards build --local --production ${lib.concatStringsSep " " defaultOptions} + '' + ) + '' + fi + + runHook postBuild + '' + ); + + installPhase = args.installPhase or ( + '' + runHook preInstall + + if [ -e Makefile ]; then + make ''${installTargets:-install} $installFlags + else + '' + ( + if buildDirectly then + lib.concatMapStringsSep "\n" ( + bin: '' + install -Dm555 ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]} + '' + ) (lib.attrNames crystalBinaries) + else '' + shards install + '' + ) + '' + fi + + runHook postInstall + '' + ); + + meta = args.meta or {} // { + platforms = args.meta.platforms or crystal.meta.platforms; + }; + } +) From dce6dd3345d700748de9bce948615985fd57575b Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Fri, 17 Apr 2020 18:18:36 +0200 Subject: [PATCH 4/5] Revert "crystal: build using Makefile or shards if available" This reverts commit 2ec0ad59849ee1a652a6534a2d2672fdb7b5fed5. --- .../compilers/crystal/build-package.nix | 136 +++++------------- 1 file changed, 38 insertions(+), 98 deletions(-) diff --git a/pkgs/development/compilers/crystal/build-package.nix b/pkgs/development/compilers/crystal/build-package.nix index 9cf5701d12f..8ffa89a11b4 100644 --- a/pkgs/development/compilers/crystal/build-package.nix +++ b/pkgs/development/compilers/crystal/build-package.nix @@ -1,9 +1,6 @@ -{ stdenv, lib, crystal, shards, git, pkgconfig, which, linkFarm, fetchFromGitHub }: -{ - # Some projects do not include a lock file, so you can pass one - lockFile ? null - # Generate shards.nix with `nix-shell -p crystal2nix --run crystal2nix` in the projects root -, shardsFile ? null +{ stdenv, lib, crystal, linkFarm, fetchFromGitHub }: +{ # Generate shards.nix with `nix-shell -p crystal2nix --run crystal2nix` in the projects root + shardsFile ? null # Specify binaries to build in the form { foo.src = "src/foo.cr"; } # The default `crystal build` options can be overridden with { foo.options = [ "--no-debug" ]; } , crystalBinaries ? {} @@ -12,102 +9,45 @@ let mkDerivationArgs = builtins.removeAttrs args [ "shardsFile" "crystalBinaries" ]; - crystalLib = linkFarm "crystal-lib" ( - lib.mapAttrsToList ( - name: value: { - inherit name; - path = fetchFromGitHub value; - } - ) (import shardsFile) - ); + crystalLib = linkFarm "crystal-lib" (lib.mapAttrsToList (name: value: { + inherit name; + path = fetchFromGitHub value; + }) (import shardsFile)); - # we previously had --no-debug here but that is not recommended by upstream - defaultOptions = [ "--release" "--progress" "--verbose" ]; + defaultOptions = [ "--release" "--progress" "--no-debug" "--verbose" ]; - buildDirectly = shardsFile == null || crystalBinaries != {}; -in -stdenv.mkDerivation ( - mkDerivationArgs // { +in stdenv.mkDerivation (mkDerivationArgs // { - configurePhase = args.configurePhase or '' - runHook preConfigure + configurePhase = args.configurePhase or '' + runHook preConfigure + ${lib.optionalString (shardsFile != null) "ln -s ${crystalLib} lib"} + runHook postConfigure + ''; - ${lib.optionalString (lockFile != null) "ln -s ${lockFile} ./shard.lock"} - ${lib.optionalString (shardsFile != null) "ln -s ${crystalLib} lib"} + buildInputs = args.buildInputs or [] ++ [ crystal ]; - runHook postConfigure - ''; + buildPhase = args.buildPhase or '' + runHook preBuild + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (bin: attrs: '' + crystal ${lib.escapeShellArgs ([ + "build" + "-o" bin + (attrs.src or (throw "No source file for crystal binary ${bin} provided")) + ] ++ attrs.options or defaultOptions)} + '') crystalBinaries)} + runHook postBuild + ''; - CRFLAGS = lib.concatStringsSep " " defaultOptions; + installPhase = args.installPhase or '' + runHook preInstall + mkdir -p "$out/bin" + ${lib.concatMapStringsSep "\n" (bin: '' + mv ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]} + '') (lib.attrNames crystalBinaries)} + runHook postInstall + ''; - buildInputs = args.buildInputs or [] ++ [ crystal shards ]; - - nativeBuildInputs = args.nativeBuildInputs or [] ++ [ git pkgconfig which ]; - - buildPhase = args.buildPhase or ( - '' - runHook preBuild - - if [ -e Makefile ]; then - echo " ** building with make" - - make ''${buildTargets:-build} $buildFlags - else - '' + ( - if buildDirectly then '' - echo " ** building with crystal" - - ${lib.concatStringsSep "\n" ( - lib.mapAttrsToList ( - bin: attrs: '' - crystal ${lib.escapeShellArgs ( - [ - "build" - "-o" - bin - (attrs.src or (throw "No source file for crystal binary ${bin} provided")) - ] ++ attrs.options or defaultOptions - )} - '' - ) crystalBinaries - )} - '' else '' - echo " ** building with shards" - shards build --local --production ${lib.concatStringsSep " " defaultOptions} - '' - ) + '' - fi - - runHook postBuild - '' - ); - - installPhase = args.installPhase or ( - '' - runHook preInstall - - if [ -e Makefile ]; then - make ''${installTargets:-install} $installFlags - else - '' + ( - if buildDirectly then - lib.concatMapStringsSep "\n" ( - bin: '' - install -Dm555 ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]} - '' - ) (lib.attrNames crystalBinaries) - else '' - shards install - '' - ) + '' - fi - - runHook postInstall - '' - ); - - meta = args.meta or {} // { - platforms = args.meta.platforms or crystal.meta.platforms; - }; - } -) + meta = args.meta or {} // { + platforms = args.meta.platforms or crystal.meta.platforms; + }; +}) From 164dfe4b44de535b6674647255de25bfc6a6e8d1 Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Mon, 20 Apr 2020 16:08:26 +0200 Subject: [PATCH 5/5] crystal: fixes for darwin --- pkgs/development/compilers/crystal/default.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/crystal/default.nix b/pkgs/development/compilers/crystal/default.nix index 8f75692d883..a04d48dd0e5 100644 --- a/pkgs/development/compilers/crystal/default.nix +++ b/pkgs/development/compilers/crystal/default.nix @@ -1,5 +1,5 @@ { stdenv, lib, fetchFromGitHub, fetchurl, makeWrapper -, coreutils, git, gmp, nettools, openssl, readline, tzdata, libxml2, libyaml +, coreutils, git, gmp, hostname, openssl, readline, tzdata, libxml2, libyaml , boehmgc, libatomic_ops, pcre, libevent, libiconv, llvm, clang, which, zlib, pkgconfig , callPackage }: @@ -62,9 +62,12 @@ let substituteInPlace src/crystal/system/unix/time.cr \ --replace /usr/share/zoneinfo ${tzdata}/share/zoneinfo - ln -s spec/compiler spec/std + ln -sf spec/compiler spec/std + + # Dirty fix for when no sandboxing is enabled + rm -rf /tmp/crystal + mkdir -p /tmp/crystal - mkdir /tmp/crystal substituteInPlace spec/std/file_spec.cr \ --replace '/bin/ls' '${coreutils}/bin/ls' \ --replace '/usr/share' '/tmp/crystal' \ @@ -81,7 +84,7 @@ let --replace '{% if flag?(:gnu) %}"listen: "{% else %}"bind: "{% end %}' '"bind: "' substituteInPlace spec/std/system_spec.cr \ - --replace '`hostname`' '`${nettools}/bin/hostname`' + --replace '`hostname`' '`${hostname}/bin/hostname`' # See https://github.com/crystal-lang/crystal/pull/8640 substituteInPlace spec/std/http/cookie_spec.cr \