Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flake-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"executor-version": "v0.2.11",
"executor-version": "vTEST",
"repo-url": "https://github.com/genlayerlabs/genvm.git",
"head-revision": "a605f30"
"head-revision": "fake"
}
320 changes: 167 additions & 153 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,167 +22,181 @@
};

outputs = { self, nixpkgs, flake-utils, systems }:
let
genvm-release =
let
pkgs = import nixpkgs {
system = "x86_64-linux";
};
flake-utils.lib.eachSystem [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
] (system:
let
pkgs = import nixpkgs {
inherit system;
};

lib = pkgs.lib;

lib = pkgs.lib;
# Build inputs for devShells — only Linux has `glibc` as a
# separate package; on darwin the C library ships via
# stdenv.cc and doesn't need an explicit reference.
linuxOnly = x: lib.optional pkgs.stdenv.isLinux x;

args = import ./support {
inherit pkgs;
root-src = self;
} // {
inherit components;
custom-rust = import ./support/rust.nix { inherit pkgs system; withLinters = true; withZig = false; };
custom-rust-builder = import ./support/compile-rust.nix {
inherit pkgs system;
zig = import ./support/zig.nix { inherit pkgs system; };
};

build-config = builtins.fromJSON (builtins.readFile ./flake-config.json);
custom-cargo-afl = custom-rust-builder rec {
name = "cargo-afl";
version = "0.15.18";
src = pkgs.fetchzip {
url = "https://crates.io/api/v1/crates/cargo-afl/0.15.18/download";
hash = "sha256-6ti50bwE4bLwIyR76bMt/Vn6Nwqu9n0IKdVuDdYkiHg=";
extension = ".tar.gz";
name = "cargo-afl-0.15.18.tar.gz";
};

components = args.merge-components [
(import ./libs args)
(import ./modules args)
(import ./executor args)
(import ./runners/release.nix args)
(import ./runners/support/all args)
];
target = system;

merge-all-for-platform = platform:
let
for-platform = components.${platform};
names = builtins.attrNames for-platform;
just-derivations = builtins.attrValues for-platform;
in
pkgs.stdenvNoCC.mkDerivation {
name = "genvm-${platform}";

srcs = just-derivations;

dontUnpack = true;
dontConfigure = true;
dontBuild = true;
dontFixup = true;

installPhase = ''
mkdir -p $out
for src in $srcs; do
cp --no-preserve=ownership -r $src/. $out/.
chmod -R u+w $out
done
'';
};
in {
inherit components;
cargoLock.lockFile = "${src}/Cargo.lock";

all-for-platform = builtins.mapAttrs (platform: sub: merge-all-for-platform platform) components;
nativeBuildInputs = [ pkgs.gnumake pkgs.makeWrapper ];

postBuild = ''
XDG_DATA_HOME="$out/data" ./target/*/release/cargo-afl afl config --build --verbose
'';

installPhase = ''
mkdir -p $out/bin
cp target/__out $out/bin/cargo-afl
wrapProgram $out/bin/cargo-afl \
--set XDG_DATA_HOME "$out/data"
'';
};

packages-0 = with pkgs; [ bash xz zlib git python312 coreutils which jq stdenv.cc nix ] ++ (linuxOnly pkgs.glibc);
packages-lint = with pkgs; [ pre-commit ];
packages-rust = [ custom-rust ];
packages-debug-test = with pkgs; [
(pkgs.ninja.overrideAttrs (old: {
postPatch = old.postPatch + ''
substituteInPlace src/subprocess-posix.cc \
--replace '"/bin/sh"' '"${pkgs.bash}/bin/bash"'
'';
}))
ruby
gcc

custom-cargo-afl
llvmPackages.libllvm

python312Packages.jsonnet
pkgs.python312Packages.aiohttp
wabt
];
packages-py-test = with pkgs; [
# aflplusplus # currently we don't run fuzzing on CI
python312
poetry
];
shell-hook-base = ''
export PATH="$(pwd)/tools/git-third-party:$PATH"
export LD_LIBRARY_PATH="${toString pkgs.xz.out}/lib:${toString pkgs.zlib.out}/lib:${pkgs.stdenv.cc.cc.lib}/lib${lib.optionalString pkgs.stdenv.isLinux ":${toString pkgs.glibc}/lib"}:$LD_LIBRARY_PATH"
export LLVM_PROFILE_FILE=/dev/null
'';

# ────────────────────────────────────────────────────────
# genvm release outputs — the platform-specific build
# artifacts (libs + modules + executor + runners +
# universal-manifest). Evaluated under the current build
# system; target platform is selected by attribute name
# (arm64-macos / amd64-linux / etc.) and cross-compiled
# via zig + wasi-sdk.
# ────────────────────────────────────────────────────────

args = import ./support {
inherit pkgs;
root-src = self;
} // {
inherit components;
build-config = builtins.fromJSON (builtins.readFile ./flake-config.json);
};

for-systems =
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};

custom-rust = import ./support/rust.nix { inherit pkgs system; withLinters = true; withZig = false; };
custom-rust-builder = import ./support/compile-rust.nix {
inherit pkgs system;
zig = import ./support/zig.nix { inherit pkgs system; };
};

custom-cargo-afl = custom-rust-builder rec {
name = "cargo-afl";
version = "0.15.18";
src = pkgs.fetchzip {
url = "https://crates.io/api/v1/crates/cargo-afl/0.15.18/download";
hash = "sha256-6ti50bwE4bLwIyR76bMt/Vn6Nwqu9n0IKdVuDdYkiHg=";
extension = ".tar.gz";
name = "cargo-afl-0.15.18.tar.gz";
};

target = system;

cargoLock.lockFile = "${src}/Cargo.lock";

nativeBuildInputs = [ pkgs.gnumake pkgs.makeWrapper ];

postBuild = ''
XDG_DATA_HOME="$out/data" ./target/*/release/cargo-afl afl config --build --verbose
'';

installPhase = ''
mkdir -p $out/bin
cp target/__out $out/bin/cargo-afl
wrapProgram $out/bin/cargo-afl \
--set XDG_DATA_HOME "$out/data"
'';
};

packages-0 = with pkgs; [ bash xz zlib git python312 coreutils which jq stdenv.cc glibc nix ];
packages-lint = with pkgs; [ pre-commit ];
packages-rust = [ custom-rust ];
packages-debug-test = with pkgs; [
(pkgs.ninja.overrideAttrs (old: {
postPatch = old.postPatch + ''
substituteInPlace src/subprocess-posix.cc \
--replace '"/bin/sh"' '"${pkgs.bash}/bin/bash"'
'';
}))
ruby
gcc

custom-cargo-afl
llvmPackages.libllvm

python312Packages.jsonnet
pkgs.python312Packages.aiohttp
wabt
];
packages-py-test = with pkgs; [
# aflplusplus # currently we don't run fuzzing on CI
python312
poetry
];
shell-hook-base = ''
export PATH="$(pwd)/tools/git-third-party:$PATH"
export LD_LIBRARY_PATH="${toString pkgs.xz.out}/lib:${toString pkgs.zlib.out}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${toString pkgs.glibc}/lib:$LD_LIBRARY_PATH"
export LLVM_PROFILE_FILE=/dev/null
'';
in
{
devShells.py-test = pkgs.mkShell {
packages = packages-py-test ++ [ pkgs.ruby ];
shellHook = shell-hook-base;
};
devShells.initial-check = pkgs.mkShell {
packages = packages-0 ++ packages-rust ++ packages-lint;
shellHook = shell-hook-base;
};
devShells.rust-test = pkgs.mkShell {
packages = packages-0 ++ packages-debug-test ++ packages-rust;
shellHook = shell-hook-base;
};
devShells.mock-tests = pkgs.mkShell {
packages = packages-0 ++ [
pkgs.python312
pkgs.python312Packages.jsonnet
pkgs.python312Packages.aiohttp
pkgs.wabt
];
shellHook = shell-hook-base;
};
devShells.full = pkgs.mkShell {
packages = packages-0 ++ packages-debug-test ++ packages-py-test ++ packages-rust ++ packages-lint;
shellHook = shell-hook-base;
};
devShells.check-qemu = pkgs.mkShell {
packages = packages-0 ++ [ pkgs.qemu ];
shellHook = shell-hook-base;
};
}
);
components = args.merge-components [
(import ./libs args)
(import ./modules args)
(import ./executor args)
(import ./runners/release.nix args)
(import ./runners/support/all args)
];

merge-all-for-platform = platform:
let
for-platform = components.${platform};
names = builtins.attrNames for-platform;
just-derivations = builtins.attrValues for-platform;
in
pkgs.stdenvNoCC.mkDerivation {
name = "genvm-${platform}";

srcs = just-derivations;

dontUnpack = true;
dontConfigure = true;
dontBuild = true;
dontFixup = true;

installPhase = ''
mkdir -p $out
for src in $srcs; do
cp --no-preserve=ownership -r $src/. $out/.
chmod -R u+w $out
done
'';
};

all-for-platform = builtins.mapAttrs (platform: sub: merge-all-for-platform platform) components;
in
for-systems // genvm-release;
{
devShells.py-test = pkgs.mkShell {
packages = packages-py-test ++ [ pkgs.ruby ];
shellHook = shell-hook-base;
};
devShells.initial-check = pkgs.mkShell {
packages = packages-0 ++ packages-rust ++ packages-lint;
shellHook = shell-hook-base;
};
devShells.rust-test = pkgs.mkShell {
packages = packages-0 ++ packages-debug-test ++ packages-rust;
shellHook = shell-hook-base;
};
devShells.mock-tests = pkgs.mkShell {
packages = packages-0 ++ [
pkgs.python312
pkgs.python312Packages.jsonnet
pkgs.python312Packages.aiohttp
pkgs.wabt
];
shellHook = shell-hook-base;
};
devShells.full = pkgs.mkShell {
packages = packages-0 ++ packages-debug-test ++ packages-py-test ++ packages-rust ++ packages-lint;
shellHook = shell-hook-base;
};
devShells.check-qemu = pkgs.mkShell {
packages = packages-0 ++ [ pkgs.qemu ];
shellHook = shell-hook-base;
};

# `nix build .#all-for-platform.X` still works: Nix resolves
# the shorthand against `legacyPackages.<current-system>`
# next (after `packages`). legacyPackages allows nested
# attrsets (packages does not, each entry must be a drv),
# which lets us keep the `all-for-platform.<target>` shape.
legacyPackages = {
inherit components;
inherit all-for-platform;
};
}
);
}
19 changes: 15 additions & 4 deletions runners/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# importing this file (no args) results in:
# importing this file results in:
# [{
# id
# hash
# uid
# derivation # tar file
# }]
#
# Callers may pass `pkgs` to evaluate under their own nixpkgs + system;
# if omitted we fall back to a pinned x86_64-linux nixpkgs for legacy
# scripts that used to `import ./runners/default.nix` without args.
{ pkgs ? null
, ...
}:
let
pkgs = import
default-pkgs = import
(builtins.fetchGit {
url = "https://github.com/NixOS/nixpkgs";
rev = "8b27c1239e5c421a2bbc2c65d52e4a6fbf2ff296";
Expand All @@ -15,11 +22,15 @@ let
{
system = "x86_64-linux";
};

effective-pkgs = if pkgs == null then default-pkgs else pkgs;

runnersLib = import ./support args;

args = {
inherit pkgs runnersLib;
inherit (pkgs) lib stdenvNoCC;
pkgs = effective-pkgs;
inherit runnersLib;
inherit (effective-pkgs) lib stdenvNoCC;
};
in
(import ./py-libs args) ++
Expand Down
5 changes: 3 additions & 2 deletions runners/support/all/head.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ build-config
{ pkgs
, build-config
, ...
}:
builtins.map
(x: x // { rev = build-config.head-revision; })
(import ../../default.nix)
(import ../../default.nix { inherit pkgs; })
Loading
Loading