forked from replit/prybar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-prybar.nix
81 lines (61 loc) · 2.54 KB
/
build-prybar.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{ language, buildInputs ? [ ], binaries ? [ ], setFlags ? false
, pkgName ? language }:
{ lib, buildGoModule, fetchFromGitHub, bash, expect, pkg-config, runCommand, git
, python3, copyPathToStore, rev, makeWrapper }:
buildGoModule {
pname = "prybar-${language}";
version = rev;
src = ./.;
inherit buildInputs;
nativeBuildInputs = [ pkg-config makeWrapper ];
subPackages = [ "languages/${language}" ];
vendorSha256 = "1nrycpyjmmhs8cl6bmrajfwczxsv8z20y7a9k7js8p7z60fz7pya";
# This prebiuild hook will setup the compiler flags on demand based on the package
# If a language requires this, it MUST expost a ${pkgName}.pc file in its `lib/pkg-config`
# for pkg-config to detect it. Otherwise, we can't find the required flags.
preBuild = ''
export CGO_LDFLAGS_ALLOW="-Wl,--compress-debug-sections=zlib"
${if setFlags then ''
export NIX_CFLAGS_COMPILE="$(pkg-config --cflags ${pkgName}) $NIX_CFLAGS_COMPILE"
export NIX_LDFLAGS="$(pkg-config --libs-only-L ${pkgName}) $(pkg-config --libs-only-l ${pkgName}) $NIX_LDFLAGS"
'' else
""}
${bash}/bin/bash ./scripts/inject.sh ${language}
go generate ./languages/${language}/main.go
if [[ -f "languages/${language}/compile" ]]; then
patchShebangs languages/${language}/compile
languages/${language}/compile;
fi
'';
# The test file expect the binary to be in the current directory rather than bin
preCheck = ''
cp $GOPATH/bin/${language} ./prybar-${language}
'';
# Add all the dependencies to the check. Binaries should include the language interpreter/binaries
# for testing the language.
checkInputs = [ expect ] ++ buildInputs ++ binaries;
# Run the end-to-end tests for this specific language
checkPhase = ''
runHook preCheck
# Nix unsets HOME but some tests rely on it, let's set it to whatever tmp dir the check
# is running in.
export HOME=$(echo pwd)
# Currently the go tests won't work in nix because of something w/ nix's sandboxing.
DISABLE_GO_TESTS=1 "${bash}/bin/bash" "./run_tests_language" "${language}"
runHook postCheck
'';
# Delete the test binary we copied in the preCheck
postCheck = ''
rm -f ./prybar-${language}
'';
postInstall = ''
mv $out/bin/${language} $out/bin/prybar-${language}
if [ -d "./prybar_assets/${language}" ]
then
mkdir -p "$out/prybar_assets/${language}"
cp -R "./prybar_assets/${language}" "$out/prybar_assets/"
wrapProgram "$out/bin/prybar-${language}" \
--set PRYBAR_ASSETS_DIR "$out/prybar_assets"
fi
'';
}