diff options
| author | seth <[email protected]> | 2024-08-26 23:51:17 -0400 |
|---|---|---|
| committer | Seth Flynn <[email protected]> | 2025-03-05 04:36:03 -0500 |
| commit | b229a37e59b9720b7017e72a6d159b869ff36458 (patch) | |
| tree | 829090d2236ac707d5670c496781a4a888a0b700 | |
[skip ci] initial commit
| -rw-r--r-- | .github/dependabot.yml | 12 | ||||
| -rw-r--r-- | .github/workflows/ci.yaml | 38 | ||||
| -rw-r--r-- | .gitignore | 83 | ||||
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | default.nix | 63 | ||||
| -rw-r--r-- | pkgs/fetch-ant-deps.nix | 68 | ||||
| -rw-r--r-- | pkgs/lwjgl.nix | 113 | ||||
| -rw-r--r-- | release.nix | 48 | ||||
| -rw-r--r-- | shell.nix | 17 |
9 files changed, 450 insertions, 0 deletions
diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9e0313c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "ci" + groups: + actions: + patterns: + - "*" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..054e4a3 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: [main] + paths: + - "**.nix" + - ".github/workflows/ci.yaml" + pull_request: + paths: + - "**.nix" + - ".github/workflows/ci.yaml" + workflow_dispatch: + +jobs: + build: + name: Build + + strategy: + matrix: + include: + - os: ubuntu-latest + system: x86_64-linux + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + with: + nix_path: nixpkgs=channel:nixos-unstable + + - name: Run build + run: | + nix-build release.nix -A ${{ matrix.system }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cb6310 --- /dev/null +++ b/.gitignore @@ -0,0 +1,83 @@ +### Nix + +# Build artifacts +result +result-* +repl-result-* + + +### https://raw.github.com/github/gitignore/8779ee73af62c669e7ca371aaab8399d87127693/Global/Linux.gitignore + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + + +### https://raw.github.com/github/gitignore/8779ee73af62c669e7ca371aaab8399d87127693/Global/macOS.gitignore + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon
+ +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### https://raw.github.com/github/gitignore/8779ee73af62c669e7ca371aaab8399d87127693/Global/Windows.gitignore + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a816c5f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# lwjgl-natives + +> [!CAUTION] +> 🚨 This is still being worked on! Builds will most likely fail + +[](https://builtwithnix.org) + +Native builds of LWJGL for more exotic platforms diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..fb95f92 --- /dev/null +++ b/default.nix @@ -0,0 +1,63 @@ +# nix-build +# or to build a cross compiled package: nix-build -A <triple>.lwjgl +# i.e., nix-build -A aarch64-unknown-linux-gnu.lwjgl +{ + pkgs ? import <nixpkgs> { + inherit system; + config = { }; + overlays = [ ]; + }, + nixpkgs ? <nixpkgs>, + system ? builtins.currentSystem, +}: + +let + inherit (pkgs) lib; + inherit (pkgs.stdenv.hostPlatform) system; + nativeTarget = pkgs.stdenv.hostPlatform.config; + + # Targets we want to build for + targets = [ + "x86_64-unknown-linux-gnu" + "i686-unknown-linux-gnu" + "aarch64-unknown-linux-gnu" + "armv7l-unknown-linux-gnueabihf" + "riscv64-unknown-linux-gnu" + ]; + + # Loop over each target + forAllTargets = lib.genAttrs targets; + + # Nixpkgs re-instantiated to cross compile from our current system to each target + crossPkgsFor = forAllTargets ( + target: + + import nixpkgs { + inherit system; + inherit (pkgs) config overlays; + crossSystem = { + config = target; + }; + } + ); + + # Our package set for each target + ourPackagesFor = forAllTargets ( + target: + + let + callPackage = lib.callPackageWith (ourPackagesFor.${target} // crossPkgsFor.${target}); + in + + { + fetchAntDeps = callPackage ./pkgs/fetch-ant-deps.nix { }; + lwjgl = callPackage ./pkgs/lwjgl.nix { }; + } + ); + + nativeLwjgl = + ourPackagesFor.${nativeTarget}.lwjgl + or (lib.trace "${nativeTarget} is not a supported target" pkgs.emptyFile); +in + +ourPackagesFor // { lwjgl = nativeLwjgl; } diff --git a/pkgs/fetch-ant-deps.nix b/pkgs/fetch-ant-deps.nix new file mode 100644 index 0000000..69e29b4 --- /dev/null +++ b/pkgs/fetch-ant-deps.nix @@ -0,0 +1,68 @@ +{ + lib, + stdenv, + ant, + buildPackages, +}: + +lib.makeOverridable ( + lib.fetchers.withNormalizedHash { } ( + { + pname, + nativeBuildInputs ? [ ], + antJdk ? buildPackages.jdk, + outputHash, + outputHashAlgo, + ... + }@args: + + let + args' = lib.removeAttrs args [ + "pname" + "nativeBuildInputs" + "antJdk" + ]; + in + + stdenv.mkDerivation ( + lib.recursiveUpdate { + pname = pname + "-ant-deps"; + + nativeBuildInputs = [ ant ] ++ nativeBuildInputs; + + buildPhase = '' + runHook preBuild + ant init + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mv bin/libs $out + runHook postInstall + ''; + + fixupPhase = '' + runHook preFixup + + find $out -type f \( \ + -name \*.lastUpdated \ + -o -name resolver-status.properties \ + -o -name _remote.repositories \) \ + -delete + + runHook postFixup + ''; + + dontConfigure = true; + + env = { + JAVA_HOME = toString (antJdk.passthru.home or antJdk); + }; + + inherit outputHash outputHashAlgo; + outputHashMode = "recursive"; + } args' + ) + ) +) diff --git a/pkgs/lwjgl.nix b/pkgs/lwjgl.nix new file mode 100644 index 0000000..fac5eb5 --- /dev/null +++ b/pkgs/lwjgl.nix @@ -0,0 +1,113 @@ +{ + lib, + stdenv, + breakpointHook, + ant, + at-spi2-atk, + buildPackages, + dbus, + fetchAntDeps, + fetchFromGitHub, + gdk-pixbuf, + gtk3, + kotlin, + libGLU, + libglvnd, + xorg, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "lwjgl"; + version = "3.3.4"; + + src = fetchFromGitHub { + owner = "LWJGL"; + repo = "lwjgl3"; + tag = finalAttrs.version; + hash = "sha256-U0pPeTqVoruqqhhMrBrczy0qt83a8atr8DyRcGgX/yI="; + }; + + antJdk = buildPackages.jdk_headless; + antDeps = fetchAntDeps { + inherit (finalAttrs) + pname + version + src + antJdk + ; + hash = "sha256-7jVlKBia8dJGuBjNwaljHBrXUep9KjOHHyZESayFnhs="; + }; + + strictDeps = true; + + nativeBuildInputs = [ + ant + kotlin + ] ++ lib.optional (lib.meta.availableOn stdenv.buildPlatform breakpointHook) breakpointHook; + + buildInputs = [ + at-spi2-atk + dbus + gdk-pixbuf + gtk3 + libGLU + xorg.libX11 + xorg.libXt + ]; + + env = { + JAVA_HOME = finalAttrs.antJdk.home; + JAVA8_HOME = buildPackages.jdk8_headless.home; + + # https://github.com/LWJGL/lwjgl3/tree/e8552d53624f789c8f8c3dc35976fa02cba73cff/doc#build-configuration + LWJGL_BUILD_OFFLINE = "yes"; + LWJGL_BUILD_ARCH = + if stdenv.hostPlatform.isx86_64 then + "x64" + else if stdenv.hostPlatform.isi686 then + "x86" + else if stdenv.hostPlatform.isAarch64 then + "arm64" + else if stdenv.hostPlatform.isArmv7 then + "arm32" + else if stdenv.hostPlatform.isRiscV64 then + "riscv64" + else + throw "${stdenv.hostPlatform.cpu.name} is not a supported architecture"; + }; + + # Put the dependencies we already downloaded in the right place + # NOTE: This directory *must* be writable + postConfigure = '' + mkdir bin + cp -dpr "$antDeps" ./bin/libs && chmod -R +w bin/libs + ''; + + postBuild = '' + mkdir $out + ant \ + -emacs \ + -Dgcc.libpath.opengl=${libglvnd}/lib \ + compile-templates compile-native + ''; + + postInstall = '' + exit 1 + ''; + + meta = { + platforms = + + let + architectures = lib.flatten [ + lib.platforms.x86_64 + lib.platforms.i686 + lib.platforms.aarch64 + lib.platforms.armv7 + lib.platforms.riscv64 + ]; + in + + lib.intersectLists architectures lib.platforms.linux; + }; +}) diff --git a/release.nix b/release.nix new file mode 100644 index 0000000..7b0524b --- /dev/null +++ b/release.nix @@ -0,0 +1,48 @@ +# nix-build release.nix -A <system> +# i.e., nix-build release.nix -A x86_64-linux +{ + lib ? import <nixpkgs/lib>, +}: + +let + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.gitTracked ./.; + }; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; +in + +lib.genAttrs systems ( + system: + + let + pkgs = import <nixpkgs> { + inherit system; + config = { }; + overlays = [ ]; + }; + + mkCheck = + name: deps: script: + pkgs.runCommand name { nativeBuildInputs = deps; } '' + ${script} + touch $out + ''; + + packages = lib.mapAttrs (lib.const lib.recurseIntoAttrs) (import ./default.nix { inherit pkgs; }); + + checks = { + deadnix = mkCheck "check-deadnix" [ pkgs.deadnix ] "deadnix --fail ${src}"; + nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${src}"; + statix = mkCheck "check-statix" [ pkgs.statix ] "statix check ${src}"; + }; + in + + checks // packages // { shell = import ./shell.nix { inherit pkgs; }; } +) diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..80e9e25 --- /dev/null +++ b/shell.nix @@ -0,0 +1,17 @@ +# nix-shell +{ + pkgs ? import <nixpkgs> { + inherit system; + config = { }; + overlays = [ ]; + }, + system ? builtins.currentSystem, +}: + +pkgs.mkShellNoCC { + packages = [ + pkgs.deadnix + pkgs.nixfmt-rfc-style + pkgs.statix + ]; +} |
