diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7757b6f --- /dev/null +++ b/flake.lock @@ -0,0 +1,57 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 0, + "narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=", + "path": "/nix/store/zq2axpgzd5kykk1v446rkffj3bxa2m2h-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e13b4df --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "Flake utils demo"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + llvm = pkgs.llvm_18; + funcheck_drv = pkgs.stdenv.mkDerivation (final: { + pname = "funcheck"; + version = "1.1.4"; + src = ./.; + nativeBuildInputs = [pkgs.makeWrapper pkgs.minilibx pkgs.gnumake pkgs.xorg.libX11]; + buildInputs = [llvm]; + buildPhase = '' + substituteInPlace host/srcs/run/runner.c \ + --replace-fail "../library/libfuncheck.so" "" + + # TODO: remove this when I take time to check wtf is happening + + echo "" >library/srcs/hook/functions/stdio.c + export CFLAGS="-Werror -Wextra -Wall -Wno-stringop-truncation \ + -Wno-attributes -Wno-array-parameter -Wno-unused-result \ + -DABSOLUTE_LIBRARY_PATH=\\\"$out/share/funcheck/libfuncheck.so\\\" \ + -g -fPIC -fvisibility=hidden" + make -C library "CC=$CC" "CFLAGS=$CFLAGS" "VERSION=${final.version}-nix" + make -C host "CC=$CC" "CFLAGS=$CFLAGS" "VERSION=${final.version}-nix" + ''; + installPhase = '' + mkdir -p "$out/bin" + mkdir -p "$out/share/funcheck" + cp ./host/funcheck "$out/bin/funcheck" + cp ./library/libfuncheck.so "$out/share/funcheck/libfuncheck.so" + wrapProgram $out/bin/funcheck \ + --prefix PATH : ${pkgs.lib.makeBinPath [llvm]} + ''; + }); + in { + packages = rec { + funcheck = default; + default = funcheck_drv; + }; + apps = rec { + funcheck = flake-utils.lib.mkApp {drv = self.packages.${system}.funcheck;}; + default = funcheck; + }; + } + ); +} diff --git a/host/srcs/run/runner.c b/host/srcs/run/runner.c index 0783ec5..9f9d831 100644 --- a/host/srcs/run/runner.c +++ b/host/srcs/run/runner.c @@ -33,6 +33,8 @@ #define RELATIVE_LIBRARY_PATH "../library/libfuncheck.so" +#ifndef ABSOLUTE_LIBRARY_PATH + /** * @brief Get the absolute path of the library * @@ -62,6 +64,22 @@ static char *get_library_path(void) return path; } +#else + +/** + * @brief Get the absolute path of the library + * + * @return char* the absolute path of the library + * @note Why does this exists ? Because if the packaging needs to force + * an library path to be absolute it is needed + */ +static char *get_library_path(void) +{ + return ABSOLUTE_LIBRARY_PATH; +} + +#endif + /** * @brief Generate resources for the runner * @@ -166,4 +184,4 @@ int run(t_run_info *run_info) } } return pid; -} \ No newline at end of file +}