@@ -1,92 +1,66 @@
1−{ stdenv, fetchurl, boehmgc, libatomic_ops, pcre, libevent, libiconv, llvm_4, makeWrapper }:
1+{ stdenv, fetchurl, boehmgc, libatomic_ops, pcre, libevent, libiconv, llvm, makeWrapper }:
22
33stdenv.mkDerivation rec {
4+ name = "crystal-${version}";
45 version = "0.23.1";
5− patch = "3";
6− name = "crystal-${version}-${patch}";
7− arch =
8− {
9− "x86_64-linux" = "linux-x86_64";
10− "i686-linux" = "linux-i686";
11− "x86_64-darwin" = "darwin-x86_64";
12− }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
13−
14− prebuiltBinary = fetchurl {
15− url = "https://github.com/crystal-lang/crystal/releases/download/${version}/crystal-${version}-${patch}-${arch}.tar.gz";
16− sha256 =
17− {
18− "x86_64-linux" = "6a84cc866838ffa5250e28c3ce1a918a93f89c06393fe8cfd4068fcbbc66f3ab";
19− "i686-linux" = "268a39b8d37385ff60d113d4d9fc966472160faa1e3bbf7ae58860ab6678aceb";
20− "x86_64-darwin" = "d3f964ebfc5cd48fad73ab2484ea2a00268812276293dd0f7e9c7d184c8aad8a";
21− }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
22− };
236
247 src = fetchurl {
258 url = "https://github.com/crystal-lang/crystal/archive/${version}.tar.gz";
269 sha256 = "8cf1b9a4eab29fca2f779ea186ae18f7ce444ce189c621925fa1a0c61dd5ff55";
2710 };
2811
12+ prebuiltName = "crystal-0.23.0-1";
13+ prebuiltSrc = let arch = {
14+ "x86_64-linux" = "linux-x86_64";
15+ "i686-linux" = "linux-i686";
16+ "x86_64-darwin" = "darwin-x86_64";
17+ }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
18+ in fetchurl {
19+ url = "https://github.com/crystal-lang/crystal/releases/download/0.23.0/${prebuiltName}-${arch}.tar.gz";
20+ sha256 = {
21+ "x86_64-linux" = "0nhs7swbll8hrk15kmmywngkhij80x62axiskb1gjmiwvzhlh0qx";
22+ "i686-linux" = "03xp8d3lqflzzm26lpdn4yavj87qzgd6xyrqxp2pn9ybwrq8fx8a";
23+ "x86_64-darwin" = "1prz6c1gs8z7dgpdy2id2mjn1c8f5p2bf9b39985bav448njbyjz";
24+ }."${stdenv.system}";
25+ };
26+
27+ srcs = [ src prebuiltSrc ];
28+
2929 # crystal on Darwin needs libiconv to build
30− buildInputs = [
31− boehmgc libatomic_ops pcre libevent llvm_4 makeWrapper
30+ libs = [
31+ boehmgc libatomic_ops pcre libevent
3232 ] ++ stdenv.lib.optionals stdenv.isDarwin [
3333 libiconv
3434 ];
3535
36− libPath = stdenv.lib.makeLibraryPath ([
37− boehmgc libatomic_ops pcre libevent
38− ] ++ stdenv.lib.optionals stdenv.isDarwin [
39− libiconv
40− ]);
36+ nativeBuildInputs = [ makeWrapper ];
4137
42− unpackPhase = ''
43− tar zxf ${src}
44− tar zxf ${prebuiltBinary}
45− '';
38+ buildInputs = libs ++ [ llvm ];
4639
47− sourceRoot = ".";
40+ libPath = stdenv.lib.makeLibraryPath libs;
41+
42+ sourceRoot = "${name}";
4843
4944 fixPrebuiltBinary = if stdenv.isDarwin then ''
50− wrapProgram $(pwd)/crystal-${version}-${patch}/embedded/bin/crystal \
45+ wrapProgram ../${prebuiltName}/embedded/bin/crystal \
5146 --suffix DYLD_LIBRARY_PATH : $libPath
5247 ''
5348 else ''
5449 patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
55− crystal-${version}-${patch}/embedded/bin/crystal
50+ ../${prebuiltName}/embedded/bin/crystal
5651 patchelf --set-rpath ${ stdenv.lib.makeLibraryPath [ stdenv.cc.cc ] } \
57− crystal-${version}-${patch}/embedded/bin/crystal
52+ ../${prebuiltName}/embedded/bin/crystal
5853 '';
5954
60− newline = "\n";
61−
62− buildPhase = ''
63− # patch the script which launches the prebuilt compiler
64− patchShebangs $(pwd)/crystal-${version}-${patch}/bin/crystal
65− patchShebangs $(pwd)/crystal-${version}/bin/crystal
66− # Due to https://github.com/crystal-lang/crystal/issues/4719,
67− # when building Crystal with LLVM 4 with debug infos from prebuilt binary (w/ LLVM 3.8) will always be failed.
68− # So we are going to build a LLVM 4 version without debug info,
69− # and use it to build Crystal with debug info on LLVM 4.
70− substituteInPlace $(pwd)/crystal-${version}/Makefile --replace \
71− "release ?=" "no_debug ?= ##${newline}force_rebuild ?= ##${newline}release ?="
72− substituteInPlace $(pwd)/crystal-${version}/Makefile --replace \
73− "FLAGS := " "FLAGS := \$(if \$(no_debug),--no-debug )"
74− substituteInPlace $(pwd)/crystal-${version}/Makefile --replace \
75− "$(O)/crystal:" "\$(O)/crystal: \$(if \$(force_rebuild),../rebuild.tmp)"
55+ preBuild = ''
56+ patchShebangs bin/crystal
57+ patchShebangs ../${prebuiltName}/bin/crystal
7658 ${fixPrebuiltBinary}
77−
78− cd crystal-${version}
79− # Build without debug infos on LLVM 4
80− make release=1 no_debug=1 PATH="../crystal-${version}-${patch}/bin:$PATH"
81−
82− # Rebuild Crystal with debug infos from the binary we just built
83− touch $(pwd)/../rebuild.tmp
84− wrapProgram .build/crystal \
85− --suffix LIBRARY_PATH : $libPath
86− make release=1 force_rebuild=1
87− make doc
59+ export PATH="$(pwd)/../${prebuiltName}/bin:$PATH"
8860 '';
8961
62+ makeFlags = [ "CRYSTAL_CONFIG_VERSION=${version}" "release=1" "all" "doc" ];
63+
9064 installPhase = ''
9165 install -Dm755 .build/crystal $out/bin/crystal
9266 wrapProgram $out/bin/crystal \
@@ -109,6 +83,8 @@ stdenv.mkDerivation rec {
10983
11084 dontStrip = true;
11185
86+ enableParallelBuilding = true;
87+
11288 meta = {
11389 description = "A compiled language with Ruby like syntax and type inference";
11490 homepage = https://crystal-lang.org/;