···1+{ stdenv, fetchurl, bash, unzip, glibc, openssl, gcc, mesa, freetype, xorg, alsaLib, cairo, libuuid, autoreconfHook, gcc48, ... }:
23+{ name, src, version, source-date, source-url, ... }:
45+# Build the Pharo VM
6stdenv.mkDerivation rec {
7+ inherit name src;
89+ # Command line invocation name.
10+ # Distinct name for 64-bit builds because they only work with 64-bit images.
11+ cmd = if stdenv.is64bit then "pharo-spur64" else "pharo-spur";
12+13+ # Choose desired VM sources. Separate for 32-bit and 64-bit VM.
14+ # (Could extent to building more VM variants e.g. SpurV3, Sista, etc.)
15+ vm = if stdenv.is64bit then "spur64src" else "spursrc";
16+17+ # Choose target platform name in the format used by the vm.
18+ flavor =
19+ if stdenv.isLinux && stdenv.isi686 then "linux32x86"
20+ else if stdenv.isLinux && stdenv.isx86_64 then "linux64x64"
21+ else if stdenv.isDarwin && stdenv.isi686 then "macos32x86"
22+ else if stdenv.isDarwin && stdenv.isx86_64 then "macos64x64"
23+ else abort "Unsupported platform: only Linux/Darwin x86/x64 are supported.";
2425+ # Shared data (for the sources file)
26 pharo-share = import ./share.nix { inherit stdenv fetchurl unzip; };
2728+ # Note: -fPIC causes the VM to segfault.
29+ hardeningDisable = [ "format" "pic"
30+ # while the VM depends on <= gcc48:
31+ "stackprotector" ];
000000003233+ # Regenerate the configure script.
34+ # Unnecessary? But the build breaks without this.
35+ autoreconfPhase = ''
36+ pushd platforms/unix/config
37+ make
38+ popd
39 '';
0004041+ # Configure with options modeled on the 'mvm' build script from the vm.
42+ configureScript = "platforms/unix/config/configure";
43+ configureFlags = [ "--without-npsqueak"
44+ "--with-vmversion=5.0"
45+ "--with-src=${vm}" ];
46+ CFLAGS = "-DPharoVM -DIMMUTABILITY=1 -msse2 -D_GNU_SOURCE -DCOGMTVM=0 -g -O2 -DNDEBUG -DDEBUGVM=0";
47+ LDFLAGS = "-Wl,-z,now";
4849+ # VM sources require some patching before build.
50+ prePatch = ''
51+ patchShebangs build.${flavor}
52+ # Fix hard-coded path to /bin/rm in a script
53+ sed -i -e 's:/bin/rm:rm:' platforms/unix/config/mkmf
54+ # Fill in mandatory metadata about the VM source version
55+ sed -i -e 's!\$Date\$!$Date: ${source-date} $!' \
56+ -e 's!\$Rev\$!$Rev: ${version} $!' \
57+ -e 's!\$URL\$!$URL: ${source-url} $!' \
58+ platforms/Cross/vm/sqSCCSVersion.h
59+ '';
6061+ # Note: --with-vmcfg configure option is broken so copy plugin specs to ./
62+ preConfigure = ''
63+ cp build."${flavor}"/pharo.cog.spur/plugins.{ext,int} .
64+ '';
6566+ # (No special build phase.)
6768+ installPhase = ''
69+ # Install in working directory and then copy
70+ make install-squeak install-plugins prefix=$(pwd)/products
7172+ # Copy binaries & rename from 'squeak' to 'pharo'
73+ mkdir -p "$out"
74+ cp products/lib/squeak/5.0-*/squeak "$out/pharo"
75+ cp -r products/lib/squeak/5.0-*/*.so "$out"
76+ ln -s "${pharo-share}/lib/"*.sources "$out"
7778+ # Create a shell script to run the VM in the proper environment.
79+ #
80+ # These wrapper puts all relevant libraries into the
81+ # LD_LIBRARY_PATH. This is important because various C code in the VM
82+ # and Smalltalk code in the image will search for them there.
83+ mkdir -p "$out/bin"
8485+ # Note: include ELF rpath in LD_LIBRARY_PATH for finding libc.
86+ libs=$out:$(patchelf --print-rpath "$out/pharo"):${cairo}/lib:${mesa}/lib:${freetype}/lib:${openssl}/lib:${libuuid}/lib:${alsaLib}/lib:${xorg.libICE}/lib:${xorg.libSM}/lib
8788+ # Create the script
89+ cat > "$out/bin/${cmd}" <<EOF
90+ #!/bin/sh
91 set -f
92+ LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:$libs" exec $out/pharo "\$@"
093 EOF
94+ chmod +x "$out/bin/${cmd}"
00095 '';
9697+ enableParallelBuilding = true;
98+99+ # gcc 4.8 used for the build:
100+ #
101+ # gcc5 crashes during compilation; gcc >= 4.9 produces a
102+ # binary that crashes when forking a child process. See:
103+ # http://forum.world.st/OSProcess-fork-issue-with-Debian-built-VM-td4947326.html
104+ #
105+ # (stack protection is disabled above for gcc 4.8 compatibility.)
106+ buildInputs = [ bash unzip glibc openssl gcc48 mesa freetype xorg.libX11 xorg.libICE xorg.libSM alsaLib cairo pharo-share libuuid autoreconfHook ];
107108 meta = {
109 description = "Clean and innovative Smalltalk-inspired environment";
···122 '';
123 homepage = http://pharo.org;
124 license = stdenv.lib.licenses.mit;
125+ maintainers = [ stdenv.lib.maintainers.lukego ];
126 # Pharo VM sources are packaged separately for darwin (macOS)
127 platforms = with stdenv.lib;
128 intersectLists
···1+{ cmake, stdenv, fetchurl, bash, unzip, glibc, openssl, gcc, mesa, freetype, xorg, alsaLib, cairo, libuuid, autoreconfHook, gcc48, fetchFromGitHub, makeWrapper} @args:
2+3+let
4+ pharo-vm-build = import ./build-vm.nix args;
5+ pharo-vm-build-legacy = import ./build-vm-legacy.nix args;
6+in
7+8+let suffix = if stdenv.is64bit then "64" else "32"; in
9+10+rec {
11+ # Build the latest VM
12+ spur = pharo-vm-build rec {
13+ name = "pharo-spur${suffix}";
14+ version = "git.${revision}";
15+ src = fetchFromGitHub {
16+ owner = "pharo-project";
17+ repo = "pharo-vm";
18+ rev = revision;
19+ sha256 = "0dkiy5fq1xn2n93cwf767xz24c01ic0wfw94jk9nvn7pmcfj7m62";
20+ };
21+ # This metadata will be compiled into the VM and introspectable
22+ # from Smalltalk. This has been manually extracted from 'git log'.
23+ #
24+ # The build would usually generate this automatically using
25+ # opensmalltalk-vm/.git_filters/RevDateURL.smudge but that script
26+ # is too impure to run from nix.
27+ revision = "6a63f68a3dd4deb7c17dd2c7ac6e4dd4b0b6d937";
28+ source-date = "Tue May 30 19:41:27 2017 -0700";
29+ source-url = "https://github.com/pharo-project/pharo-vm";
30+ };
31+32+ # Build an old ("legacy") CogV3 VM for running pre-spur images.
33+ # (Could be nicer to build the latest VM in CogV3 mode but this is
34+ # not supported on the Pharo VM variant at the moment.)
35+ cog = pharo-vm-build-legacy rec {
36+ version = "2016.02.18";
37+ name = "pharo-cog${suffix}";
38+ base-url = http://files.pharo.org/vm/src/vm-unix-sources/blessed;
39+ src = fetchurl {
40+ url = "${base-url}/pharo-vm-${version}.tar.bz2";
41+ sha256 = "16n2zg7v2s1ml0vvpbhkw6khmgn637sr0d7n2b28qm5yc8pfhcj4";
42+ };
43+ };
44+45+}
46+
···1+#!/bin/sh
2+# This is based on the script by David T. Lewis posted here:
3+# http://lists.squeakfoundation.org/pipermail/vm-dev/2017-April/024836.html
4+#
5+# VM run utility script
6+# usage: run <myimage>
7+#
8+# Select a VM and run an image based on the image format number
9+10+PATH=$PATH:@file@/bin
11+12+# Search for the image filename in the command line arguments
13+for arg in $* $SQUEAK_IMAGE; do
14+ case ${arg} in
15+ -*) # ignore
16+ ;;
17+ *) # either an option argument or the image name
18+ if test -e ${arg}; then
19+ magic=$(file -L -b -m @magic@ "$arg")
20+ case "$magic" in
21+ "Smalltalk image V3 32b"*)
22+ image=${arg}
23+ vm=@cog32@/bin/pharo-cog
24+ ;;
25+ "Smalltalk image Spur 32b"*)
26+ image=${arg}
27+ vm=@spur32@/bin/pharo-spur
28+ ;;
29+ "Smalltalk image Spur 64b"*)
30+ if [ "@spur64vm@" == "none" ]; then
31+ echo "error: detected 64-bit image but 64-bit VM is not available" >&2
32+ exit 1
33+ fi
34+ image=${arg}
35+ vm=@spur64@/bin/pharo-spur64
36+ ;;
37+ esac
38+ fi
39+ ;;
40+ esac
41+done
42+43+# Print a message to explain our DWIM'ery.
44+if [ -n "$image" ]; then
45+ echo "using VM selected by image type."
46+ echo " image: $image"
47+ echo " type: $magic"
48+ echo " vm: $vm"
49+else
50+ echo "using default vm; image type not detected"
51+ vm=@cog32@/bin/pharo-cog
52+fi
53+54+# Run the VM
55+set -f
56+exec -- "${vm}" "$@"
57+