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
104 changes: 104 additions & 0 deletions .github/workflows/test-using-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: build and test (using nix)

on:
pull_request:
merge_group:
workflow_dispatch:
push:
branches:
- main

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

defaults:
run:
shell: nix develop .#ci --ignore-env --keep-env-var CI --command bash -e {0}

jobs:
build_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5
with:
submodules: true

- uses: cachix/install-nix-action@v31
- run: echo "Preparing Nix shell"

- run: dune build --profile=release
- run: dune runtest --force

format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5
with:
submodules: true

- uses: cachix/install-nix-action@v31
- run: echo "Preparing Nix shell"

- run: dune build @fmt --display=quiet
if: "!cancelled()"
- run: dune build '@treesit'
if: "!cancelled()"

build_test_slower:
timeout-minutes: 15
runs-on: ubuntu-latest
needs: [ build_test, format ]
if: "! ( cancelled() || success() ) || github.ref == 'refs/heads/main'"

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v6
with:
submodules: true

- uses: ocaml/setup-ocaml@v3

- run: opam option --global 'archive-mirrors+="https://opam.ocaml.org/cache"'
- run: opam repository --all add pac https://github.com/uq-pac/opam-repository.git
- run: opam install . --deps-only --with-test
- run: echo LIBRARY_PATH="$LIBRARY_PATH:/opt/homebrew/lib" >> "$GITHUB_ENV"
if: matrix.os == 'macos-latest'
- run: opam lint
- run: opam exec -- dune build @fmt --display=quiet
- run: opam exec -- dune build --ignore-promoted-rules --profile=release
- run: opam exec -- dune build --ignore-promoted-rules '@treesit'
- run: opam exec -- dune runtest --ignore-promoted-rules --force

at_least_one_success:
runs-on: ubuntu-latest
needs: [ build_test_slower ]
if: "!cancelled()"

defaults:
run:
shell: bash

steps:
- run: ${{ needs.build_test_slower.result == 'success' || needs.build_test_slower.result == 'skipped' }}
name: "Check that at least one build & test job succeeded"

docs-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5
with:
submodules: true

- uses: cachix/install-nix-action@v31
- run: echo "Preparing Nix shell"

- run: odoc_driver bincaml # TODO: fixme. need to register packages somehow?
2 changes: 1 addition & 1 deletion bincaml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.24"}
"dune" {>= "3.20"}
"ocaml"
"unionFind"
"capstone_arm64_disas"
Expand Down
2 changes: 1 addition & 1 deletion bincaml_lsp.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.24"}
"dune" {>= "3.20"}
"menhir" {>= "20180523"}
"ppx_expect"
"bincaml"
Expand Down
2 changes: 1 addition & 1 deletion capstone_arm64_disas.opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.24"}
"dune" {>= "3.20"}
"ocaml"
"ppx_expect"
"odoc" {with-doc}
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 3.24)
(lang dune 3.20)

(using menhir 3.0)

Expand Down
44 changes: 35 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
nixConfig.extra-substituters = [ "https://pac-nix.cachix.org/" ];
nixConfig.extra-trusted-public-keys = [
"pac-nix.cachix.org-1:l29Pc2zYR5yZyfSzk1v17uEZkhEw0gI4cXuOIsxIGpc="
];

