wip
This commit is contained in:
164
flake.nix
Normal file
164
flake.nix
Normal file
@@ -0,0 +1,164 @@
|
||||
{
|
||||
description = "Java FFM bindings for libghostty-vt";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
ghostty = {
|
||||
url = "github:ghostty-org/ghostty";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, ghostty }:
|
||||
let
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs systems;
|
||||
in
|
||||
{
|
||||
packages = forAllSystems (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
jdk =
|
||||
if pkgs ? jdk25_headless then pkgs.jdk25_headless
|
||||
else if pkgs ? jdk25 then pkgs.jdk25
|
||||
else if pkgs ? jdk24_headless then pkgs.jdk24_headless
|
||||
else if pkgs ? jdk24 then pkgs.jdk24
|
||||
else pkgs.jdk;
|
||||
|
||||
version = "0.1.0-SNAPSHOT";
|
||||
groupPath = "dev/jlibghostty";
|
||||
artifactId = "jlibghostty";
|
||||
ghosttyVt = ghostty.packages.${system}.libghostty-vt;
|
||||
|
||||
platformName =
|
||||
if system == "x86_64-linux" then "linux-x86_64"
|
||||
else if system == "aarch64-linux" then "linux-aarch64"
|
||||
else if system == "x86_64-darwin" then "macos-x86_64"
|
||||
else if system == "aarch64-darwin" then "macos-aarch64"
|
||||
else throw "unsupported system: ${system}";
|
||||
|
||||
bundledLibraryName =
|
||||
if pkgs.stdenv.hostPlatform.isDarwin then "libghostty-vt.dylib"
|
||||
else "libghostty-vt.so";
|
||||
|
||||
sharedLibraryPattern =
|
||||
if pkgs.stdenv.hostPlatform.isDarwin then "libghostty-vt*.dylib"
|
||||
else "libghostty-vt.so*";
|
||||
|
||||
package = pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = artifactId;
|
||||
inherit version;
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = [ jdk ];
|
||||
|
||||
dontConfigure = true;
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
mkdir -p build/classes build/test-classes build/resources/${groupPath}/native/${platformName}
|
||||
|
||||
ghostty_lib="$(find ${ghosttyVt} -type f -name '${sharedLibraryPattern}' -print -quit)"
|
||||
if [ -z "$ghostty_lib" ]; then
|
||||
echo "Could not find ${sharedLibraryPattern} in ${ghosttyVt}" >&2
|
||||
find ${ghosttyVt} -maxdepth 4 -type f >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bundled_lib="build/resources/${groupPath}/native/${platformName}/${bundledLibraryName}"
|
||||
cp "$ghostty_lib" "$bundled_lib"
|
||||
|
||||
find src/main/java -name '*.java' | sort > build/sources.txt
|
||||
javac --release 22 -d build/classes @build/sources.txt
|
||||
|
||||
jar --create \
|
||||
--file build/${artifactId}-${version}.jar \
|
||||
-C build/classes . \
|
||||
-C build/resources .
|
||||
|
||||
jar --create \
|
||||
--file build/${artifactId}-${version}-sources.jar \
|
||||
-C src/main/java .
|
||||
|
||||
find src/test/java -name '*.java' | sort > build/test-sources.txt
|
||||
if [ -s build/test-sources.txt ]; then
|
||||
javac --release 22 -cp build/classes -d build/test-classes @build/test-sources.txt
|
||||
java \
|
||||
--enable-native-access=ALL-UNNAMED \
|
||||
-Djlibghostty.library.path="$bundled_lib" \
|
||||
-cp build/classes:build/test-classes \
|
||||
dev.jlibghostty.GhosttySmokeTest
|
||||
fi
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p "$out/share/java" "$out/maven/${groupPath}/${artifactId}/${version}"
|
||||
|
||||
cp build/${artifactId}-${version}.jar "$out/share/java/"
|
||||
cp build/${artifactId}-${version}.jar "$out/maven/${groupPath}/${artifactId}/${version}/"
|
||||
cp build/${artifactId}-${version}-sources.jar "$out/maven/${groupPath}/${artifactId}/${version}/"
|
||||
|
||||
cat > "$out/maven/${groupPath}/${artifactId}/${version}/${artifactId}-${version}.pom" <<'POM'
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>dev.jlibghostty</groupId>
|
||||
<artifactId>jlibghostty</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>jlibghostty</name>
|
||||
<description>Java FFM bindings for libghostty-vt</description>
|
||||
</project>
|
||||
POM
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Java FFM bindings for libghostty-vt";
|
||||
platforms = systems;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
default = package;
|
||||
jlibghostty = package;
|
||||
mavenRepository = package;
|
||||
});
|
||||
|
||||
devShells = forAllSystems (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
jdk =
|
||||
if pkgs ? jdk25_headless then pkgs.jdk25_headless
|
||||
else if pkgs ? jdk25 then pkgs.jdk25
|
||||
else if pkgs ? jdk24_headless then pkgs.jdk24_headless
|
||||
else if pkgs ? jdk24 then pkgs.jdk24
|
||||
else pkgs.jdk;
|
||||
ghosttyVt = ghostty.packages.${system}.libghostty-vt;
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
packages =
|
||||
[ jdk pkgs.gradle ]
|
||||
++ pkgs.lib.optional (pkgs ? jextract) pkgs.jextract;
|
||||
|
||||
JLIBGHOSTTY_LIBRARY =
|
||||
if pkgs.stdenv.hostPlatform.isDarwin
|
||||
then "${ghosttyVt}/lib/libghostty-vt.dylib"
|
||||
else "${ghosttyVt}/lib/libghostty-vt.so";
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user