diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-05-12 14:45:39 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-05-12 14:56:01 +0000 |
commit | eb7dadee9c0f903f1152f8dd4165453bfa48ccf4 (patch) | |
tree | a6bd66dcbec895aae167465672af08a1ca70f089 /nixpkgs/pkgs/development/compilers/crystal | |
parent | 3879b925f5dae3a0eb5c98b10c1ac5a0e4d729a3 (diff) | |
parent | 683c68232e91f76386db979c461d8fbe2a018782 (diff) | |
download | nixlib-eb7dadee9c0f903f1152f8dd4165453bfa48ccf4.tar nixlib-eb7dadee9c0f903f1152f8dd4165453bfa48ccf4.tar.gz nixlib-eb7dadee9c0f903f1152f8dd4165453bfa48ccf4.tar.bz2 nixlib-eb7dadee9c0f903f1152f8dd4165453bfa48ccf4.tar.lz nixlib-eb7dadee9c0f903f1152f8dd4165453bfa48ccf4.tar.xz nixlib-eb7dadee9c0f903f1152f8dd4165453bfa48ccf4.tar.zst nixlib-eb7dadee9c0f903f1152f8dd4165453bfa48ccf4.zip |
Merge commit '683c68232e91f76386db979c461d8fbe2a018782'
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/crystal')
3 files changed, 106 insertions, 39 deletions
diff --git a/nixpkgs/pkgs/development/compilers/crystal/build-package.nix b/nixpkgs/pkgs/development/compilers/crystal/build-package.nix index 8ffa89a11b4a..856c6e58bc18 100644 --- a/nixpkgs/pkgs/development/compilers/crystal/build-package.nix +++ b/nixpkgs/pkgs/development/compilers/crystal/build-package.nix @@ -1,53 +1,109 @@ -{ 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, installShellFiles }: + +{ # 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 + # We support different builders. To make things more straight forward, make it + # user selectable instead of trying to autodetect +, format ? "make" +, installManPages ? true # 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 ? {} -, ... -}@args: +, crystalBinaries ? { }, ... }@args: + +assert (builtins.elem format [ "make" "crystal" "shards" ]); + let - mkDerivationArgs = builtins.removeAttrs args [ "shardsFile" "crystalBinaries" ]; + mkDerivationArgs = builtins.removeAttrs args [ + "format" + "installManPages" + "lockFile" + "shardsFile" + "crystalBinaries" + ]; 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" ]; + 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 lib.concatStringsSep "\n" ([ + "runHook preConfigure" + ] ++ lib.optional (lockFile != null) "ln -s ${lockFile} ./shard.lock" + ++ lib.optional (shardsFile != null) "ln -s ${crystalLib} lib" + ++ [ "runHook postConfigure "]); - buildInputs = args.buildInputs or [] ++ [ crystal ]; - - 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; + + PREFIX = placeholder "out"; + + buildInputs = args.buildInputs or [ ] ++ [ crystal ] + ++ lib.optional (format != "crystal") shards; + + nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ git installShellFiles pkgconfig which ]; + + buildPhase = args.buildPhase or (lib.concatStringsSep "\n" ([ + "runHook preBuild" + ] ++ lib.optional (format == "make") + ''make ''${buildTargets:-build} $makeFlags'' + ++ lib.optionals (format == "crystal") (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) + ++ lib.optional (format == "shards") + "shards build --local --production ${lib.concatStringsSep " " defaultOptions}" + ++ [ "runHook postBuild" ])); + + installPhase = args.installPhase or (lib.concatStringsSep "\n" ([ + "runHook preInstall" + ] ++ lib.optional (format == "make") + ''make ''${installTargets:-install} $installFlags'' + ++ lib.optionals (format == "crystal") (map (bin: '' + install -Dm555 ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]} + '') (lib.attrNames crystalBinaries)) + ++ lib.optional (format == "shards") + ''install -Dm555 bin/* -t $out/bin'' + ++ [ + '' + for f in README* *.md LICENSE; do + test -f $f && install -Dm444 $f -t $out/share/doc/${args.pname} + done + '' + ] ++ (lib.optional installManPages '' + if [ -d man ]; then + installManPage man/*.? + fi + '') ++ [ + "runHook postInstall" + ])); + + doCheck = args.doCheck or true; + + checkPhase = args.checkPhase or (lib.concatStringsSep "\n" ([ + "runHook preCheck" + ] ++ lib.optional (format == "make") + ''make ''${checkTarget:-test} $checkFlags'' + ++ lib.optional (format != "make") + ''crystal ''${checkTarget:-spec} $checkFlags'' + ++ [ "runHook postCheck" ])); + + doInstallCheck = args.doInstallCheck or true; - 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 + installCheckPhase = args.installCheckPhase or '' + for f in $out/bin/*; do + $f --help + done ''; - meta = args.meta or {} // { + meta = args.meta or { } // { platforms = args.meta.platforms or crystal.meta.platforms; }; }) diff --git a/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.nix b/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.nix index ac69b9b3d965..5fc40cd23741 100644 --- a/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.nix +++ b/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.nix @@ -1,4 +1,5 @@ { lib, crystal, nix-prefetch-git }: + crystal.buildCrystalPackage { pname = "crystal2nix"; version = "unstable-2018-07-31"; @@ -6,11 +7,16 @@ crystal.buildCrystalPackage { nixPrefetchGit = "${lib.getBin nix-prefetch-git}/bin/nix-prefetch-git"; unpackPhase = "substituteAll ${./crystal2nix.cr} crystal2nix.cr"; + format = "crystal"; + crystalBinaries.crystal2nix.src = "crystal2nix.cr"; + # it will blow up without a shard.yml file + doInstallCheck = false; + meta = with lib; { description = "Utility to convert Crystal's shard.lock files to a Nix file"; license = licenses.mit; - maintainers = [ maintainers.manveru ]; + maintainers = with maintainers; [ manveru ]; }; } diff --git a/nixpkgs/pkgs/development/compilers/crystal/default.nix b/nixpkgs/pkgs/development/compilers/crystal/default.nix index db22b668cf5e..a04d48dd0e5a 100644 --- a/nixpkgs/pkgs/development/compilers/crystal/default.nix +++ b/nixpkgs/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 \ @@ -108,6 +111,8 @@ let "all" "docs" ]; + LLVM_CONFIG = "${llvm}/bin/llvm-config"; + FLAGS = [ "--release" "--single-module" # needed for deterministic builds |