diff --git a/.gitignore b/.gitignore index c9f6e45..82bdb4d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ /build /traces +/result +/result-* /todo/* /src/pkg/.zig-cache diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cd56566 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1778443072, + "narHash": "sha256-zi7/fsqM/kFdNuED//4WOCUtezGtKKqRNORjMvfwjnA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "da5ad661ba4e5ef59ba743f0d112cbc30e474f32", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..00fc60f --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Ant JavaScript runtime"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + ant = pkgs.callPackage ./nix/package.nix { }; + in { + packages.default = ant; + packages.ant = ant; + + devShells.default = pkgs.mkShell { + inputsFrom = [ ant ]; + packages = with pkgs; [ ccache lld ]; + }; + }); +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..2002467 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,91 @@ +{ lib +, llvmPackages_18 +, stdenv +, meson +, ninja +, cmake +, pkg-config +, python3 +, nodejs_22 +, git +, curl +, rustc +, cargo +, rustPlatform +, zig_0_15 ? null +, zig ? null +, importNpmLock +, apple-sdk ? null +, callPackage +}: + +let + zigPkg = if zig_0_15 != null then zig_0_15 else zig; + + antVendor = callPackage ./vendor.nix { }; + + toolsNodeModules = importNpmLock.buildNodeModules { + package = lib.importJSON ../src/tools/package.json; + packageLock = lib.importJSON ../src/tools/npm-shrinkwrap.json; + nodejs = nodejs_22; + }; +in +llvmPackages_18.stdenv.mkDerivation (finalAttrs: { + pname = "ant"; + version = lib.fileContents ../meson/ant.version; + + src = ../.; + + nativeBuildInputs = [ + meson + ninja + cmake + pkg-config + python3 + nodejs_22 + git + curl + rustc + cargo + rustPlatform.cargoSetupHook + zigPkg + ]; + + buildInputs = lib.optionals stdenv.isDarwin [ apple-sdk ]; + + cargoDeps = rustPlatform.importCargoLock { + lockFile = ../src/strip/Cargo.lock; + }; + cargoRoot = "src/strip"; + + postUnpack = '' + chmod -R u+w "$sourceRoot/vendor" + cp -rT --no-preserve=mode ${antVendor} "$sourceRoot/vendor" + chmod -R u+w "$sourceRoot/vendor" + ''; + + preConfigure = '' + export ZIG_GLOBAL_CACHE_DIR=$TMPDIR/zig-cache + export ZIG_LOCAL_CACHE_DIR=$TMPDIR/zig-local-cache + mkdir -p "$ZIG_GLOBAL_CACHE_DIR" "$ZIG_LOCAL_CACHE_DIR" + + ln -sfn ${toolsNodeModules}/node_modules src/tools/node_modules + ''; + + installPhase = '' + runHook preInstall + install -Dm755 ant "$out/bin/ant" + ln -s ant "$out/bin/antx" + runHook postInstall + ''; + + doCheck = false; + + meta = { + description = "Ant JavaScript runtime"; + homepage = "https://github.com/themackabu/ant"; + license = lib.licenses.mit; + platforms = lib.platforms.unix; + mainProgram = "ant"; + }; +}) diff --git a/nix/vendor.nix b/nix/vendor.nix new file mode 100644 index 0000000..dd7a259 --- /dev/null +++ b/nix/vendor.nix @@ -0,0 +1,49 @@ +{ lib, stdenvNoCC, meson, ninja, git, cacert }: + +let + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.unions [ + ../meson.build + ../meson_options.txt + ../meson + (lib.fileset.fileFilter (f: f.hasExt "wrap") ../vendor) + ../vendor/packagefiles + ]; + }; +in +stdenvNoCC.mkDerivation { + pname = "ant-vendor"; + version = lib.fileContents ../meson/ant.version; + + inherit src; + + nativeBuildInputs = [ meson ninja git cacert ]; + + dontConfigure = true; + dontPatchShebangs = true; + dontFixup = true; + + buildPhase = '' + runHook preBuild + export HOME=$TMPDIR + meson subprojects download || true + test -n "$(ls -A vendor/packagecache 2>/dev/null)" \ + || test -d vendor/boringssl \ + || { echo "FATAL: meson subprojects download produced nothing"; exit 1; } + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + find vendor -type d -name .git -prune -exec rm -rf {} + + rm -rf vendor/packagecache + mkdir -p $out + cp -r vendor/. $out/ + runHook postInstall + ''; + + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = "sha256-LKq8zNUxBHKJFhEblmshzAl55VU1ihQcjVUGXQMoeDg="; +}