From b1c83f9f0110e704e2bd7abf11dab911b639726b Mon Sep 17 00:00:00 2001 From: Weijia Wang <9713184+wegank@users.noreply.github.com> Date: Tue, 16 May 2023 19:44:49 +0300 Subject: [PATCH 1/3] vlang: fix build on darwin --- pkgs/development/compilers/vlang/default.nix | 37 +++++++++++-------- .../libraries/boehm-gc/default.nix | 2 + 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pkgs/development/compilers/vlang/default.nix b/pkgs/development/compilers/vlang/default.nix index c0e6bf1e129..431cfe789f1 100644 --- a/pkgs/development/compilers/vlang/default.nix +++ b/pkgs/development/compilers/vlang/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, glfw, freetype, openssl, makeWrapper, upx, pkgsStatic, xorg, binaryen }: +{ lib, stdenv, fetchFromGitHub, glfw, freetype, openssl, makeWrapper, upx, pkgsStatic, xorg, binaryen, darwin }: let version = "weekly.2023.19"; @@ -33,6 +33,9 @@ let rev = "6e970bd0a7459ad7798588f1ace4aa46c5e789a2"; hash = "sha256-hFf7c8ZNMU1j7fgmDakuO7tBVr12Wq0dgQddJnkMajE="; }; + boehmgcStatic = pkgsStatic.boehmgc.override { + enableStatic = stdenv.isDarwin; + }; in stdenv.mkDerivation { pname = "vlang"; @@ -50,14 +53,16 @@ stdenv.mkDerivation { nativeBuildInputs = [ makeWrapper ]; + buildInputs = lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Cocoa; + makeFlags = [ "local=1" ]; 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" + # on darwin we need to add a manual link to libgc + "-cc ${stdenv.cc}/bin/cc -no-retry-compilation -ldflags -L${boehmgcStatic}/lib -ldflags -lgc -ldflags -L${binaryen}/lib" else # libX11.dev and xorg.xorgproto are needed because of # builder error: Header file , needed for module `clipboard.x11` was not found. Please install a package with the X11 development headers, for example: `apt-get install libx11-dev`. @@ -68,23 +73,25 @@ stdenv.mkDerivation { preBuild = '' export HOME=$(mktemp -d) 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 + cp -r ${boehmgcStatic}/lib/* ./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 + + lib.optionalString stdenv.isLinux '' 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. - # vtest.v fails on Darwin, so let's just disable it for now. preInstall = '' mv cmd/tools/vcreate/vcreate_test.v $HOME/vcreate_test.v - '' + lib.optionalString stdenv.isDarwin '' - mv cmd/tools/vtest.v $HOME/vtest.v + '' + # builder error: Header file , needed for module `clipboard` was not found. + + lib.optionalString stdenv.isDarwin '' + for flag in $NIX_CFLAGS_COMPILE; do + if [[ $flag == /*/Library/Frameworks ]]; then + VFLAGS+=" -ldflags -F$flag" + fi + done ''; installPhase = '' @@ -110,8 +117,6 @@ stdenv.mkDerivation { # 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 - '' + lib.optionalString stdenv.isDarwin '' - cp $HOME/vtest.v $out/lib/cmd/tools/vtest.v ''; meta = with lib; { diff --git a/pkgs/development/libraries/boehm-gc/default.nix b/pkgs/development/libraries/boehm-gc/default.nix index de5aff6c3b6..e37eb26deb3 100644 --- a/pkgs/development/libraries/boehm-gc/default.nix +++ b/pkgs/development/libraries/boehm-gc/default.nix @@ -4,6 +4,7 @@ # doc: https://github.com/ivmai/bdwgc/blob/v8.2.2/doc/README.macros (LARGE_CONFIG) , enableLargeConfig ? false , enableMmap ? true +, enableStatic ? false , nixVersions }: @@ -26,6 +27,7 @@ stdenv.mkDerivation (finalAttrs: { "--enable-cplusplus" "--with-libatomic-ops=none" ] + ++ lib.optional enableStatic "--enable-static" ++ lib.optional enableMmap "--enable-mmap" ++ lib.optional enableLargeConfig "--enable-large-config"; From fedc294f603016efdcfe80d5cfad51aa70b6ea2c Mon Sep 17 00:00:00 2001 From: Weijia Wang <9713184+wegank@users.noreply.github.com> Date: Tue, 16 May 2023 19:53:18 +0300 Subject: [PATCH 2/3] vlang: eliminate pkgsStatic --- pkgs/development/compilers/vlang/default.nix | 37 +++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/pkgs/development/compilers/vlang/default.nix b/pkgs/development/compilers/vlang/default.nix index 431cfe789f1..865980d7866 100644 --- a/pkgs/development/compilers/vlang/default.nix +++ b/pkgs/development/compilers/vlang/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, glfw, freetype, openssl, makeWrapper, upx, pkgsStatic, xorg, binaryen, darwin }: +{ lib, stdenv, fetchFromGitHub, glfw, freetype, openssl, makeWrapper, upx, boehmgc, xorg, binaryen, darwin }: let version = "weekly.2023.19"; @@ -33,8 +33,8 @@ let rev = "6e970bd0a7459ad7798588f1ace4aa46c5e789a2"; hash = "sha256-hFf7c8ZNMU1j7fgmDakuO7tBVr12Wq0dgQddJnkMajE="; }; - boehmgcStatic = pkgsStatic.boehmgc.override { - enableStatic = stdenv.isDarwin; + boehmgcStatic = boehmgc.override { + enableStatic = true; }; in stdenv.mkDerivation { @@ -60,25 +60,28 @@ stdenv.mkDerivation { ]; env.VC = vc; - env.VFLAGS = if stdenv.isDarwin then - # on darwin we need to add a manual link to libgc - "-cc ${stdenv.cc}/bin/cc -no-retry-compilation -ldflags -L${boehmgcStatic}/lib -ldflags -lgc -ldflags -L${binaryen}/lib" - else - # libX11.dev and xorg.xorgproto are needed because of - # builder error: Header file , 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"; + env.VFLAGS = toString ([ + "-cc ${stdenv.cc}/bin/cc" + "-no-retry-compilation" + "-ldflags -L${binaryen}/lib" + ] + # builder error: Header file , needed for module `clipboard.x11` was not found. + ++ lib.optionals stdenv.isLinux [ + "-cflags -I${xorg.libX11.dev}/include" + "-cflags -I${xorg.xorgproto}/include" + "-ldflags -L${xorg.libX11}/lib" + "-ldflags -L${xorg.libxcb}/lib" + "-ldflags -lxcb" + "-ldflags -L${xorg.libXau}/lib" + "-ldflags -lXau" + "-ldflags -L${xorg.libXdmcp}/lib" + "-ldflags -lXdmcp" + ]); preBuild = '' export HOME=$(mktemp -d) mkdir -p ./thirdparty/tcc/lib cp -r ${boehmgcStatic}/lib/* ./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 - + lib.optionalString stdenv.isLinux '' - ln -s ${pkgsStatic.tinycc}/bin/tcc ./thirdparty/tcc/tcc.exe ''; # vcreate_test.v requires git, so we must remove it when building the tools. From e8408498f79c71d6bc25d2b430ca015cc4bbec30 Mon Sep 17 00:00:00 2001 From: Weijia Wang <9713184+wegank@users.noreply.github.com> Date: Tue, 16 May 2023 23:20:58 +0300 Subject: [PATCH 3/3] vlang: eliminate env.VFLAGS --- pkgs/development/compilers/vlang/default.nix | 36 ++++++-------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/pkgs/development/compilers/vlang/default.nix b/pkgs/development/compilers/vlang/default.nix index 865980d7866..bfc90c76fe0 100644 --- a/pkgs/development/compilers/vlang/default.nix +++ b/pkgs/development/compilers/vlang/default.nix @@ -53,30 +53,22 @@ stdenv.mkDerivation { nativeBuildInputs = [ makeWrapper ]; - buildInputs = lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Cocoa; + buildInputs = [ + binaryen + ] ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Cocoa + ] ++ lib.optionals stdenv.isLinux [ + xorg.libX11 + xorg.libXau + xorg.libXdmcp + xorg.xorgproto + ]; makeFlags = [ "local=1" ]; env.VC = vc; - env.VFLAGS = toString ([ - "-cc ${stdenv.cc}/bin/cc" - "-no-retry-compilation" - "-ldflags -L${binaryen}/lib" - ] - # builder error: Header file , needed for module `clipboard.x11` was not found. - ++ lib.optionals stdenv.isLinux [ - "-cflags -I${xorg.libX11.dev}/include" - "-cflags -I${xorg.xorgproto}/include" - "-ldflags -L${xorg.libX11}/lib" - "-ldflags -L${xorg.libxcb}/lib" - "-ldflags -lxcb" - "-ldflags -L${xorg.libXau}/lib" - "-ldflags -lXau" - "-ldflags -L${xorg.libXdmcp}/lib" - "-ldflags -lXdmcp" - ]); preBuild = '' export HOME=$(mktemp -d) @@ -87,14 +79,6 @@ stdenv.mkDerivation { # vcreate_test.v requires git, so we must remove it when building the tools. preInstall = '' mv cmd/tools/vcreate/vcreate_test.v $HOME/vcreate_test.v - '' - # builder error: Header file , needed for module `clipboard` was not found. - + lib.optionalString stdenv.isDarwin '' - for flag in $NIX_CFLAGS_COMPILE; do - if [[ $flag == /*/Library/Frameworks ]]; then - VFLAGS+=" -ldflags -F$flag" - fi - done ''; installPhase = ''