Merge pull request #232219 from happysalada/vlang_improve_darwin

vlang: improve darwin situation

authored by

Weijia Wang and committed by
GitHub
1fed4678 a8484588

+36 -10
+36 -10
pkgs/development/compilers/vlang/default.nix
··· 2 2 3 3 let 4 4 version = "weekly.2023.19"; 5 + ptraceSubstitution = '' 6 + #include <sys/types.h> 7 + #include <sys/ptrace.h> 8 + ''; 5 9 # Required for bootstrap. 6 - vc = fetchFromGitHub { 7 - owner = "vlang"; 8 - repo = "vc"; 9 - rev = "f7c2b5f2a0738d0d236161c9de9f31dd0280ac86"; 10 - sha256 = "sha256-xU3TvyNgc0o4RCsHtoC6cZTNaue2yuAiolEOvP37TKA="; 10 + vc = stdenv.mkDerivation { 11 + pname = "v.c"; 12 + version = "unstable-2023-05-14"; 13 + src = fetchFromGitHub { 14 + owner = "vlang"; 15 + repo = "vc"; 16 + rev = "f7c2b5f2a0738d0d236161c9de9f31dd0280ac86"; 17 + sha256 = "sha256-xU3TvyNgc0o4RCsHtoC6cZTNaue2yuAiolEOvP37TKA="; 18 + }; 19 + 20 + # patch the ptrace reference for darwin 21 + installPhase = lib.optionalString stdenv.isDarwin '' 22 + substituteInPlace v.c \ 23 + --replace "#include <sys/ptrace.h>" "${ptraceSubstitution}" 24 + '' + '' 25 + mkdir -p $out 26 + cp v.c $out/ 27 + ''; 11 28 }; 12 29 # Required for vdoc. 13 30 markdown = fetchFromGitHub { ··· 38 55 ]; 39 56 40 57 env.VC = vc; 41 - # libX11.dev and xorg.xorgproto are needed because of 42 - # 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`. 43 - # libXau, libxcb, libXdmcp need to be static if you use static gcc otherwise 44 - # /nix/store/xnk2z26fqy86xahiz3q797dzqx96sidk-glibc-2.37-8/lib/libc.so.6: undefined reference to `_rtld_glob al_ro@GLIBC_PRIVATE' 45 - env.VFLAGS = "-cc ${pkgsStatic.gcc}/bin/gcc -no-retry-compilation -cflags -I${xorg.libX11.dev}/include -cflags -I${xorg.xorgproto}/include -ldflags -L${binaryen}/lib -ldflags -L${pkgsStatic.xorg.libX11}/lib -ldflags -L${pkgsStatic.xorg.libxcb}/lib -ldflags -lxcb -ldflags -L${pkgsStatic.xorg.libXau}/lib -ldflags -lXau -ldflags -L${pkgsStatic.xorg.libXdmcp}/lib -ldflags -lXdmcp"; 58 + env.VFLAGS = if stdenv.isDarwin then 59 + # on darwin we need to add a manual link to libgc since it doesn't have a libgc.a 60 + "-cg -cc ${pkgsStatic.clang}/bin/clang -no-retry-compilation -ldflags -L${pkgsStatic.boehmgc}/lib -ldflags -lgc -ldflags -L${binaryen}/lib" 61 + else 62 + # libX11.dev and xorg.xorgproto are needed because of 63 + # 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`. 64 + # libXau, libxcb, libXdmcp need to be static if you use static gcc otherwise 65 + # /nix/store/xnk2z26fqy86xahiz3q797dzqx96sidk-glibc-2.37-8/lib/libc.so.6: undefined reference to `_rtld_glob al_ro@GLIBC_PRIVATE' 66 + "-cc ${pkgsStatic.gcc}/bin/gcc -no-retry-compilation -cflags -I${xorg.libX11.dev}/include -cflags -I${xorg.xorgproto}/include -ldflags -L${binaryen}/lib -ldflags -L${pkgsStatic.xorg.libX11}/lib -ldflags -L${pkgsStatic.xorg.libxcb}/lib -ldflags -lxcb -ldflags -L${pkgsStatic.xorg.libXau}/lib -ldflags -lXau -ldflags -L${pkgsStatic.xorg.libXdmcp}/lib -ldflags -lXdmcp"; 46 67 47 68 preBuild = '' 48 69 export HOME=$(mktemp -d) ··· 51 72 # we don't use tcc at all since it fails on a missing libatomic 52 73 ln -s ${pkgsStatic.tinycc}/bin/tcc ./thirdparty/tcc/tcc.exe 53 74 cp -r ${pkgsStatic.boehmgc}/lib/* ./thirdparty/tcc/lib 75 + '' + lib.optionalString stdenv.isDarwin '' 76 + # this file isn't used by clang, but it's just to silence a warning 77 + # the compiler complains on an empty file, so this makes it "close" to real 78 + substituteInPlace vlib/builtin/builtin_d_gcboehm.c.v \ 79 + --replace "libgc.a" "libgc.la" 54 80 ''; 55 81 56 82 # vcreate_test.v requires git, so we must remove it when building the tools.