1{ stdenv, fetchFromGitHub, glfw, freetype, openssl, upx ? null }:
2
3assert stdenv.hostPlatform.isUnix -> upx != null;
4
5stdenv.mkDerivation rec {
6 pname = "vlang";
7 version = "0.1.21";
8
9 src = fetchFromGitHub {
10 owner = "vlang";
11 repo = "v";
12 rev = version;
13 sha256 = "0npd7a7nhd6r9mr99naib9scqk30209hz18nxif27284ckjbl4fk";
14 };
15
16 # V compiler source translated to C for bootstrap.
17 # Use matching v.c release commit for now, 0.1.21 release is not available.
18 vc = fetchFromGitHub {
19 owner = "vlang";
20 repo = "vc";
21 rev = "950a90b6acaebad1c6ddec5486fc54307e38a9cd";
22 sha256 = "1dh5l2m207rip1xj677hvbp067inw28n70ddz5wxzfpmaim63c0l";
23 };
24
25 enableParallelBuilding = true;
26 propagatedBuildInputs = [ glfw freetype openssl ]
27 ++ stdenv.lib.optional stdenv.hostPlatform.isUnix upx;
28
29 buildPhase = ''
30 runHook preBuild
31 cc -std=gnu11 $CFLAGS -w -o v $vc/v.c -lm $LDFLAGS
32 ./v -prod -cflags `$CFLAGS` -o v compiler
33 # Exclude thirdparty/vschannel as it is windows-specific.
34 find thirdparty -path thirdparty/vschannel -prune -o -type f -name "*.c" -execdir cc -std=gnu11 $CFLAGS -w -c {} $LDFLAGS ';'
35 runHook postBuild
36 '';
37
38 installPhase = ''
39 runHook preInstall
40 mkdir -p $out/{bin,lib,share}
41 cp -r examples $out/share
42 cp -r {vlib,thirdparty} $out/lib
43 cp v $out/lib
44 ln -s $out/lib/v $out/bin/v
45 runHook postInstall
46 '';
47
48 meta = with stdenv.lib; {
49 homepage = "https://vlang.io/";
50 description = "Simple, fast, safe, compiled language for developing maintainable software";
51 license = licenses.mit;
52 maintainers = with maintainers; [ chiiruno ];
53 platforms = platforms.all;
54 };
55}