Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / pharo / vm / build-vm.nix
blobc1f703f7251563e8409aa93eb995a759c6c9c477
1 { lib, stdenv
2 , fetchurl
3 , bash
4 , unzip
5 , glibc
6 , openssl
7 , libgit2
8 , libGLU, libGL
9 , freetype
10 , xorg
11 , alsaLib
12 , cairo
13 , libuuid
14 , autoreconfHook
15 , gcc48
16 , runtimeShell
17 , ... }:
19 { name, src, version, source-date, source-url, ... }:
21 # Build the Pharo VM
22 stdenv.mkDerivation rec {
23   inherit name src;
25   # Command line invocation name.
26   # Distinct name for 64-bit builds because they only work with 64-bit images.
27   cmd = if stdenv.is64bit then "pharo-spur64" else "pharo-spur";
29   # Choose desired VM sources. Separate for 32-bit and 64-bit VM.
30   # (Could extent to building more VM variants e.g. SpurV3, Sista, etc.)
31   vm = if stdenv.is64bit then "spur64src" else "spursrc";
33   # Choose target platform name in the format used by the vm.
34   flavor =
35     if      stdenv.isLinux && stdenv.isi686    then "linux32x86"
36     else if stdenv.isLinux && stdenv.isx86_64  then "linux64x64"
37     else if stdenv.isDarwin && stdenv.isi686   then "macos32x86"
38     else if stdenv.isDarwin && stdenv.isx86_64 then "macos64x64"
39     else throw "Unsupported platform: only Linux/Darwin x86/x64 are supported.";
41   # Shared data (for the sources file)
42   pharo-share = import ./share.nix { inherit lib stdenv fetchurl unzip; };
44   # Note: -fPIC causes the VM to segfault.
45   hardeningDisable = [ "format" "pic"
46                        # while the VM depends on <= gcc48:
47                        "stackprotector" ];
49   # gcc 4.8 used for the build:
50   #
51   # gcc5 crashes during compilation; gcc >= 4.9 produces a
52   # binary that crashes when forking a child process. See:
53   # http://forum.world.st/OSProcess-fork-issue-with-Debian-built-VM-td4947326.html
54   #
55   # (stack protection is disabled above for gcc 4.8 compatibility.)
56   nativeBuildInputs = [ autoreconfHook unzip ];
57   buildInputs = [
58     bash
59     glibc
60     openssl
61     gcc48
62     libGLU libGL
63     freetype
64     xorg.libX11
65     xorg.libICE
66     xorg.libSM
67     alsaLib
68     cairo
69     pharo-share
70     libuuid
71   ];
73   enableParallelBuilding = true;
75   # Regenerate the configure script.
76   # Unnecessary? But the build breaks without this.
77   autoreconfPhase = ''
78     pushd platforms/unix/config
79     make
80     popd
81   '';
83   # Configure with options modeled on the 'mvm' build script from the vm.
84   configureScript = "platforms/unix/config/configure";
85   configureFlags = [ "--without-npsqueak"
86                      "--with-vmversion=5.0"
87                      "--with-src=${vm}" ];
88   CFLAGS = "-DPharoVM -DIMMUTABILITY=1 -msse2 -D_GNU_SOURCE -DCOGMTVM=0 -g -O2 -DNDEBUG -DDEBUGVM=0";
89   LDFLAGS = "-Wl,-z,now";
91   # VM sources require some patching before build.
92   prePatch = ''
93     patchShebangs build.${flavor}
94     # Fix hard-coded path to /bin/rm in a script
95     sed -i -e 's:/bin/rm:rm:' platforms/unix/config/mkmf
96     # Fill in mandatory metadata about the VM source version
97     sed -i -e 's!\$Date\$!$Date: ${source-date} $!' \
98            -e 's!\$Rev\$!$Rev: ${version} $!' \
99            -e 's!\$URL\$!$URL: ${source-url} $!' \
100            platforms/Cross/vm/sqSCCSVersion.h
101   '';
103   # Note: --with-vmcfg configure option is broken so copy plugin specs to ./
104   preConfigure = ''
105     cp build."${flavor}"/pharo.cog.spur/plugins.{ext,int} .
106   '';
108   # (No special build phase.)
110   installPhase = let
111     libs = [
112       cairo
113       libgit2
114       libGLU libGL
115       freetype
116       openssl
117       libuuid
118       alsaLib
119       xorg.libICE
120       xorg.libSM
121     ];
122   in ''
123     # Install in working directory and then copy
124     make install-squeak install-plugins prefix=$(pwd)/products
126     # Copy binaries & rename from 'squeak' to 'pharo'
127     mkdir -p "$out"
128     cp products/lib/squeak/5.0-*/squeak "$out/pharo"
129     cp -r products/lib/squeak/5.0-*/*.so "$out"
130     ln -s "${pharo-share}/lib/"*.sources "$out"
132     # Create a shell script to run the VM in the proper environment.
133     #
134     # These wrapper puts all relevant libraries into the
135     # LD_LIBRARY_PATH. This is important because various C code in the VM
136     # and Smalltalk code in the image will search for them there.
137     mkdir -p "$out/bin"
139     # Note: include ELF rpath in LD_LIBRARY_PATH for finding libc.
140     libs=$out:$(patchelf --print-rpath "$out/pharo"):${lib.makeLibraryPath libs}
142     # Create the script
143     cat > "$out/bin/${cmd}" <<EOF
144     #!${runtimeShell}
145     set -f
146     LD_LIBRARY_PATH="\$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$libs" exec $out/pharo "\$@"
147     EOF
148     chmod +x "$out/bin/${cmd}"
149     ln -s ${libgit2}/lib/libgit2.so* "$out/"
150   '';
152   meta = with lib; {
153     description = "Clean and innovative Smalltalk-inspired environment";
154     homepage = "https://pharo.org";
155     longDescription = ''
156       Pharo's goal is to deliver a clean, innovative, free open-source
157       Smalltalk-inspired environment. By providing a stable and small core
158       system, excellent dev tools, and maintained releases, Pharo is an
159       attractive platform to build and deploy mission critical applications.
161       This package provides the executable VM. You should probably not care
162       about this package (which represents a packaging detail) and have a
163       look at the pharo-vm-core package instead.
165       Please fill bug reports on http://bugs.pharo.org under the 'Ubuntu
166       packaging (ppa:pharo/stable)' project.
167     '';
168     license = licenses.mit;
169     maintainers = [ maintainers.lukego ];
170     platforms = [ "i686-linux" "x86_64-linux" ];
171   };