summary refs log tree commit diff
diff options
context:
space:
mode:
authorhappysalada <raphael@megzari.com>2023-05-16 07:34:12 -0400
committerhappysalada <raphael@megzari.com>2023-05-16 07:34:12 -0400
commitd922302771cff731915866d959d6ae64690f28e4 (patch)
treee3efef32373461a5dad7aa92c99cf43bae3685f9
parentf594db6447b0e17fd5a4adec81ada8cf2dc77f45 (diff)
downloadnixpkgs-d922302771cff731915866d959d6ae64690f28e4.tar
nixpkgs-d922302771cff731915866d959d6ae64690f28e4.tar.gz
nixpkgs-d922302771cff731915866d959d6ae64690f28e4.tar.bz2
nixpkgs-d922302771cff731915866d959d6ae64690f28e4.tar.lz
nixpkgs-d922302771cff731915866d959d6ae64690f28e4.tar.xz
nixpkgs-d922302771cff731915866d959d6ae64690f28e4.tar.zst
nixpkgs-d922302771cff731915866d959d6ae64690f28e4.zip
vlang: improve darwin situation
-rw-r--r--pkgs/development/compilers/vlang/default.nix46
1 files changed, 36 insertions, 10 deletions
diff --git a/pkgs/development/compilers/vlang/default.nix b/pkgs/development/compilers/vlang/default.nix
index 81c9f414d8e..c0e6bf1e129 100644
--- a/pkgs/development/compilers/vlang/default.nix
+++ b/pkgs/development/compilers/vlang/default.nix
@@ -2,12 +2,29 @@
 
 let
   version = "weekly.2023.19";
+  ptraceSubstitution = ''
+    #include <sys/types.h>
+    #include <sys/ptrace.h>
+  '';
   # Required for bootstrap.
-  vc = fetchFromGitHub {
-    owner = "vlang";
-    repo = "vc";
-    rev = "f7c2b5f2a0738d0d236161c9de9f31dd0280ac86";
-    sha256 = "sha256-xU3TvyNgc0o4RCsHtoC6cZTNaue2yuAiolEOvP37TKA=";
+  vc = stdenv.mkDerivation {
+    pname = "v.c";
+    version = "unstable-2023-05-14";
+    src = fetchFromGitHub {
+      owner = "vlang";
+      repo = "vc";
+      rev = "f7c2b5f2a0738d0d236161c9de9f31dd0280ac86";
+      sha256 = "sha256-xU3TvyNgc0o4RCsHtoC6cZTNaue2yuAiolEOvP37TKA=";
+    };
+
+    # patch the ptrace reference for darwin
+    installPhase = lib.optionalString stdenv.isDarwin ''
+      substituteInPlace v.c \
+        --replace "#include <sys/ptrace.h>" "${ptraceSubstitution}"
+    '' + ''
+      mkdir -p $out
+      cp v.c $out/
+    '';
   };
   # Required for vdoc.
   markdown = fetchFromGitHub {
@@ -38,11 +55,15 @@ stdenv.mkDerivation {
   ];
 
   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 = "-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";
+  env.VFLAGS = if stdenv.isDarwin then
+    # on darwin we need to add a manual link to libgc since it doesn't have a libgc.a
+    "-cg -cc ${pkgsStatic.clang}/bin/clang -no-retry-compilation -ldflags -L${pkgsStatic.boehmgc}/lib -ldflags -lgc -ldflags -L${binaryen}/lib"
+  else
+    # 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'
+    "-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";
 
   preBuild = ''
     export HOME=$(mktemp -d)
@@ -51,6 +72,11 @@ stdenv.mkDerivation {
     # 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/* ./thirdparty/tcc/lib
+  '' + lib.optionalString stdenv.isDarwin ''
+    # this file isn't used by clang, but it's just to silence a warning
+    # the compiler complains on an empty file, so this makes it "close" to real
+    substituteInPlace vlib/builtin/builtin_d_gcboehm.c.v \
+        --replace "libgc.a" "libgc.la"
   '';
 
   # vcreate_test.v requires git, so we must remove it when building the tools.