vlang: fix build on darwin

This commit is contained in:
Weijia Wang 2023-05-16 19:44:49 +03:00
parent 1fed46780d
commit b1c83f9f01
2 changed files with 23 additions and 16 deletions

View file

@ -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 let
version = "weekly.2023.19"; version = "weekly.2023.19";
@ -33,6 +33,9 @@ let
rev = "6e970bd0a7459ad7798588f1ace4aa46c5e789a2"; rev = "6e970bd0a7459ad7798588f1ace4aa46c5e789a2";
hash = "sha256-hFf7c8ZNMU1j7fgmDakuO7tBVr12Wq0dgQddJnkMajE="; hash = "sha256-hFf7c8ZNMU1j7fgmDakuO7tBVr12Wq0dgQddJnkMajE=";
}; };
boehmgcStatic = pkgsStatic.boehmgc.override {
enableStatic = stdenv.isDarwin;
};
in in
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "vlang"; pname = "vlang";
@ -50,14 +53,16 @@ stdenv.mkDerivation {
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
buildInputs = lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Cocoa;
makeFlags = [ makeFlags = [
"local=1" "local=1"
]; ];
env.VC = vc; env.VC = vc;
env.VFLAGS = if stdenv.isDarwin then 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 # on darwin we need to add a manual link to libgc
"-cg -cc ${pkgsStatic.clang}/bin/clang -no-retry-compilation -ldflags -L${pkgsStatic.boehmgc}/lib -ldflags -lgc -ldflags -L${binaryen}/lib" "-cc ${stdenv.cc}/bin/cc -no-retry-compilation -ldflags -L${boehmgcStatic}/lib -ldflags -lgc -ldflags -L${binaryen}/lib"
else else
# libX11.dev and xorg.xorgproto are needed because of # 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`. # 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`.
@ -68,23 +73,25 @@ stdenv.mkDerivation {
preBuild = '' preBuild = ''
export HOME=$(mktemp -d) export HOME=$(mktemp -d)
mkdir -p ./thirdparty/tcc/lib mkdir -p ./thirdparty/tcc/lib
# this step is not needed it's just to silence a warning cp -r ${boehmgcStatic}/lib/* ./thirdparty/tcc/lib
# we don't use tcc at all since it fails on a missing libatomic ''
# 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 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. # 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 = '' preInstall = ''
mv cmd/tools/vcreate/vcreate_test.v $HOME/vcreate_test.v 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 <Cocoa/Cocoa.h>, 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 = '' installPhase = ''
@ -110,8 +117,6 @@ stdenv.mkDerivation {
# Return vcreate_test.v and vtest.v, so the user can use it. # Return vcreate_test.v and vtest.v, so the user can use it.
postInstall = '' postInstall = ''
cp $HOME/vcreate_test.v $out/lib/cmd/tools/vcreate_test.v 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; { meta = with lib; {

View file

@ -4,6 +4,7 @@
# doc: https://github.com/ivmai/bdwgc/blob/v8.2.2/doc/README.macros (LARGE_CONFIG) # doc: https://github.com/ivmai/bdwgc/blob/v8.2.2/doc/README.macros (LARGE_CONFIG)
, enableLargeConfig ? false , enableLargeConfig ? false
, enableMmap ? true , enableMmap ? true
, enableStatic ? false
, nixVersions , nixVersions
}: }:
@ -26,6 +27,7 @@ stdenv.mkDerivation (finalAttrs: {
"--enable-cplusplus" "--enable-cplusplus"
"--with-libatomic-ops=none" "--with-libatomic-ops=none"
] ]
++ lib.optional enableStatic "--enable-static"
++ lib.optional enableMmap "--enable-mmap" ++ lib.optional enableMmap "--enable-mmap"
++ lib.optional enableLargeConfig "--enable-large-config"; ++ lib.optional enableLargeConfig "--enable-large-config";