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

feat: added flake.nix #107

Merged
merged 3 commits into from
Nov 18, 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ If you you want to update the tool, you can run the same command.

You can now use the `funcheck` command. (run `funcheck --help` for more information how to use it)

## Nix flake support

If you have the nix package manager installed, you can run funcheck using this command

```bash
nix nix --extra-experimental-features "flakes nix-command" run github:froz42/funcheck
```

this will build funcheck onto your machine, and install llvm-symbolizer (thought it will use the one in your `PATH` by default)

## Build instructions

### Requirements
Expand Down
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.

76 changes: 76 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
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;
#commit = pkgs.lib.removeSuffix "-dirty" self.dirtyShortRev;
commit = builtins.substring 0 12 (pkgs.lib.removeSuffix "-dirty" self.dirtyRev);
funcheck_drv = pkgs.stdenv.mkDerivation (final: {
pname = "funcheck";
version = commit;
src = ./.;
patches = [
(
builtins.toFile
"remove_fwrite_unlocked.patch"
''
diff --git a/library/srcs/hook/functions/stdio.c b/library/srcs/hook/functions/stdio.c
index dbb9e2a..2d6b9dd 100644
--- a/library/srcs/hook/functions/stdio.c
+++ b/library/srcs/hook/functions/stdio.c
@@ -104,7 +104,7 @@ DEFINE_HOOK_FUNCTION(size_t, fwrite, EIO, 0, const void *, ptr, size_t, size, si

DEFINE_HOOK_FUNCTION(int, fputs_unlocked, EIO, 0, const char *, s, FILE *, stream);
DEFINE_HOOK_FUNCTION(size_t, fread_unlocked, EIO, 0, void *, ptr, size_t, size, size_t, nmemb, FILE *, stream);
-DEFINE_HOOK_FUNCTION(size_t, fwrite_unlocked, EIO, 0, const void *, ptr, size_t, size, size_t, nmemb, FILE *, stream);
+//DEFINE_HOOK_FUNCTION(size_t, fwrite_unlocked, EIO, 0, const void *, ptr, size_t, size, size_t, nmemb, FILE *, stream);

DEFINE_HOOK_FUNCTION(int, fseek, EIO, -1, FILE *, stream, long, offset, int, whence);
DEFINE_HOOK_FUNCTION(long, ftell, EIO, -1, FILE *, stream);

''
)
];
nativeBuildInputs = [pkgs.makeWrapper pkgs.minilibx pkgs.gnumake pkgs.xorg.libX11];
buildInputs = [llvm];
buildPhase = ''
ls -la
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}"
make -C host "CC=$CC" "CFLAGS=$CFLAGS" "VERSION=${final.version}"
'';
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;
}
}
Loading