inputs = {
self.submodules = true;

nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";

Expand Down Expand Up @@ -37,7 +41,7 @@
in
flake-for-all-systems args {
overlays = {
addBincamlPackages = ofinal: _: {
addBincamlPackages = ofinal: oprev: {
buildDune324Package = ofinal.buildDunePackage.override {
dune_3 = ofinal.dune_3_24;
};
Expand All @@ -53,6 +57,7 @@
capstone_arm64_disas = ofinal.callPackage ./nix/capstone_arm64_disas.nix {
buildDunePackage = ofinal.buildDune324Package;
};
bincaml-docs = ofinal.callPackage ./nix/bincaml-docs.nix { };

ocaml-protoc-plugin-6-1-0 = ofinal.callPackage ./nix/ocaml-protoc-plugin.nix { };
aslp_lifter_ocaml = ofinal.callPackage ./nix/aslp-lifter-ocaml.nix { };
Expand All @@ -61,6 +66,20 @@
kittyimg = ofinal.callPackage ./nix/kittyimg.nix { };
stb_image = ofinal.callPackage ./nix/stb_image.nix { };
containers = ofinal.callPackage ./nix/containers.nix { };

odoc =
(oprev.odoc.override {
cmdliner = ofinal.cmdliner;
}).overrideAttrs
(
f: p: {
doCheck = false;
propagatedBuildInputs = (p.propagatedBuildInputs or [ ]) ++ (p.buildInputs or [ ]) ++ [ofinal.ppx_expect];
}
);
sherlodoc = ofinal.callPackage ./nix/sherlodoc.nix { };
odoc-md = ofinal.callPackage ./nix/odoc-md.nix { };
odoc-driver = ofinal.callPackage ./nix/odoc-driver.nix { };
};

enableOcamlFramePointer =
Expand Down Expand Up @@ -88,16 +107,22 @@
...
}:
let
inherit (pac-nix.legacyPackages) bnfc-treesitter;

pkgs = nixpkgs.legacyPackages;
selfOcamlPackages = pkgs.ocamlPackages.overrideScope self.overlays.addBincamlPackages;
ocamlPackages = pkgs.ocamlPackages.overrideScope (
_: _: {
z3-bin = pkgs.z3;
inherit (pac-nix.legacyPackages) bnfc-treesitter;
}
);
selfOcamlPackages = ocamlPackages.overrideScope self.overlays.addBincamlPackages;
fpOcamlPackages = selfOcamlPackages.overrideScope self.overlays.enableOcamlFramePointer;
in
{
defaultPackage = selfOcamlPackages.bincaml;

legacyPackages = {
ocamlPackages = selfOcamlPackages;

bincaml = selfOcamlPackages.bincaml;
bincaml_lsp = selfOcamlPackages.bincaml_lsp;
aslp_lifter_ocaml = selfOcamlPackages.aslp_lifter_ocaml;
Expand All @@ -123,12 +148,13 @@
devShells = {
default = self.devShells.fp;
fp = fpOcamlPackages.callPackage ./nix/shell.nix {
inherit bnfc-treesitter;
z3 = pkgs.z3.out;
isShellForCI = false;
};
no-fp = selfOcamlPackages.callPackage ./nix/shell.nix {
inherit bnfc-treesitter;
z3 = pkgs.z3.out;
isShellForCI = false;
};
ci = selfOcamlPackages.callPackage ./nix/shell.nix {
isShellForCI = true;
};
};
};
Expand Down
1 change: 0 additions & 1 deletion nix/aslp-lifter-ocaml.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ buildDunePackage (self: {

outputs = [
"out"
"dev"
];

meta = {
Expand Down
55 changes: 55 additions & 0 deletions nix/bincaml-docs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
buildEnv,
runCommand,
writeShellScriptBin,
odoc-driver,
bincaml,
bincaml_lsp,
odoc,
findlib,
ocaml,
fmt,
sherlodoc,
runtimeShell
}:

let
dummy-opam = runCommand "dummy-opam" {
} ''
mkdir -pv $out/lib $out/bin
cp ${findlib}/etc/findlib.conf $out/lib
cp -r ${ocaml}/lib/ocaml $out/lib/ocaml

cat <<EOF > $out/bin/opam
#!${runtimeShell}
echo $out
EOF
chmod +x $out/bin/opam
'';

env = buildEnv {
name = "ajidso";
paths = [ fmt ];
includeClosures = true;
pathsToLink = [ "/share/doc" "/lib/ocaml/5.4.1/site-lib" ];

postBuild = ''
mv $out/share/doc doc
mv $out/lib/ocaml/*/site-lib lib
ln -s ${ocaml}/lib/ocaml lib

rm -rf $out
mkdir -v $out
mv doc lib $out
'';
};

in runCommand "bincaml-docs" {
nativeBuildInputs = [ dummy-opam odoc-driver odoc sherlodoc ocaml ];
} ''
dune_prefix=$(mktemp -d)/_build/install/default
mkdir -p $(dirname $dune_prefix)
ln -s ${env} $dune_prefix
ls -l $(dirname $dune_prefix)
OCAMLPATH=$dune_prefix/lib odoc_driver --html-dir=$out -v $(cd $dune_prefix/lib && echo *)
''
10 changes: 3 additions & 7 deletions nix/bincaml-lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ buildDunePackage {
logs
fmt
iter
linol
linol-lwt
containers
ppx_deriving
linol
linol-lwt
];
propagatedBuildInputs = [ ];

doCheck = true;
outputs = [
"out"
"dev"
];
outputs = [ "out" ];

meta = {
homepage = "https://github.com/agle/bincaml";
Expand Down
19 changes: 15 additions & 4 deletions nix/bincaml.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
qcheck-core,
qcheck-alcotest,
qcheck-stm,
tree-sitter,
nodejs-slim,
bnfc-treesitter,
boogie,
cvc5,
z3-bin, # custom name for z3 binary, since `z3` is the ocaml library

# dev:
# , odig
Expand All @@ -66,6 +72,14 @@ buildDunePackage {
qcheck-alcotest
qcheck-stm
];
nativeCheckInputs = [
tree-sitter
nodejs-slim
bnfc-treesitter
boogie
cvc5
z3-bin.out
];
nativeBuildInputs = [
writableTmpDirAsHomeHook
protobuf
Expand Down Expand Up @@ -110,10 +124,7 @@ buildDunePackage {
'';

doCheck = true;
outputs = [
"out"
"dev"
];
outputs = [ "out" ];

meta = {
homepage = "https://github.com/agle/bincaml";
Expand Down
5 changes: 1 addition & 4 deletions nix/capstone_arm64_disas.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ buildDunePackage {
propagatedBuildInputs = [ capstone ];

doCheck = false;
outputs = [
"out"
"dev"
];
outputs = [ "out" ];

meta = {
homepage = "https://github.com/agle/bincaml";
Expand Down
Loading
Loading