1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 fetchurl,
6 alsa-lib,
7 coreutils,
8 file,
9 freetype,
10 gnugrep,
11 libpulseaudio,
12 libtool,
13 libuuid,
14 openssl,
15 pango,
16 pkg-config,
17 xorg,
18}:
19let
20 buildVM =
21 {
22 # VM-specific information, manually extracted from building/<platformDir>/<vmName>/build/mvm
23 platformDir,
24 vmName,
25 scriptName,
26 configureFlagsArray,
27 configureFlags,
28 }:
29 let
30 src = fetchFromGitHub {
31 owner = "OpenSmalltalk";
32 repo = "opensmalltalk-vm";
33 rev = "202206021410";
34 hash = "sha256-QqElPiJuqD5svFjWrLz1zL0Tf+pHxQ2fPvkVRn2lyBI=";
35 };
36 in
37 stdenv.mkDerivation {
38 pname =
39 let
40 vmNameNoDots = builtins.replaceStrings [ "." ] [ "-" ] vmName;
41 in
42 "opensmalltalk-vm-${platformDir}-${vmNameNoDots}";
43 version = src.rev;
44
45 inherit src;
46
47 postPatch = ''
48 vmVersionFiles=$(sed -n 's/^versionfiles="\(.*\)"/\1/p' ./scripts/updateSCCSVersions)
49 for vmVersionFile in $vmVersionFiles; do
50 substituteInPlace "$vmVersionFile" \
51 --replace "\$Date\$" "\$Date: Thu Jan 1 00:00:00 1970 +0000 \$" \
52 --replace "\$URL\$" "\$URL: ${src.url} \$" \
53 --replace "\$Rev\$" "\$Rev: ${src.rev} \$" \
54 --replace "\$CommitHash\$" "\$CommitHash: 000000000000 \$"
55 done
56 patchShebangs --build ./building/${platformDir} scripts
57 substituteInPlace ./platforms/unix/config/mkmf \
58 --replace "/bin/rm" "rm"
59 substituteInPlace ./platforms/unix/config/configure \
60 --replace "/usr/bin/file" "file" \
61 --replace "/usr/bin/pkg-config" "pkg-config" \
62 '';
63
64 preConfigure = ''
65 cd building/${platformDir}/${vmName}/build
66 # Exits with non-zero code if the check fails, counterintuitively
67 ../../../../scripts/checkSCCSversion && exit 1
68 cp ../plugins.int ../plugins.ext .
69 configureFlagsArray=${configureFlagsArray}
70 '';
71
72 configureScript = "../../../../platforms/unix/config/configure";
73
74 configureFlags = [ "--with-scriptname=${scriptName}" ] ++ configureFlags;
75
76 buildFlags = [ "all" ];
77
78 enableParallelBuilding = true;
79
80 nativeBuildInputs = [
81 file
82 pkg-config
83 ];
84
85 buildInputs = [
86 alsa-lib
87 freetype
88 libpulseaudio
89 libtool
90 libuuid
91 openssl
92 pango
93 xorg.libX11
94 xorg.libXrandr
95 ];
96
97 postInstall = ''
98 rm "$out/squeak"
99 cd "$out/bin"
100 BIN="$(find ../lib -type f -name squeak)"
101 for f in $(find . -type f); do
102 rm "$f"
103 ln -s "$BIN" "$f"
104 done
105 '';
106
107 meta = {
108 description = "Cross-platform virtual machine for Squeak, Pharo, Cuis, and Newspeak";
109 mainProgram = scriptName;
110 homepage = "https://opensmalltalk.org/";
111 license = with lib.licenses; [ mit ];
112 maintainers = with lib.maintainers; [ jakewaksbaum ];
113 platforms = [ stdenv.targetPlatform.system ];
114 };
115 };
116
117 vmsByPlatform = {
118 "aarch64-linux" = {
119 "squeak-cog-spur" = buildVM {
120 platformDir = "linux64ARMv8";
121 vmName = "squeak.cog.spur";
122 scriptName = "squeak";
123 configureFlagsArray = ''
124 (
125 CFLAGS="-DNDEBUG -DDEBUGVM=0 -DMUSL -D_GNU_SOURCE -DUSEEVDEV -DCOGMTVM=0 -DDUAL_MAPPED_CODE_ZONE=1"
126 LIBS="-lrt"
127 )
128 '';
129 configureFlags = [
130 "--with-vmversion=5.0"
131 "--with-src=src/spur64.cog"
132 "--without-npsqueak"
133 "--enable-fast-bitblt"
134 ];
135 };
136
137 "squeak-stack-spur" = buildVM {
138 platformDir = "linux64ARMv8";
139 vmName = "squeak.stack.spur";
140 scriptName = "squeak";
141 configureFlagsArray = ''
142 (
143 CFLAGS="-DNDEBUG -DDEBUGVM=0 -DMUSL -D_GNU_SOURCE -DUSEEVDEV -D__ARM_ARCH_ISA_A64 -DARM64 -D__arm__ -D__arm64__ -D__aarch64__"
144 )
145 '';
146 configureFlags = [
147 "--with-vmversion=5.0"
148 "--with-src=src/spur64.stack"
149 "--disable-cogit"
150 "--without-npsqueak"
151 ];
152 };
153 };
154
155 "x86_64-linux" = {
156 "newspeak-cog-spur" = buildVM {
157 platformDir = "linux64x64";
158 vmName = "newspeak.cog.spur";
159 scriptName = "newspeak";
160 configureFlagsArray = ''
161 (
162 CFLAGS="-DNDEBUG -DDEBUGVM=0"
163 )
164 '';
165 configureFlags = [
166 "--with-vmversion=5.0"
167 "--with-src=src/spur64.cog.newspeak"
168 "--without-vm-display-fbdev"
169 "--without-npsqueak"
170 ];
171 };
172
173 "squeak-cog-spur" = buildVM {
174 platformDir = "linux64x64";
175 vmName = "squeak.cog.spur";
176 scriptName = "squeak";
177 configureFlagsArray = ''
178 (
179 CFLAGS="-DNDEBUG -DDEBUGVM=0 -DCOGMTVM=0"
180 )
181 '';
182 configureFlags = [
183 "--with-vmversion=5.0"
184 "--with-src=src/spur64.cog"
185 "--without-npsqueak"
186 ];
187 };
188 };
189 };
190
191 platform = stdenv.targetPlatform.system;
192in
193vmsByPlatform.${platform} or (throw (
194 "Unsupported platform ${platform}: only the following platforms are supported: "
195 + builtins.toString (builtins.attrNames vmsByPlatform)
196))