Commit d9223027 authored by happysalada's avatar happysalada
Browse files

vlang: improve darwin situation

parent f594db64
Loading
Loading
Loading
Loading
+36 −10
Original line number Diff line number Diff line
@@ -2,13 +2,30 @@

let
  version = "weekly.2023.19";
  ptraceSubstitution = ''
    #include <sys/types.h>
    #include <sys/ptrace.h>
  '';
  # Required for bootstrap.
  vc = fetchFromGitHub {
  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 {
    owner = "vlang";
@@ -38,11 +55,15 @@ stdenv.mkDerivation {
  ];

  env.VC = vc;
  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'
  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";
    "-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.