Skip to content

Commit a491173

Browse files
committed
packaging: Add withASan,withUBSan options to the scope
1 parent 199b6ff commit a491173

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

ci/gha/tests/default.nix

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ let
2323
packages' = nixFlake.packages.${system};
2424
stdenv = (getStdenv pkgs);
2525

26-
enableSanitizersLayer = finalAttrs: prevAttrs: {
27-
mesonFlags =
28-
(prevAttrs.mesonFlags or [ ])
29-
++ [ (lib.mesonOption "b_sanitize" "address,undefined") ]
30-
++ (lib.optionals stdenv.cc.isClang [
31-
# https://www.github.com/mesonbuild/meson/issues/764
32-
(lib.mesonBool "b_lundef" false)
33-
]);
34-
};
35-
3626
collectCoverageLayer = finalAttrs: prevAttrs: {
3727
env =
3828
let
@@ -55,14 +45,15 @@ let
5545
'';
5646
};
5747

58-
componentOverrides =
59-
(lib.optional withSanitizers enableSanitizersLayer)
60-
++ (lib.optional withCoverage collectCoverageLayer);
48+
componentOverrides = (lib.optional withCoverage collectCoverageLayer);
6149
in
6250

6351
rec {
6452
nixComponentsInstrumented = nixComponents.overrideScope (
6553
final: prev: {
54+
withASan = withSanitizers;
55+
withUBSan = withSanitizers;
56+
6657
nix-store-tests = prev.nix-store-tests.override { withBenchmarks = true; };
6758
# Boehm is incompatible with ASAN.
6859
nix-expr = prev.nix-expr.override { enableGC = !withSanitizers; };

packaging/components.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,25 @@ let
204204
mesonFlags = [ (lib.mesonBool "b_asneeded" false) ] ++ prevAttrs.mesonFlags or [ ];
205205
};
206206

207+
enableSanitizersLayer =
208+
finalAttrs: prevAttrs:
209+
let
210+
sanitizers = lib.optional scope.withASan "address" ++ lib.optional scope.withUBSan "undefined";
211+
in
212+
{
213+
mesonFlags =
214+
(prevAttrs.mesonFlags or [ ])
215+
++ lib.optionals (lib.length sanitizers > 0) (
216+
[
217+
(lib.mesonOption "b_sanitize" (lib.concatStringsSep "," sanitizers))
218+
]
219+
++ (lib.optionals stdenv.cc.isClang [
220+
# https://www.github.com/mesonbuild/meson/issues/764
221+
(lib.mesonBool "b_lundef" false)
222+
])
223+
);
224+
};
225+
207226
nixDefaultsLayer = finalAttrs: prevAttrs: {
208227
strictDeps = prevAttrs.strictDeps or true;
209228
enableParallelBuilding = true;
@@ -246,6 +265,16 @@ in
246265

247266
inherit filesetToSource;
248267

268+
/**
269+
Whether meson components are built with [AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html).
270+
*/
271+
withASan = false;
272+
273+
/**
274+
Whether meson components are built with [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html).
275+
*/
276+
withUBSan = false;
277+
249278
/**
250279
A user-provided extension function to apply to each component derivation.
251280
*/
@@ -332,6 +361,7 @@ in
332361
setVersionLayer
333362
mesonLayer
334363
fixupStaticLayer
364+
enableSanitizersLayer
335365
scope.mesonComponentOverrides
336366
];
337367
mkMesonExecutable = mkPackageBuilder [
@@ -342,6 +372,7 @@ in
342372
mesonLayer
343373
mesonBuildLayer
344374
fixupStaticLayer
375+
enableSanitizersLayer
345376
scope.mesonComponentOverrides
346377
];
347378
mkMesonLibrary = mkPackageBuilder [
@@ -353,6 +384,7 @@ in
353384
mesonBuildLayer
354385
mesonLibraryLayer
355386
fixupStaticLayer
387+
enableSanitizersLayer
356388
scope.mesonComponentOverrides
357389
];
358390

0 commit comments

Comments
 (0)