Skip to content

Commit

Permalink
feat: added flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
Maix0 committed Nov 17, 2024
1 parent d4e7f55 commit 014cb8e
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 1 deletion.
57 changes: 57 additions & 0 deletions flake.lock

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

57 changes: 57 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
);
}
20 changes: 19 additions & 1 deletion host/srcs/run/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#define RELATIVE_LIBRARY_PATH "../library/libfuncheck.so"

#ifndef ABSOLUTE_LIBRARY_PATH

/**
* @brief Get the absolute path of the library
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -166,4 +184,4 @@ int run(t_run_info *run_info)
}
}
return pid;
}
}

0 comments on commit 014cb8e

Please sign in to comment.