@@ -1,8 +1,9 @@
11{ stdenv, fetchurl, boehmgc, libatomic_ops, pcre, libevent, libiconv, llvm_4, makeWrapper }:
22
33stdenv.mkDerivation rec {
4− version = "0.23.0";
5− name = "crystal-${version}-1";
4+ version = "0.23.1";
5+ patch = "3";
6+ name = "crystal-${version}-${patch}";
67 arch =
78 {
89 "x86_64-linux" = "linux-x86_64";
@@ -11,18 +12,18 @@ stdenv.mkDerivation rec {
1112 }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
1213
1314 prebuiltBinary = fetchurl {
14− url = "https://github.com/crystal-lang/crystal/releases/download/${version}/crystal-${version}-1-${arch}.tar.gz";
15+ url = "https://github.com/crystal-lang/crystal/releases/download/${version}/crystal-${version}-${patch}-${arch}.tar.gz";
1516 sha256 =
1617 {
17− "x86_64-linux" = "0nhs7swbll8hrk15kmmywngkhij80x62axiskb1gjmiwvzhlh0qx";
18− "i686-linux" = "03xp8d3lqflzzm26lpdn4yavj87qzgd6xyrqxp2pn9ybwrq8fx8a";
19− "x86_64-darwin" = "1prz6c1gs8z7dgpdy2id2mjn1c8f5p2bf9b39985bav448njbyjz";
18+ "x86_64-linux" = "6a84cc866838ffa5250e28c3ce1a918a93f89c06393fe8cfd4068fcbbc66f3ab";
19+ "i686-linux" = "268a39b8d37385ff60d113d4d9fc966472160faa1e3bbf7ae58860ab6678aceb";
20+ "x86_64-darwin" = "d3f964ebfc5cd48fad73ab2484ea2a00268812276293dd0f7e9c7d184c8aad8a";
2021 }."${stdenv.system}" or (throw "system ${stdenv.system} not supported");
2122 };
2223
2324 src = fetchurl {
2425 url = "https://github.com/crystal-lang/crystal/archive/${version}.tar.gz";
25− sha256 = "05ymwmjkl1b4m888p725kybpiap5ag2vj8l07d59j02inm5r0rcv";
26+ sha256 = "8cf1b9a4eab29fca2f779ea186ae18f7ce444ce189c621925fa1a0c61dd5ff55";
2627 };
2728
2829 # crystal on Darwin needs libiconv to build
@@ -46,27 +47,43 @@ stdenv.mkDerivation rec {
4647 sourceRoot = ".";
4748
4849 fixPrebuiltBinary = if stdenv.isDarwin then ''
49− wrapProgram $(pwd)/crystal-${version}-1/embedded/bin/crystal \
50+ wrapProgram $(pwd)/crystal-${version}-${patch}/embedded/bin/crystal \
5051 --suffix DYLD_LIBRARY_PATH : $libPath
5152 ''
5253 else ''
5354 patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
54− crystal-${version}-1/embedded/bin/crystal
55+ crystal-${version}-${patch}/embedded/bin/crystal
5556 patchelf --set-rpath ${ stdenv.lib.makeLibraryPath [ stdenv.cc.cc ] } \
56− crystal-${version}-1/embedded/bin/crystal
57+ crystal-${version}-${patch}/embedded/bin/crystal
5758 '';
5859
60+ newline = "\n";
61+
5962 buildPhase = ''
6063 # patch the script which launches the prebuilt compiler
61− substituteInPlace $(pwd)/crystal-${version}-1/bin/crystal --replace \
62− "/usr/bin/env bash" "${stdenv.shell}"
63− substituteInPlace $(pwd)/crystal-${version}/bin/crystal --replace \
64− "/usr/bin/env bash" "${stdenv.shell}"
65−
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)"
6676 ${fixPrebuiltBinary}
6777
6878 cd crystal-${version}
69− make release=1 PATH="../crystal-${version}-1/bin:$PATH"
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
7087 make doc
7188 '';
7289
@@ -75,7 +92,6 @@ stdenv.mkDerivation rec {
7592 wrapProgram $out/bin/crystal \
7693 --suffix CRYSTAL_PATH : $out/lib/crystal \
7794 --suffix LIBRARY_PATH : $libPath
78−
7995 install -dm755 $out/lib/crystal
8096 cp -r src/* $out/lib/crystal/
8197
@@ -97,8 +113,7 @@ stdenv.mkDerivation rec {
97113 description = "A compiled language with Ruby like syntax and type inference";
98114 homepage = https://crystal-lang.org/;
99115 license = stdenv.lib.licenses.asl20;
100− maintainers = with stdenv.lib.maintainers; [ sifmelcara ];
116+ maintainers = with stdenv.lib.maintainers; [ sifmelcara david50407 ];
101117 platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
102118 };
103119}
104−