2023-05-15 18:57:17 +00:00
{ lib , stdenv , fetchFromGitHub , glfw , freetype , openssl , makeWrapper , upx , pkgsStatic , xorg , binaryen }:
2019-07-29 18:36:27 +00:00
2023-05-15 18:57:17 +00:00
let
version = " w e e k l y . 2 0 2 3 . 1 9 " ;
2022-05-14 23:59:38 +00:00
# Required for bootstrap.
2019-07-29 18:36:27 +00:00
vc = fetchFromGitHub {
owner = " v l a n g " ;
repo = " v c " ;
2023-05-15 18:57:17 +00:00
rev = " f 7 c 2 b 5 f 2 a 0 7 3 8 d 0 d 2 3 6 1 6 1 c 9 d e 9 f 3 1 d d 0 2 8 0 a c 8 6 " ;
sha256 = " s h a 2 5 6 - x U 3 T v y N g c 0 o 4 R C s H t o C 6 c Z T N a u e 2 y u A i o l E O v P 3 7 T K A = " ;
2019-07-29 18:36:27 +00:00
} ;
2022-05-14 23:59:38 +00:00
# Required for vdoc.
markdown = fetchFromGitHub {
owner = " v l a n g " ;
repo = " m a r k d o w n " ;
2023-05-15 18:57:17 +00:00
rev = " 6 e 9 7 0 b d 0 a 7 4 5 9 a d 7 7 9 8 5 8 8 f 1 a c e 4 a a 4 6 c 5 e 7 8 9 a 2 " ;
hash = " s h a 2 5 6 - h F f 7 c 8 Z N M U 1 j 7 f g m D a k u O 7 t B V r 1 2 W q 0 d g Q d d J n k M a j E = " ;
} ;
in
stdenv . mkDerivation {
pname = " v l a n g " ;
inherit version ;
src = fetchFromGitHub {
owner = " v l a n g " ;
repo = " v " ;
rev = version ;
sha256 = " s h a 2 5 6 - f H n 1 z 2 q 3 L m S y c C O a 1 i i 4 D o H v b E W 4 u J t 3 P s q 3 / V u Z N V Q = " ;
2022-05-14 23:59:38 +00:00
} ;
2019-10-07 04:02:34 +00:00
propagatedBuildInputs = [ glfw freetype openssl ]
2021-01-22 11:25:31 +00:00
++ lib . optional stdenv . hostPlatform . isUnix upx ;
2019-07-29 18:36:27 +00:00
2021-08-12 09:55:21 +00:00
nativeBuildInputs = [ makeWrapper ] ;
makeFlags = [
" l o c a l = 1 "
] ;
2019-07-29 18:36:27 +00:00
2023-05-15 18:57:17 +00:00
env . VC = vc ;
# libX11.dev and xorg.xorgproto are needed because of
# builder error: Header file <X11/Xlib.h>, needed for module `clipboard.x11` was not found. Please install a package with the X11 development headers, for example: `apt-get install libx11-dev`.
# libXau, libxcb, libXdmcp need to be static if you use static gcc otherwise
# /nix/store/xnk2z26fqy86xahiz3q797dzqx96sidk-glibc-2.37-8/lib/libc.so.6: undefined reference to `_rtld_glob al_ro@GLIBC_PRIVATE'
env . VFLAGS = " - c c ${ pkgsStatic . gcc } / b i n / g c c - n o - r e t r y - c o m p i l a t i o n - c f l a g s - I ${ xorg . libX11 . dev } / i n c l u d e - c f l a g s - I ${ xorg . xorgproto } / i n c l u d e - l d f l a g s - L ${ binaryen } / l i b - l d f l a g s - L ${ pkgsStatic . xorg . libX11 } / l i b - l d f l a g s - L ${ pkgsStatic . xorg . libxcb } / l i b - l d f l a g s - l x c b - l d f l a g s - L ${ pkgsStatic . xorg . libXau } / l i b - l d f l a g s - l X a u - l d f l a g s - L ${ pkgsStatic . xorg . libXdmcp } / l i b - l d f l a g s - l X d m c p " ;
2022-05-17 11:23:29 +00:00
preBuild = ''
2022-05-14 23:59:38 +00:00
export HOME = $ ( mktemp - d )
2023-05-15 18:57:17 +00:00
mkdir - p ./thirdparty/tcc/lib
# this step is not needed it's just to silence a warning
# we don't use tcc at all since it fails on a missing libatomic
ln - s $ { pkgsStatic . tinycc } /bin/tcc ./thirdparty/tcc/tcc.exe
cp - r $ { pkgsStatic . boehmgc } /lib /* . / t h i r d p a r t y / t c c / l i b
2022-05-17 11:23:29 +00:00
'' ;
# vcreate_test.v requires git, so we must remove it when building the tools.
# vtest.v fails on Darwin, so let's just disable it for now.
preInstall = ''
2023-05-15 18:57:17 +00:00
mv cmd/tools/vcreate/vcreate_test.v $ HOME/vcreate_test.v
2022-05-17 11:23:29 +00:00
'' + l i b . o p t i o n a l S t r i n g s t d e n v . i s D a r w i n ''
mv cmd/tools/vtest.v $ HOME/vtest.v
2022-05-14 23:59:38 +00:00
'' ;
2019-07-29 18:36:27 +00:00
installPhase = ''
runHook preInstall
2022-05-14 23:59:38 +00:00
2019-10-03 20:47:40 +00:00
mkdir - p $ out / { bin , lib , share }
cp - r examples $ out/share
2021-06-26 13:02:25 +00:00
cp - r { cmd , vlib , thirdparty } $ out/lib
2022-05-14 23:59:38 +00:00
cp v $ out/lib
2019-10-03 20:47:40 +00:00
ln - s $ out/lib/v $ out/bin/v
2021-08-12 09:55:21 +00:00
wrapProgram $ out/bin/v - - prefix PATH : $ { lib . makeBinPath [ stdenv . cc ] }
2022-05-14 23:59:38 +00:00
mkdir - p $ HOME/.vmodules ;
ln - sf $ { markdown } $ HOME/.vmodules/markdown
$ out/lib/v - v build-tools
$ out/lib/v - v $ out/lib/cmd/tools/vdoc
$ out/lib/v - v $ out/lib/cmd/tools/vast
$ out/lib/v - v $ out/lib/cmd/tools/vvet
2019-07-29 18:36:27 +00:00
runHook postInstall
'' ;
2022-05-17 11:23:29 +00:00
# Return vcreate_test.v and vtest.v, so the user can use it.
postInstall = ''
cp $ HOME/vcreate_test.v $ out/lib/cmd/tools/vcreate_test.v
'' + l i b . o p t i o n a l S t r i n g s t d e n v . i s D a r w i n ''
cp $ HOME/vtest.v $ out/lib/cmd/tools/vtest.v
'' ;
2021-01-22 11:25:31 +00:00
meta = with lib ; {
2019-07-29 18:36:27 +00:00
homepage = " h t t p s : / / v l a n g . i o / " ;
description = " S i m p l e , f a s t , s a f e , c o m p i l e d l a n g u a g e f o r d e v e l o p i n g m a i n t a i n a b l e s o f t w a r e " ;
license = licenses . mit ;
2022-04-17 23:13:36 +00:00
maintainers = with maintainers ; [ Madouura ] ;
2022-05-05 00:46:39 +00:00
mainProgram = " v " ;
2019-07-29 18:36:27 +00:00
platforms = platforms . all ;
} ;
}