From dd1a8799674887cd112b5a888cd078935fbcd709 Mon Sep 17 00:00:00 2001 From: Jenna Fligor Date: Sat, 24 Aug 2024 07:40:35 -0500 Subject: [PATCH] rename frontend and nix cleanup --- Justfile | 10 +- flake.nix | 137 ++++++------- .../{probe_frontend => frontend}/Cargo.lock | 0 .../{probe_frontend => frontend}/Cargo.toml | 0 .../{probe_frontend => frontend}/LICENSE | 0 .../{probe_frontend => frontend}/README.md | 0 .../cli/Cargo.toml | 0 .../cli/src/dump.rs | 0 .../cli/src/main.rs | 0 .../cli/src/record.rs | 0 .../cli/src/transcribe.rs | 0 .../cli/src/util.rs | 0 .../{probe_frontend => frontend}/deny.toml | 0 probe_src/frontend/frontend.nix | 191 ++++++++++++++++++ .../lib/Cargo.toml | 0 .../{probe_frontend => frontend}/lib/build.rs | 0 .../lib/src/error.rs | 0 .../lib/src/lib.rs | 0 .../lib/src/metadata.rs | 0 .../lib/src/ops.rs | 0 .../lib/src/transcribe.rs | 0 .../macros/Cargo.toml | 0 .../macros/src/lib.rs | 0 .../macros/src/pygen.rs | 0 .../python/probe_py/__init__.py | 0 .../python/probe_py/generated/__init__.py | 0 .../python/probe_py/generated/ops.py | 0 .../python/probe_py/generated/parser.py | 0 .../python/pyproject.toml | 0 probe_src/probe_frontend/frontend.nix | 191 ------------------ setup_devshell.sh | 10 +- 31 files changed, 268 insertions(+), 271 deletions(-) rename probe_src/{probe_frontend => frontend}/Cargo.lock (100%) rename probe_src/{probe_frontend => frontend}/Cargo.toml (100%) rename probe_src/{probe_frontend => frontend}/LICENSE (100%) rename probe_src/{probe_frontend => frontend}/README.md (100%) rename probe_src/{probe_frontend => frontend}/cli/Cargo.toml (100%) rename probe_src/{probe_frontend => frontend}/cli/src/dump.rs (100%) rename probe_src/{probe_frontend => frontend}/cli/src/main.rs (100%) rename probe_src/{probe_frontend => frontend}/cli/src/record.rs (100%) rename probe_src/{probe_frontend => frontend}/cli/src/transcribe.rs (100%) rename probe_src/{probe_frontend => frontend}/cli/src/util.rs (100%) rename probe_src/{probe_frontend => frontend}/deny.toml (100%) create mode 100644 probe_src/frontend/frontend.nix rename probe_src/{probe_frontend => frontend}/lib/Cargo.toml (100%) rename probe_src/{probe_frontend => frontend}/lib/build.rs (100%) rename probe_src/{probe_frontend => frontend}/lib/src/error.rs (100%) rename probe_src/{probe_frontend => frontend}/lib/src/lib.rs (100%) rename probe_src/{probe_frontend => frontend}/lib/src/metadata.rs (100%) rename probe_src/{probe_frontend => frontend}/lib/src/ops.rs (100%) rename probe_src/{probe_frontend => frontend}/lib/src/transcribe.rs (100%) rename probe_src/{probe_frontend => frontend}/macros/Cargo.toml (100%) rename probe_src/{probe_frontend => frontend}/macros/src/lib.rs (100%) rename probe_src/{probe_frontend => frontend}/macros/src/pygen.rs (100%) rename probe_src/{probe_frontend => frontend}/python/probe_py/__init__.py (100%) rename probe_src/{probe_frontend => frontend}/python/probe_py/generated/__init__.py (100%) rename probe_src/{probe_frontend => frontend}/python/probe_py/generated/ops.py (100%) rename probe_src/{probe_frontend => frontend}/python/probe_py/generated/parser.py (100%) rename probe_src/{probe_frontend => frontend}/python/pyproject.toml (100%) delete mode 100644 probe_src/probe_frontend/frontend.nix diff --git a/Justfile b/Justfile index 185d9147..f7631f65 100644 --- a/Justfile +++ b/Justfile @@ -13,16 +13,16 @@ check-ruff: ruff check probe_src check-format-rust: - env --chdir probe_src/probe_frontend cargo fmt --check + env --chdir probe_src/frontend cargo fmt --check fix-format-rust: - env --chdir probe_src/probe_frontend cargo fmt + env --chdir probe_src/frontend cargo fmt check-clippy: - env --chdir probe_src/probe_frontend cargo clippy + env --chdir probe_src/frontend cargo clippy fix-clippy: - env --chdir probe_src/probe_frontend cargo clippy --fix --allow-staged + env --chdir probe_src/frontend cargo clippy --fix --allow-staged check-mypy: mypy --strict --package probe_py.manual @@ -33,7 +33,7 @@ compile-lib: make --directory=probe_src/libprobe all compile-cli: - env --chdir=probe_src/probe_frontend cargo build --release + env --chdir=probe_src/frontend cargo build --release compile-tests: make --directory=probe_src/tests/c all diff --git a/flake.nix b/flake.nix index 3dc37322..e036fc54 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,7 @@ flake-utils, rust-overlay, ... - }@inputs: let + } @ inputs: let supported-systems = [ "x86_64-linux" "i686-linux" @@ -37,64 +37,68 @@ "armv7l-linux" ]; in - flake-utils.lib.eachSystem supported-systems (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [(import rust-overlay)]; - }; - python = pkgs.python312; - frontend = (import ./probe_src/probe_frontend/frontend.nix) ({ inherit system pkgs python; } // inputs); - in { - packages = rec { - probe-bundled = let - # libprobe is a "private" package - # It is only used in probe-bundled - # TODO: The only public package should probably be probe-bundled and probe-py. - libprobe = pkgs.stdenv.mkDerivation rec { - pname = "libprobe"; + flake-utils.lib.eachSystem supported-systems ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + python = pkgs.python312; + frontend = (import ./probe_src/frontend/frontend.nix) ({inherit system pkgs python;} // inputs); + in { + packages = + rec { + probe-bundled = let + # libprobe is a "private" package + # It is only used in probe-bundled + # TODO: The only public package should probably be probe-bundled and probe-py. + libprobe = pkgs.stdenv.mkDerivation rec { + pname = "libprobe"; + version = "0.1.0"; + src = ./probe_src/libprobe; + makeFlags = ["INSTALL_PREFIX=$(out)" "SOURCE_VERSION=${version}"]; + buildInputs = [ + (pkgs.python312.withPackages (pypkgs: [ + pypkgs.pycparser + ])) + ]; + }; + in + pkgs.stdenv.mkDerivation rec { + pname = "probe-bundled"; + version = "0.1.0"; + dontUnpack = true; + dontBuild = true; + nativeBuildInputs = [pkgs.makeWrapper]; + installPhase = '' + mkdir $out $out/bin + makeWrapper \ + ${self.packages.${system}.probe-cli}/bin/probe \ + $out/bin/probe \ + --set __PROBE_LIB ${libprobe}/lib + ''; + }; + probe-py-manual = python.pkgs.buildPythonPackage rec { + pname = "probe_py.manual"; version = "0.1.0"; - src = ./probe_src/libprobe; - makeFlags = [ "INSTALL_PREFIX=$(out)" "SOURCE_VERSION=${version}" ]; - buildInputs = [ - (pkgs.python312.withPackages (pypkgs: [ - pypkgs.pycparser - ])) + pyproject = true; + build-system = [ + python.pkgs.flit-core ]; + src = ./probe_src/python; + propagatedBuildInputs = [ + self.packages.${system}.probe-py-generated + python.pkgs.networkx + python.pkgs.pygraphviz + python.pkgs.pydot + python.pkgs.rich + python.pkgs.typer + ]; + pythonImportsCheck = [pname]; }; - in pkgs.stdenv.mkDerivation rec { - pname = "probe-bundled"; - version = "0.1.0"; - dontUnpack = true; - dontBuild = true; - nativeBuildInputs = [ pkgs.makeWrapper ]; - installPhase = '' - mkdir $out $out/bin - makeWrapper \ - ${self.packages.${system}.probe-cli}/bin/probe \ - $out/bin/probe \ - --set __PROBE_LIB ${libprobe}/lib - ''; - }; - probe-py-manual = python.pkgs.buildPythonPackage rec { - pname = "probe_py.manual"; - version = "0.1.0"; - pyproject = true; - build-system = [ - python.pkgs.flit-core - ]; - src = ./probe_src/python; - propagatedBuildInputs = [ - self.packages.${system}.probe-py-generated - python.pkgs.networkx - python.pkgs.pygraphviz - python.pkgs.pydot - python.pkgs.rich - python.pkgs.typer - ]; - pythonImportsCheck = [ pname ]; - }; - default = probe-bundled; - } // frontend.packages; + default = probe-bundled; + } + // frontend.packages; # TODO: Run pytest tests in Nix checks checks = self.packages.${system} // frontend.checks; devShells = { @@ -105,7 +109,8 @@ popd ''; buildInputs = - oldAttrs.buildInputs ++ [ + oldAttrs.buildInputs + ++ [ (python.withPackages (pypkgs: [ # probe_py.manual runtime requirements pypkgs.networkx @@ -135,20 +140,12 @@ pkgs.black pkgs.ruff ] - ++ ( - # gdb broken on apple silicon - if system != "aarch64-darwin" - then [pkgs.gdb] - else [] - ) - ++ ( - # while xdot isn't marked as linux only, it has a dependency (xvfb-run) that is - if builtins.elem system pkgs.lib.platforms.linux - then [pkgs.xdot] - else [] - ); + # gdb broken on apple silicon + ++ pkgs.lib.lists.optional (system != "aarch64-darwin") pkgs.gdb + # while xdot isn't marked as linux only, it has a dependency (xvfb-run) that is + ++ pkgs.lib.lists.optional (builtins.elem system pkgs.lib.platforms.linux) pkgs.xdot; }); }; - } + } ); } diff --git a/probe_src/probe_frontend/Cargo.lock b/probe_src/frontend/Cargo.lock similarity index 100% rename from probe_src/probe_frontend/Cargo.lock rename to probe_src/frontend/Cargo.lock diff --git a/probe_src/probe_frontend/Cargo.toml b/probe_src/frontend/Cargo.toml similarity index 100% rename from probe_src/probe_frontend/Cargo.toml rename to probe_src/frontend/Cargo.toml diff --git a/probe_src/probe_frontend/LICENSE b/probe_src/frontend/LICENSE similarity index 100% rename from probe_src/probe_frontend/LICENSE rename to probe_src/frontend/LICENSE diff --git a/probe_src/probe_frontend/README.md b/probe_src/frontend/README.md similarity index 100% rename from probe_src/probe_frontend/README.md rename to probe_src/frontend/README.md diff --git a/probe_src/probe_frontend/cli/Cargo.toml b/probe_src/frontend/cli/Cargo.toml similarity index 100% rename from probe_src/probe_frontend/cli/Cargo.toml rename to probe_src/frontend/cli/Cargo.toml diff --git a/probe_src/probe_frontend/cli/src/dump.rs b/probe_src/frontend/cli/src/dump.rs similarity index 100% rename from probe_src/probe_frontend/cli/src/dump.rs rename to probe_src/frontend/cli/src/dump.rs diff --git a/probe_src/probe_frontend/cli/src/main.rs b/probe_src/frontend/cli/src/main.rs similarity index 100% rename from probe_src/probe_frontend/cli/src/main.rs rename to probe_src/frontend/cli/src/main.rs diff --git a/probe_src/probe_frontend/cli/src/record.rs b/probe_src/frontend/cli/src/record.rs similarity index 100% rename from probe_src/probe_frontend/cli/src/record.rs rename to probe_src/frontend/cli/src/record.rs diff --git a/probe_src/probe_frontend/cli/src/transcribe.rs b/probe_src/frontend/cli/src/transcribe.rs similarity index 100% rename from probe_src/probe_frontend/cli/src/transcribe.rs rename to probe_src/frontend/cli/src/transcribe.rs diff --git a/probe_src/probe_frontend/cli/src/util.rs b/probe_src/frontend/cli/src/util.rs similarity index 100% rename from probe_src/probe_frontend/cli/src/util.rs rename to probe_src/frontend/cli/src/util.rs diff --git a/probe_src/probe_frontend/deny.toml b/probe_src/frontend/deny.toml similarity index 100% rename from probe_src/probe_frontend/deny.toml rename to probe_src/frontend/deny.toml diff --git a/probe_src/frontend/frontend.nix b/probe_src/frontend/frontend.nix new file mode 100644 index 00000000..4a82270f --- /dev/null +++ b/probe_src/frontend/frontend.nix @@ -0,0 +1,191 @@ +{ + self, + pkgs, + crane, + advisory-db, + system, + python, + ... +}: let + systems = { + # "nix system" = "rust target"; + "x86_64-linux" = "x86_64-unknown-linux-musl"; + "i686-linux" = "i686-unknown-linux-musl"; + "aarch64-linux" = "aarch64-unknown-linux-musl"; + "armv7l-linux" = "armv7-unknown-linux-musleabi"; + }; + craneLib = (crane.mkLib pkgs).overrideToolchain (p: + p.rust-bin.stable.latest.default.override { + targets = [systems.${system}]; + }); + + src = ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + + # all the crates in this workspace either use rust-bindgen or depend + # on local crate that does. + nativeBuildInputs = [ + pkgs.rustPlatform.bindgenHook + ]; + + # pygen needs to know where to write the python file + preConfigurePhases = [ + "pygenConfigPhase" + ]; + pygenConfigPhase = '' + export PYGEN_OUTFILE="$(realpath ./python/probe_py/generated/ops.py)" + ''; + + CARGO_BUILD_TARGET = systems.${system}; + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; + CPATH = ../libprobe/include; + }; + + # Build *just* the cargo dependencies (of the entire workspace), + # so we can reuse all of that work (e.g. via cachix) when running in CI + # It is *highly* recommended to use something like cargo-hakari to avoid + # cache misses when building individual top-level-crates + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + individualCrateArgs = + commonArgs + // { + # inherit cargoArtifacts; + inherit (craneLib.crateNameFromCargoToml {inherit src;}) version; + # disable tests since we'll run them all via cargo-nextest + doCheck = false; + }; + + # Build the top-level crates of the workspace as individual derivations. + # This allows consumers to only depend on (and build) only what they need. + # Though it is possible to build the entire workspace as a single derivation, + # so this is left up to you on how to organize things + probe-frontend = craneLib.buildPackage (individualCrateArgs + // { + pname = "probe-frontend"; + cargoExtraArgs = "-p probe_frontend"; + installPhase = '' + cp -r ./python/ $out + cp ./LICENSE $out/LICENSE + ''; + }); + probe-py-generated = let + workspace = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace; + + # TODO: Simplify this + # Perhaps by folding the substituteAllFiles into probe-py-generated (upstream) or probe-py-frontend (downstream) + # Could we combine all the packages? + probe-py-generated-src = pkgs.substituteAllFiles rec { + name = "probe-py-${version}"; + src = probe-frontend; + files = [ + "./pyproject.toml" + "./LICENSE" + "./probe_py/generated/__init__.py" + "./probe_py/generated/ops.py" + "./probe_py/generated/parser.py" + ]; + + authors = builtins.concatStringsSep "" (builtins.map (match: let + name = builtins.elemAt match 0; + email = builtins.elemAt match 1; + in "\n {name = \"${name}\", email = \"${email}\"},") ( + builtins.map + (author-str: builtins.match "(.+) <(.+)>" author-str) + (workspace.package.authors) + )); + version = workspace.package.version; + }; + in + python.pkgs.buildPythonPackage rec { + pname = "probe_py.generated"; + version = probe-py-generated-src.version; + pyproject = true; + build-system = [ + python.pkgs.flit-core + ]; + unpackPhase = '' + cp --recursive ${probe-py-generated-src}/* /build + ''; + pythonImportsCheck = [pname]; + }; + probe-cli = craneLib.buildPackage (individualCrateArgs + // { + pname = "probe-cli"; + cargoExtraArgs = "-p probe_cli"; + }); + probe-macros = craneLib.buildPackage (individualCrateArgs + // { + pname = "probe-macros"; + cargoExtraArgs = "-p probe_macros"; + }); +in { + checks = { + # Build the crates as part of `nix flake check` for convenience + inherit probe-frontend probe-py-generated probe-cli probe-macros; + + # Run clippy (and deny all warnings) on the workspace source, + # again, reusing the dependency artifacts from above. + # + # Note that this is done as a separate derivation so that + # we can block the CI if there are issues here, but not + # prevent downstream consumers from building our crate by itself. + probe-workspace-clippy = craneLib.cargoClippy (commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + probe-workspace-doc = craneLib.cargoDoc (commonArgs + // { + inherit cargoArtifacts; + }); + + # Check formatting + probe-workspace-fmt = craneLib.cargoFmt { + inherit src; + }; + + # Audit dependencies + probe-workspace-audit = craneLib.cargoAudit { + inherit src advisory-db; + }; + + # Audit licenses + probe-workspace-deny = craneLib.cargoDeny { + inherit src; + }; + + # Run tests with cargo-nextest + # this is why `doCheck = false` on the crate derivations, so as to not + # run the tests twice. + probe-workspace-nextest = craneLib.cargoNextest (commonArgs + // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + }); + }; + + packages = { + inherit probe-cli probe-py-generated probe-frontend probe-macros; + }; + + devShells.default = craneLib.devShell { + # Inherit inputs from checks. + checks = self.checks.${system}; + + packages = [ + pkgs.cargo-audit + pkgs.cargo-expand + pkgs.cargo-flamegraph + pkgs.cargo-watch + pkgs.gdb + pkgs.rust-analyzer + ]; + }; +} diff --git a/probe_src/probe_frontend/lib/Cargo.toml b/probe_src/frontend/lib/Cargo.toml similarity index 100% rename from probe_src/probe_frontend/lib/Cargo.toml rename to probe_src/frontend/lib/Cargo.toml diff --git a/probe_src/probe_frontend/lib/build.rs b/probe_src/frontend/lib/build.rs similarity index 100% rename from probe_src/probe_frontend/lib/build.rs rename to probe_src/frontend/lib/build.rs diff --git a/probe_src/probe_frontend/lib/src/error.rs b/probe_src/frontend/lib/src/error.rs similarity index 100% rename from probe_src/probe_frontend/lib/src/error.rs rename to probe_src/frontend/lib/src/error.rs diff --git a/probe_src/probe_frontend/lib/src/lib.rs b/probe_src/frontend/lib/src/lib.rs similarity index 100% rename from probe_src/probe_frontend/lib/src/lib.rs rename to probe_src/frontend/lib/src/lib.rs diff --git a/probe_src/probe_frontend/lib/src/metadata.rs b/probe_src/frontend/lib/src/metadata.rs similarity index 100% rename from probe_src/probe_frontend/lib/src/metadata.rs rename to probe_src/frontend/lib/src/metadata.rs diff --git a/probe_src/probe_frontend/lib/src/ops.rs b/probe_src/frontend/lib/src/ops.rs similarity index 100% rename from probe_src/probe_frontend/lib/src/ops.rs rename to probe_src/frontend/lib/src/ops.rs diff --git a/probe_src/probe_frontend/lib/src/transcribe.rs b/probe_src/frontend/lib/src/transcribe.rs similarity index 100% rename from probe_src/probe_frontend/lib/src/transcribe.rs rename to probe_src/frontend/lib/src/transcribe.rs diff --git a/probe_src/probe_frontend/macros/Cargo.toml b/probe_src/frontend/macros/Cargo.toml similarity index 100% rename from probe_src/probe_frontend/macros/Cargo.toml rename to probe_src/frontend/macros/Cargo.toml diff --git a/probe_src/probe_frontend/macros/src/lib.rs b/probe_src/frontend/macros/src/lib.rs similarity index 100% rename from probe_src/probe_frontend/macros/src/lib.rs rename to probe_src/frontend/macros/src/lib.rs diff --git a/probe_src/probe_frontend/macros/src/pygen.rs b/probe_src/frontend/macros/src/pygen.rs similarity index 100% rename from probe_src/probe_frontend/macros/src/pygen.rs rename to probe_src/frontend/macros/src/pygen.rs diff --git a/probe_src/probe_frontend/python/probe_py/__init__.py b/probe_src/frontend/python/probe_py/__init__.py similarity index 100% rename from probe_src/probe_frontend/python/probe_py/__init__.py rename to probe_src/frontend/python/probe_py/__init__.py diff --git a/probe_src/probe_frontend/python/probe_py/generated/__init__.py b/probe_src/frontend/python/probe_py/generated/__init__.py similarity index 100% rename from probe_src/probe_frontend/python/probe_py/generated/__init__.py rename to probe_src/frontend/python/probe_py/generated/__init__.py diff --git a/probe_src/probe_frontend/python/probe_py/generated/ops.py b/probe_src/frontend/python/probe_py/generated/ops.py similarity index 100% rename from probe_src/probe_frontend/python/probe_py/generated/ops.py rename to probe_src/frontend/python/probe_py/generated/ops.py diff --git a/probe_src/probe_frontend/python/probe_py/generated/parser.py b/probe_src/frontend/python/probe_py/generated/parser.py similarity index 100% rename from probe_src/probe_frontend/python/probe_py/generated/parser.py rename to probe_src/frontend/python/probe_py/generated/parser.py diff --git a/probe_src/probe_frontend/python/pyproject.toml b/probe_src/frontend/python/pyproject.toml similarity index 100% rename from probe_src/probe_frontend/python/pyproject.toml rename to probe_src/frontend/python/pyproject.toml diff --git a/probe_src/probe_frontend/frontend.nix b/probe_src/probe_frontend/frontend.nix deleted file mode 100644 index 682652ee..00000000 --- a/probe_src/probe_frontend/frontend.nix +++ /dev/null @@ -1,191 +0,0 @@ -{ - self, - pkgs, - crane, - advisory-db, - system, - python, - ... -}: -let - systems = { - # "nix system" = "rust target"; - "x86_64-linux" = "x86_64-unknown-linux-musl"; - "i686-linux" = "i686-unknown-linux-musl"; - "aarch64-linux" = "aarch64-unknown-linux-musl"; - "armv7l-linux" = "armv7-unknown-linux-musleabi"; - }; - craneLib = (crane.mkLib pkgs).overrideToolchain (p: - p.rust-bin.stable.latest.default.override { - targets = [systems.${system}]; - }); - - src = ./.; - - # Common arguments can be set here to avoid repeating them later - commonArgs = { - inherit src; - strictDeps = true; - - # all the crates in this workspace either use rust-bindgen or depend - # on local crate that does. - nativeBuildInputs = [ - pkgs.rustPlatform.bindgenHook - ]; - - # pygen needs to know where to write the python file - preConfigurePhases = [ - "pygenConfigPhase" - ]; - pygenConfigPhase = '' - export PYGEN_OUTFILE="$(realpath ./python/probe_py/generated/ops.py)" - ''; - - CARGO_BUILD_TARGET = systems.${system}; - CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; - CPATH = ../libprobe/include; - }; - - # Build *just* the cargo dependencies (of the entire workspace), - # so we can reuse all of that work (e.g. via cachix) when running in CI - # It is *highly* recommended to use something like cargo-hakari to avoid - # cache misses when building individual top-level-crates - cargoArtifacts = craneLib.buildDepsOnly commonArgs; - - individualCrateArgs = - commonArgs - // { - # inherit cargoArtifacts; - inherit (craneLib.crateNameFromCargoToml {inherit src;}) version; - # disable tests since we'll run them all via cargo-nextest - doCheck = false; - }; - - # Build the top-level crates of the workspace as individual derivations. - # This allows consumers to only depend on (and build) only what they need. - # Though it is possible to build the entire workspace as a single derivation, - # so this is left up to you on how to organize things - probe-frontend = craneLib.buildPackage (individualCrateArgs - // { - pname = "probe-frontend"; - cargoExtraArgs = "-p probe_frontend"; - installPhase = '' - cp -r ./python/ $out - cp ./LICENSE $out/LICENSE - ''; - }); - probe-py-generated = let - workspace = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace; - - # TODO: Simplify this - # Perhaps by folding the substituteAllFiles into probe-py-generated (upstream) or probe-py-frontend (downstream) - # Could we combine all the packages? - probe-py-generated-src = pkgs.substituteAllFiles rec { - name = "probe-py-${version}"; - src = probe-frontend; - files = [ - "./pyproject.toml" - "./LICENSE" - "./probe_py/generated/__init__.py" - "./probe_py/generated/ops.py" - "./probe_py/generated/parser.py" - ]; - - authors = builtins.concatStringsSep "" (builtins.map (match: let - name = builtins.elemAt match 0; - email = builtins.elemAt match 1; - in "\n {name = \"${name}\", email = \"${email}\"},") ( - builtins.map - (author-str: builtins.match "(.+) <(.+)>" author-str) - (workspace.package.authors) - )); - version = workspace.package.version; - }; - in python.pkgs.buildPythonPackage rec { - pname = "probe_py.generated"; - version = probe-py-generated-src.version; - pyproject = true; - build-system = [ - python.pkgs.flit-core - ]; - unpackPhase = '' - cp --recursive ${probe-py-generated-src}/* /build - ''; - pythonImportsCheck = [ pname ]; - }; - probe-cli = craneLib.buildPackage (individualCrateArgs - // { - pname = "probe-cli"; - cargoExtraArgs = "-p probe_cli"; - }); - probe-macros = craneLib.buildPackage (individualCrateArgs - // { - pname = "probe-macros"; - cargoExtraArgs = "-p probe_macros"; - }); - in { - checks = { - # Build the crates as part of `nix flake check` for convenience - inherit probe-frontend probe-py-generated probe-cli probe-macros; - - # Run clippy (and deny all warnings) on the workspace source, - # again, reusing the dependency artifacts from above. - # - # Note that this is done as a separate derivation so that - # we can block the CI if there are issues here, but not - # prevent downstream consumers from building our crate by itself. - probe-workspace-clippy = craneLib.cargoClippy (commonArgs - // { - inherit cargoArtifacts; - cargoClippyExtraArgs = "--all-targets -- --deny warnings"; - }); - - probe-workspace-doc = craneLib.cargoDoc (commonArgs - // { - inherit cargoArtifacts; - }); - - # Check formatting - probe-workspace-fmt = craneLib.cargoFmt { - inherit src; - }; - - # Audit dependencies - probe-workspace-audit = craneLib.cargoAudit { - inherit src advisory-db; - }; - - # Audit licenses - probe-workspace-deny = craneLib.cargoDeny { - inherit src; - }; - - # Run tests with cargo-nextest - # this is why `doCheck = false` on the crate derivations, so as to not - # run the tests twice. - probe-workspace-nextest = craneLib.cargoNextest (commonArgs - // { - inherit cargoArtifacts; - partitions = 1; - partitionType = "count"; - }); - }; - - packages = { - inherit probe-cli probe-py-generated probe-frontend probe-macros; - }; - - devShells.default = craneLib.devShell { - # Inherit inputs from checks. - checks = self.checks.${system}; - - packages = [ - pkgs.cargo-audit - pkgs.cargo-expand - pkgs.cargo-flamegraph - pkgs.cargo-watch - pkgs.gdb - pkgs.rust-analyzer - ]; - }; - } diff --git a/setup_devshell.sh b/setup_devshell.sh index 82c07bf4..419703a4 100644 --- a/setup_devshell.sh +++ b/setup_devshell.sh @@ -18,19 +18,19 @@ fi # Rust code uses PYGEN_OUTFILE to determine where to write this file. # TODO: Replace this with a static path, because it is never not this path. -export PYGEN_OUTFILE="$project_root/probe_src/probe_frontend/python/probe_py/generated/ops.py" +export PYGEN_OUTFILE="$project_root/probe_src/frontend/python/probe_py/generated/ops.py" # Ensure PROBE CLI gets built -if [ ! -f $project_root/probe_src/probe_frontend/target/release/probe ]; then +if [ ! -f $project_root/probe_src/frontend/target/release/probe ]; then echo -e "${red}Please run 'just compile-cli' to compile probe binary${clr}" fi # Add PROBE CLI to path -export PATH="$project_root/probe_src/probe_frontend/target/release:$PATH" +export PATH="$project_root/probe_src/frontend/target/release:$PATH" # Add probe_py.generated to the Python path -export PYTHONPATH="$project_root/probe_src/probe_frontend/python:$PYTHONPATH" -export MYPYPATH="$project_root/probe_src/probe_frontend/python:$MYPYPATH" +export PYTHONPATH="$project_root/probe_src/frontend/python:$PYTHONPATH" +export MYPYPATH="$project_root/probe_src/frontend/python:$MYPYPATH" # Add probe_py.manual to the Python path export PYTHONPATH="$project_root/probe_src/python:$PYTHONPATH"