Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glue libprobe and probe_frontend together #36

Merged
merged 18 commits into from
Aug 4, 2024
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
**/.directory
**/.Trash*
**/desktop.ini

probe_log
38 changes: 28 additions & 10 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,43 @@ check-ruff:
#ruff format --check probe_src # TODO: uncomment
ruff check probe_src

check-format-rust:
env --chdir probe_src/probe_frontend cargo fmt --check

fix-format-rust:
env --chdir probe_src/probe_frontend cargo fmt

check-clippy:
env --chdir probe_src/probe_frontend cargo clippy

fix-clippy:
env --chdir probe_src/probe_frontend cargo clippy --fix --allow-staged

check-mypy:
MYPYPATH=probe_src mypy --strict --package arena
MYPYPATH=probe_src mypy --strict --package probe_py
mypy --strict --package probe_py.manual
mypy --strict --package probe_py.generated
mypy --strict probe_src/libprobe

compile-libprobe:
compile-lib:
make --directory=probe_src/libprobe all

test-ci: compile-libprobe
make --directory=probe_src/tests/c all
cd probe_src && python -m pytest .
compile-cli:
env --chdir=probe_src/probe_frontend cargo build --release

test-dev: compile-libprobe
compile-tests:
make --directory=probe_src/tests/c all
cd probe_src && python -m pytest . --failed-first --maxfail=1

compile: compile-lib compile-cli compile-tests

test-ci: compile-lib
pytest probe_src

test-dev: compile-lib
pytest probe_src --failed-first --maxfail=1

check-flake:
nix flake check --all-systems

pre-commit: fix-format-nix fix-ruff check-mypy check-flake compile-libprobe test-dev
pre-commit: fix-format-nix fix-ruff fix-format-rust fix-clippy compile check-mypy test-dev

on-push: check-format-nix check-ruff check-mypy check-flake compile-libprobe test-ci
on-push: check-format-nix check-ruff check-format-rust check-clippy compile check-mypy check-flake test-ci
77 changes: 70 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 113 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,51 +1,127 @@
{
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
flake-utils = {
url = "github:numtide/flake-utils";
};

crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};

advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};

rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
python312-debug = pkgs.python312.overrideAttrs (oldAttrs: {
configureFlags = oldAttrs.configureFlags ++ ["--with-pydebug"];
# patches = oldAttrs.patches ++ [ ./python.patch ];
});
export-and-rename = pkg: file-pairs:
pkgs.stdenv.mkDerivation {
pname = "${pkg.pname}-only-bin";
rust-overlay,
...
}@inputs: let
supported-systems = [
"x86_64-linux"
"i686-linux"
"aarch64-linux"
"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";
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;
version = pkg.version;
buildInputs = [pkg];
buildPhase =
builtins.concatStringsSep
"\n"
(builtins.map
(pairs: "install -D ${pkg}/${builtins.elemAt pairs 0} $out/${builtins.elemAt pairs 1}")
file-pairs);
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
'';
};
in {
packages = {
python-dbg = python312-debug;
};
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;
# TODO: Run pytest tests in Nix checks
checks = self.packages.${system} // frontend.checks;
devShells = {
default = pkgs.mkShell {
default = frontend.devShells.default.overrideAttrs (oldAttrs: rec {
shellHook = ''
pushd $(git rev-parse --show-toplevel)
source ./setup_devshell.sh
popd
'';
buildInputs =
[
(pkgs.python312.withPackages (pypkgs: [
pypkgs.psutil
oldAttrs.buildInputs ++ [
(python.withPackages (pypkgs: [
# probe_py.manual runtime requirements
pypkgs.networkx
pypkgs.pygraphviz
pypkgs.pydot
pypkgs.rich
pypkgs.typer
pypkgs.pycparser

# probe_py.manual "dev time" requirements
pypkgs.psutil
pypkgs.pytest
pypkgs.mypy
pypkgs.pygraphviz
pypkgs.networkx
pypkgs.ipython
pypkgs.pydot
pypkgs.rich

# libprobe build time requirement
pypkgs.pycparser
]))
# (export-and-rename python312-debug [["bin/python" "bin/python-dbg"]])
pkgs.which
Expand All @@ -67,12 +143,12 @@
)
++ (
# while xdot isn't marked as linux only, it has a dependency (xvfb-run) that is
if builtins.elem system lib.platforms.linux
if builtins.elem system pkgs.lib.platforms.linux
then [pkgs.xdot]
else []
);
};
});
};
}
}
);
}
5 changes: 0 additions & 5 deletions probe_src/PROBE

This file was deleted.

20 changes: 11 additions & 9 deletions probe_src/libprobe/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
SOURCE_VERSION ?= $(shell git rev-parse --short HEAD)
CFLAGS ?= -DSOURCE_VERSION=\"$(SOURCE_VERSION)\" -Wno-cast-function-type -Wno-array-parameter -ffreestanding -Wl,--as-needed -Wall -Wextra -pthread
DBGCFLAGS ?= $(CFLAGS) -Og -g
OPTCFLAGS ?= $(CFLAGS) -O3 -DNDEBUG
LIBCFLAGS ?= -fPIC -nostdlib -shared
SOURCE_FILES := $(wildcard src/*.c) $(wildcard include/*.h)
CFLAGS ?= -DSOURCE_VERSION=\"$(SOURCE_VERSION)\" -Wno-cast-function-type -Wno-array-parameter -ffreestanding -Wl,--as-needed -Wall -Wextra -pthread -fPIC -nostdlib -shared $(NIX_CFLAGS_COMPILE)
DBGCFLAGS ?= -Og -g
OPTCFLAGS ?= -O3 -DNDEBUG

SOURCE_FILES := $(wildcard src/*.c) $(wildcard include/*.h)
GENERATED_FILES := generated/libc_hooks.c generated/libc_hooks.h
ALL_TARGETS := build/libprobe-dbg.so build/libprobe.so

all: $(ALL_TARGETS)
.PHONY: all

build/lib%.so: $(SOURCE_FILES) $(GENERATED_FILES)
mkdir --parents build/
gcc $(OPTCFLAGS) $(LIBCFLAGS) -o $@ src/lib.c
mkdir --parents build
gcc $(CFLAGS) $(OPTCFLAGS) -o $@ src/lib.c

build/lib%-dbg.so: $(SOURCE_FILES) $(GENERATED_FILES)
mkdir --parents build/
gcc $(DBGCFLAGS) $(LIBCFLAGS) -o $@ src/lib.c
mkdir --parents build
gcc $(CFLAGS) $(DBGCFLAGS) -o $@ src/lib.c

$(GENERATED_FILES): $(wildcard generator/*)
./generator/gen_libc_hooks.py

install:
install -D --target-directory $(INSTALL_PREFIX)/lib/ build/lib*.so

clean:
mkdir --parents build/ generated/
touch $(GENERATED_FILES) $(ALL_TARGETS)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef ARENA
#define ARENA
#pragma once

#define _GNU_SOURCE
#ifdef PYCPARSER
Expand Down Expand Up @@ -334,5 +333,3 @@ __attribute__((unused)) static bool arena_is_initialized(struct ArenaDir* arena_
);
return arena_dir->__tail != NULL;
}

#endif // ARENA
File renamed without changes.
Loading
Loading