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

nix: add asan shell #4443

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 44 additions & 1 deletion nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{ self', pkgs, rustToolchain, ... }:
{ self', pkgs, system, rustToolchain, ... }:

let
devToolchain = rustToolchain.default.override { extensions = [ "rust-analyzer" "rust-src" ]; };
nodejs = pkgs.nodejs_latest;

asanToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "rust-src" ];
});

targetTripleMap = {
"x86_64-linux" = "x86_64-unknown-linux-gnu";
"x86_64-darwin" = "x86_64-apple-darwin";
"aarch64-linux" = "aarch64-unknown-linux-gnu";
"aarch64-darwin" = "aarch64-apple-darwin";
};
in
{
devShells.default = pkgs.mkShell {
Expand All @@ -18,4 +29,36 @@ in
shellHook = pkgs.lib.optionalString pkgs.stdenv.isLinux
"export RUSTFLAGS='-C link-arg=-fuse-ld=lld'";
};

devShells.asan = pkgs.mkShell {
inputsFrom = [ self'.packages.prisma-engines ];

packages = [
asanToolchain
];

shellHook = ''
export RUSTFLAGS="-Zsanitizer=address"
export RUSTDOCFLAGS="-Zsanitizer=address"
export CFLAGS="-fsanitize=address"
export CXXFLAGS="-fsanitize=address"
export LDFLAGS="-fsanitize=address"
alias cargo-asan-build="${asanToolchain}/bin/cargo build -Zbuild-std --target ${targetTripleMap.${system}}"
'';
};

devShells.asan-node = pkgs.mkShell {
packages = [
nodejs
nodejs.pkgs.pnpm
];

shellHook =
if pkgs.stdenv.isDarwin then ''
export DYLD_INSERT_LIBRARIES=${asanToolchain}/lib/rustlib/aarch64-apple-darwin/lib/librustc-nightly_rt.asan.dylib
''
else ''
export LD_PRELOAD=$(gcc --print-file-name=libasan.so)
'';
};
}
Loading