208 lines
6.9 KiB
Nix
208 lines
6.9 KiB
Nix
{
|
|
description = "tricu";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
packageName = "tricu";
|
|
containerPackageName = "${packageName}-container";
|
|
|
|
haskellPackages = pkgs.haskellPackages;
|
|
hsLib = pkgs.haskell.lib;
|
|
|
|
tricuStatic = hsLib.justStaticExecutables self.packages.${system}.default;
|
|
|
|
tricuPackageTests =
|
|
haskellPackages.callCabal2nix packageName self {};
|
|
|
|
tricuPackage =
|
|
hsLib.dontCheck (
|
|
haskellPackages.callCabal2nix packageName self {}
|
|
);
|
|
|
|
customGHC = haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
|
|
megaparsec
|
|
]);
|
|
|
|
# ------------------------------------------------------------------
|
|
# Zig Arboricx host
|
|
# ------------------------------------------------------------------
|
|
tricuZig = pkgs.stdenv.mkDerivation {
|
|
pname = "tricu-zig";
|
|
version = "0.1.0";
|
|
src = ./ext/zig;
|
|
nativeBuildInputs = [ pkgs.zig ];
|
|
buildPhase = ''
|
|
export ZIG_GLOBAL_CACHE_DIR=$TMPDIR/zig-cache
|
|
zig build
|
|
'';
|
|
installPhase = ''
|
|
mkdir -p $out/bin $out/lib $out/include
|
|
cp zig-out/bin/* $out/bin/ 2>/dev/null || true
|
|
cp zig-out/lib/* $out/lib/ 2>/dev/null || true
|
|
cp include/arboricx.h $out/include/
|
|
'';
|
|
};
|
|
|
|
tricuZigTests = pkgs.stdenv.mkDerivation {
|
|
pname = "tricu-zig-tests";
|
|
version = "0.1.0";
|
|
src = ./.;
|
|
nativeBuildInputs = [ pkgs.gcc pkgs.python3 tricuZig ];
|
|
buildPhase = "true";
|
|
doCheck = true;
|
|
checkPhase = ''
|
|
export LD_LIBRARY_PATH=${tricuZig}/lib:$LD_LIBRARY_PATH
|
|
ulimit -s 32768
|
|
|
|
cd ext/zig
|
|
|
|
# C ABI smoke test
|
|
gcc -o /tmp/c_abi_test tests/c_abi_test.c \
|
|
-I ${tricuZig}/include -L ${tricuZig}/lib -larboricx \
|
|
-Wl,-rpath,${tricuZig}/lib
|
|
/tmp/c_abi_test
|
|
|
|
# Kernel path append test
|
|
gcc -o /tmp/c_abi_append_test tests/c_abi_append_test.c \
|
|
-I ${tricuZig}/include -L ${tricuZig}/lib -larboricx \
|
|
-Wl,-rpath,${tricuZig}/lib
|
|
/tmp/c_abi_append_test
|
|
|
|
# Native bundle tests
|
|
gcc -o /tmp/native_bundle_append_test tests/native_bundle_append_test.c \
|
|
-I ${tricuZig}/include -L ${tricuZig}/lib -larboricx \
|
|
-Wl,-rpath,${tricuZig}/lib
|
|
/tmp/native_bundle_append_test
|
|
|
|
gcc -o /tmp/native_bundle_id_test tests/native_bundle_id_test.c \
|
|
-I ${tricuZig}/include -L ${tricuZig}/lib -larboricx \
|
|
-Wl,-rpath,${tricuZig}/lib
|
|
/tmp/native_bundle_id_test
|
|
|
|
gcc -o /tmp/native_bundle_bools_test tests/native_bundle_bools_test.c \
|
|
-I ${tricuZig}/include -L ${tricuZig}/lib -larboricx \
|
|
-Wl,-rpath,${tricuZig}/lib
|
|
/tmp/native_bundle_bools_test
|
|
|
|
# Python FFI test
|
|
ARBORICX_LIB=${tricuZig}/lib/libarboricx.so \
|
|
python3 tests/python_ffi_test.py
|
|
|
|
mkdir -p $out
|
|
echo "All Zig tests passed" > $out/result
|
|
'';
|
|
};
|
|
|
|
# ------------------------------------------------------------------
|
|
# PHP FFI host
|
|
# ------------------------------------------------------------------
|
|
tricuPhp = pkgs.stdenv.mkDerivation {
|
|
pname = "tricu-php";
|
|
version = "0.1.0";
|
|
src = ./ext/php;
|
|
nativeBuildInputs = [ pkgs.makeWrapper phpWithFfi tricuZig ];
|
|
buildPhase = "true";
|
|
installPhase = ''
|
|
mkdir -p $out/share/tricu-php $out/lib $out/bin
|
|
cp -r src public run.php $out/share/tricu-php/
|
|
cp ${tricuZig}/lib/libarboricx.so $out/lib/
|
|
cp ${tricuZig}/include/arboricx.h $out/share/tricu-php/
|
|
|
|
makeWrapper ${phpWithFfi}/bin/php $out/bin/tricu-php \
|
|
--add-flags "$out/share/tricu-php/run.php" \
|
|
--set ARBORICX_LIB "$out/lib/libarboricx.so" \
|
|
--prefix LD_LIBRARY_PATH : "$out/lib"
|
|
'';
|
|
};
|
|
|
|
# ------------------------------------------------------------------
|
|
# PHP FFI tests (separate target)
|
|
# ------------------------------------------------------------------
|
|
phpWithFfi = pkgs.php.withExtensions (exts: [ pkgs.phpExtensions.ffi ]);
|
|
|
|
tricuPhpTests = pkgs.stdenv.mkDerivation {
|
|
pname = "tricu-php-tests";
|
|
version = "0.1.0";
|
|
src = ./.;
|
|
nativeBuildInputs = [ phpWithFfi tricuPhp ];
|
|
buildPhase = "true";
|
|
doCheck = true;
|
|
checkPhase = ''
|
|
export ARBORICX_LIB=${tricuPhp}/lib/libarboricx.so
|
|
export LD_LIBRARY_PATH=${tricuPhp}/lib:$LD_LIBRARY_PATH
|
|
ulimit -s 32768
|
|
|
|
# Run PHP host against fixture bundles
|
|
php ext/php/run.php run test/fixtures/id.arboricx hello
|
|
php ext/php/run.php run test/fixtures/append.arboricx "Hello, " "world!"
|
|
php ext/php/run.php run test/fixtures/true.arboricx
|
|
php ext/php/run.php run test/fixtures/false.arboricx
|
|
php ext/php/run.php run test/fixtures/notQ.arboricx "t t t"
|
|
|
|
mkdir -p $out
|
|
echo "All PHP tests passed" > $out/result
|
|
'';
|
|
};
|
|
in {
|
|
packages.${packageName} = tricuPackage;
|
|
packages.default = tricuPackage;
|
|
packages.tricu-zig = tricuZig;
|
|
packages.tricu-zig-tests = tricuZigTests;
|
|
packages.tricu-php = tricuPhp;
|
|
packages.tricu-php-tests = tricuPhpTests;
|
|
|
|
checks.${packageName} = tricuPackageTests;
|
|
checks.default = tricuPackageTests;
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
buildInputs = with pkgs; [
|
|
haskellPackages.cabal-install
|
|
haskellPackages.ghc-events
|
|
haskellPackages.ghcid
|
|
customGHC
|
|
upx
|
|
gcc
|
|
python3
|
|
];
|
|
|
|
inputsFrom = [
|
|
tricuPackage
|
|
tricuZig
|
|
tricuPhp
|
|
];
|
|
};
|
|
|
|
packages.${containerPackageName} = pkgs.dockerTools.buildImage {
|
|
name = "tricu";
|
|
|
|
copyToRoot = pkgs.buildEnv {
|
|
name = "image-root";
|
|
paths = [ tricuStatic ];
|
|
pathsToLink = [ "/bin" ];
|
|
};
|
|
tag = "latest";
|
|
config = {
|
|
Cmd = [
|
|
"/bin/tricu"
|
|
"server"
|
|
"-h" "0.0.0.0"
|
|
"-p" "8787"
|
|
];
|
|
WorkingDir = "/app";
|
|
ExposedPorts = {
|
|
"8787/tcp" = {};
|
|
};
|
|
extraCommands = ''
|
|
'';
|
|
};
|
|
};
|
|
});
|
|
}
|