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 3 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
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.

131 changes: 106 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,117 @@
{
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,
crane,
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";
advisory-db,
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)];
};
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";
dontUnpack = true;
version = pkg.version;
buildInputs = [ pkg ];
buildPhase =
"\n"
(builtins.map
(pairs: "install -D ${pkg}/${builtins.elemAt pairs 0} $out/${builtins.elemAt pairs 1}")
file-pairs);
};
rust-stuff = (import ./probe_src/probe_frontend/rust-stuff.nix) ({ inherit system pkgs; } // inputs);
in {
packages = rec {
python-dbg = python312-debug;
libprobe-interface = pkgs.stdenv.mkDerivation {
pname = "libprobe-interface";
version = "0.1.0";
src = ./probe_src/libprobe-interface;
dontBuild = true;
installPhase = ''
install -D --target-directory $out/include/libprobe *.h
'';
};
arena = pkgs.stdenv.mkDerivation {
pname = "arena";
version = "0.1.0";
src = ./probe_src/arena;
dontBuild = true;
installPhase = ''
install -D --target-directory $out/include/arena *.h
'';
};
libprobe = pkgs.stdenv.mkDerivation rec {
pname = "libprobe";
version = "0.1.0";
src = ./probe_src/libprobe;
makeFlags = [ "INSTALL_PREFIX=$(out)" "SOURCE_VERSION=${version}" ];
buildInputs = [
libprobe-interface
arena
(pkgs.python312.withPackages (pypkgs: [
pypkgs.pycparser
]))
];
};
probe-bundled = 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 ${self.packages.${system}.libprobe}/lib
'';
};
in {
packages = {
python-dbg = python312-debug;
};
} // rust-stuff.packages;
checks = self.packages.${system} // rust-stuff.checks;
devShells = {
default = pkgs.mkShell {
buildInputs =
Expand Down
5 changes: 1 addition & 4 deletions probe_src/arena/arena.c → probe_src/arena/arena.h
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
2 changes: 1 addition & 1 deletion probe_src/arena/test_arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string.h>
#include <sys/stat.h>
#define ARENA_PERROR
#include "arena.c"
#include "arena.h"

int main() {
struct stat stat_buf;
Expand Down
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
4 changes: 2 additions & 2 deletions probe_src/libprobe/src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ static __thread bool __thread_inited = false;

/* #include "fd_table.c" */

#include "../include/prov_ops.h"
#include <libprobe/prov_ops.h>

#define ARENA_USE_UNWRAPPED_LIBC
#define ARENA_PERROR
#include "../../arena/arena.c"
#include <arena/arena.h>

#include "global_state.c"

Expand Down
7 changes: 0 additions & 7 deletions probe_src/probe_frontend/configure

This file was deleted.

Loading
Loading