forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
150 lines (128 loc) · 4.29 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# This nix-shell script can be used to get a complete development environment
# for the Crystal compiler.
#
# You can choose which llvm version use and, on Linux, choose to use musl.
#
# $ nix-shell --pure
# $ nix-shell --pure --arg llvm 10
# $ nix-shell --pure --arg llvm 10 --arg musl true
# $ nix-shell --pure --arg llvm 9
# $ nix-shell --pure --arg llvm 9 --argstr system i686-linux
# ...
# $ nix-shell --pure --arg llvm 6
#
# If needed, you can use https://app.cachix.org/cache/crystal-ci to avoid building
# packages that are not available in Nix directly. This is mostly useful for musl.
#
# $ nix-env -iA cachix -f https://cachix.org/api/v1/install
# $ cachix use crystal-ci
# $ nix-shell --pure --arg musl true
#
{llvm ? 11, musl ? false, system ? builtins.currentSystem}:
let
nixpkgs = import (builtins.fetchTarball {
name = "nixpkgs-23.05";
url = "https://github.com/NixOS/nixpkgs/archive/23.05.tar.gz";
sha256 = "10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf";
}) {
inherit system;
};
pkgs = if musl then nixpkgs.pkgsMusl else nixpkgs;
genericBinary = { url, sha256 }:
pkgs.stdenv.mkDerivation rec {
name = "crystal-binary";
src = builtins.fetchTarball { inherit url sha256; };
# Extract only the compiler binary
buildCommand = ''
mkdir -p $out/bin
# Darwin packages use embedded/bin/crystal
[ ! -f "${src}/embedded/bin/crystal" ] || cp ${src}/embedded/bin/crystal $out/bin/
# Linux packages use lib/crystal/bin/crystal
[ ! -f "${src}/lib/crystal/bin/crystal" ] || cp ${src}/lib/crystal/bin/crystal $out/bin/
'';
};
# Hashes obtained using `nix-prefetch-url --unpack <url>`
latestCrystalBinary = genericBinary ({
x86_64-darwin = {
url = "https://github.com/crystal-lang/crystal/releases/download/1.11.2/crystal-1.11.2-1-darwin-universal.tar.gz";
sha256 = "sha256:0qcdr8yl6k7il0x63z2gyqbkjp89m77nq7x1h3m80y1imfg0z1q9";
};
aarch64-darwin = {
url = "https://github.com/crystal-lang/crystal/releases/download/1.11.2/crystal-1.11.2-1-darwin-universal.tar.gz";
sha256 = "sha256:0qcdr8yl6k7il0x63z2gyqbkjp89m77nq7x1h3m80y1imfg0z1q9";
};
x86_64-linux = {
url = "https://github.com/crystal-lang/crystal/releases/download/1.11.2/crystal-1.11.2-1-linux-x86_64.tar.gz";
sha256 = "sha256:01l9cq8d3p7p3ijkrg0xpchj0l21z3sjvd5f6zw1pnms647a6hdr";
};
}.${pkgs.stdenv.system});
pkgconfig = pkgs.pkgconfig;
llvm_suite = ({
llvm_16 = {
llvm = pkgs.llvm_16;
extra = [ pkgs.lld_16 pkgs.lldb_16 ];
};
llvm_15 = {
llvm = pkgs.llvm_15;
extra = [ pkgs.lld_15 pkgs.lldb_15 ];
};
llvm_14 = {
llvm = pkgs.llvm_14;
extra = [ pkgs.lld_14 pkgs.lldb_14 ];
};
llvm_13 = {
llvm = pkgs.llvm_13;
extra = [ pkgs.lld_13 pkgs.lldb_13 ];
};
llvm_12 = {
llvm = pkgs.llvm_12;
extra = [ pkgs.lld_12 pkgs.lldb_12 ];
};
llvm_11 = {
llvm = pkgs.llvm_11;
extra = [ pkgs.lld_11 pkgs.lldb_11 ];
};
llvm_10 = {
llvm = pkgs.llvm_10;
extra = [ pkgs.lld_10 ]; # lldb marked as broken
};
llvm_9 = {
llvm = pkgs.llvm_9;
extra = [ pkgs.lld_9 ]; # lldb marked as broken
};
llvm_8 = {
llvm = pkgs.llvm_8;
extra = [ pkgs.lld_8 ]; # lldb marked as broken
};
}."llvm_${toString llvm}");
boehmgc = pkgs.stdenv.mkDerivation rec {
pname = "boehm-gc";
version = "8.2.4";
src = builtins.fetchTarball {
url = "https://github.com/ivmai/bdwgc/releases/download/v${version}/gc-${version}.tar.gz";
sha256 = "0primpxl7hykfbmszf7ppbv7k1nj41f1r5m56n96q92mmzqlwybm";
};
configureFlags = [
"--disable-debug"
"--disable-dependency-tracking"
"--disable-shared"
"--enable-large-config"
];
enableParallelBuilding = true;
};
stdLibDeps = with pkgs; [
boehmgc gmp libevent libiconv libxml2 libyaml openssl pcre2 zlib
] ++ lib.optionals stdenv.isDarwin [ libiconv ];
tools = [ pkgs.hostname pkgs.git llvm_suite.extra ];
in
pkgs.stdenv.mkDerivation rec {
name = "crystal-dev";
buildInputs = tools ++ stdLibDeps ++ [
latestCrystalBinary
pkgconfig
llvm_suite.llvm
pkgs.libffi
];
LLVM_CONFIG = "${llvm_suite.llvm.dev}/bin/llvm-config";
MACOSX_DEPLOYMENT_TARGET = "10.11";
}