|
|
|
@ -1,6 +1,5 @@ |
|
|
|
|
{ stdenv |
|
|
|
|
, tree-sitter |
|
|
|
|
, libcxx |
|
|
|
|
, lib |
|
|
|
|
}: |
|
|
|
|
|
|
|
|
@ -16,42 +15,46 @@ |
|
|
|
|
, location ? null |
|
|
|
|
}: |
|
|
|
|
|
|
|
|
|
stdenv.mkDerivation { |
|
|
|
|
stdenv.mkDerivation rec { |
|
|
|
|
|
|
|
|
|
pname = "${language}-grammar"; |
|
|
|
|
inherit version; |
|
|
|
|
|
|
|
|
|
src = |
|
|
|
|
if location == null |
|
|
|
|
then |
|
|
|
|
source |
|
|
|
|
else |
|
|
|
|
"${source}/${location}" |
|
|
|
|
; |
|
|
|
|
src = if location == null then source else "${source}/${location}"; |
|
|
|
|
|
|
|
|
|
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1"; |
|
|
|
|
buildInputs = [ tree-sitter ]; |
|
|
|
|
|
|
|
|
|
dontUnpack = true; |
|
|
|
|
dontConfigure = true; |
|
|
|
|
|
|
|
|
|
CFLAGS = [ "-I${src}/src" "-O2" ]; |
|
|
|
|
CXXFLAGS = [ "-I${src}/src" "-O2" ]; |
|
|
|
|
|
|
|
|
|
# When both scanner.{c,cc} exist, we should not link both since they may be the same but in |
|
|
|
|
# different languages. Just randomly prefer C++ if that happens. |
|
|
|
|
buildPhase = '' |
|
|
|
|
runHook preBuild |
|
|
|
|
scanner_cc="$src/src/scanner.cc" |
|
|
|
|
if [ ! -f "$scanner_cc" ]; then |
|
|
|
|
scanner_cc="" |
|
|
|
|
fi |
|
|
|
|
scanner_c="$src/src/scanner.c" |
|
|
|
|
if [ ! -f "$scanner_c" ]; then |
|
|
|
|
scanner_c="" |
|
|
|
|
if [[ -e "$src/src/scanner.cc" ]]; then |
|
|
|
|
$CXX -c "$src/src/scanner.cc" -o scanner.o $CXXFLAGS |
|
|
|
|
elif [[ -e "$src/src/scanner.c" ]]; then |
|
|
|
|
$CC -c "$src/src/scanner.c" -o scanner.o $CFLAGS |
|
|
|
|
fi |
|
|
|
|
$CC -I$src/src/ -shared -o parser -Os $src/src/parser.c $scanner_cc $scanner_c -lstdc++ |
|
|
|
|
$CC -c "$src/src/parser.c" -o parser.o $CFLAGS |
|
|
|
|
$CXX -shared -o parser *.o |
|
|
|
|
runHook postBuild |
|
|
|
|
''; |
|
|
|
|
|
|
|
|
|
installPhase = '' |
|
|
|
|
runHook preInstall |
|
|
|
|
mkdir $out |
|
|
|
|
mv parser $out/ |
|
|
|
|
runHook postInstall |
|
|
|
|
''; |
|
|
|
|
|
|
|
|
|
# Auto strip cannot detect files missing extension. |
|
|
|
|
fixupPhase = '' |
|
|
|
|
runHook preFixup |
|
|
|
|
strip -s $out/parser |
|
|
|
|
runHook postFixup |
|
|
|
|
''; |
|
|
|
|
} |
|
|
|
|