1{ lib, stdenv, fetchFromGitHub, glfw, freetype, openssl, makeWrapper, upx }:
2
3stdenv.mkDerivation rec {
4 pname = "vlang";
5 version = "weekly.2022.20";
6
7 src = fetchFromGitHub {
8 owner = "vlang";
9 repo = "v";
10 rev = version;
11 sha256 = "1isbyfs98bdbm2qjf7q4bqbpsmdiqlavn3gznwr12bkvhnsf4j3x";
12 };
13
14 # Required for bootstrap.
15 vc = fetchFromGitHub {
16 owner = "vlang";
17 repo = "vc";
18 rev = "167f262866090493650f58832d62d910999dd5a4";
19 sha256 = "1xax8355qkrccjcmx24gcab88xnrqj15mhqy0bgp3v2rb1hw1n3a";
20 };
21
22 # Required for vdoc.
23 markdown = fetchFromGitHub {
24 owner = "vlang";
25 repo = "markdown";
26 rev = "bbbd324a361e404ce0682fc00666df3a7877b398";
27 sha256 = "0cawzizr3rjz81blpvxvxrcvcdai1adj66885ss390444qq1fnv7";
28 };
29
30 propagatedBuildInputs = [ glfw freetype openssl ]
31 ++ lib.optional stdenv.hostPlatform.isUnix upx;
32
33 nativeBuildInputs = [ makeWrapper ];
34
35 makeFlags = [
36 "local=1"
37 "VC=${vc}"
38 ];
39
40 preBuild = ''
41 export HOME=$(mktemp -d)
42 '';
43
44 # vcreate_test.v requires git, so we must remove it when building the tools.
45 # vtest.v fails on Darwin, so let's just disable it for now.
46 preInstall = ''
47 mv cmd/tools/vcreate_test.v $HOME/vcreate_test.v
48 '' + lib.optionalString stdenv.isDarwin ''
49 mv cmd/tools/vtest.v $HOME/vtest.v
50 '';
51
52 installPhase = ''
53 runHook preInstall
54
55 mkdir -p $out/{bin,lib,share}
56 cp -r examples $out/share
57 cp -r {cmd,vlib,thirdparty} $out/lib
58 cp v $out/lib
59 ln -s $out/lib/v $out/bin/v
60 wrapProgram $out/bin/v --prefix PATH : ${lib.makeBinPath [ stdenv.cc ]}
61
62 mkdir -p $HOME/.vmodules;
63 ln -sf ${markdown} $HOME/.vmodules/markdown
64 $out/lib/v -v build-tools
65 $out/lib/v -v $out/lib/cmd/tools/vdoc
66 $out/lib/v -v $out/lib/cmd/tools/vast
67 $out/lib/v -v $out/lib/cmd/tools/vvet
68
69 runHook postInstall
70 '';
71
72 # Return vcreate_test.v and vtest.v, so the user can use it.
73 postInstall = ''
74 cp $HOME/vcreate_test.v $out/lib/cmd/tools/vcreate_test.v
75 '' + lib.optionalString stdenv.isDarwin ''
76 cp $HOME/vtest.v $out/lib/cmd/tools/vtest.v
77 '';
78
79 meta = with lib; {
80 homepage = "https://vlang.io/";
81 description = "Simple, fast, safe, compiled language for developing maintainable software";
82 license = licenses.mit;
83 maintainers = with maintainers; [ Madouura ];
84 mainProgram = "v";
85 platforms = platforms.all;
86 };
87}