Skip to content

Commit

Permalink
Add --with-asan option
Browse files Browse the repository at this point in the history
  • Loading branch information
sagudev committed Feb 26, 2024
1 parent 1dd3e80 commit 9d4ca94
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
36 changes: 32 additions & 4 deletions python/servo/build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Command,
)
from mach.registrar import Registrar
from python.servo.platform.base import NIGHTLY_RUST

import servo.platform
import servo.util
Expand All @@ -53,11 +54,12 @@ class MachCommands(CommandBase):
@CommandArgument('--very-verbose', '-vv',
action='store_true',
help='Print very verbose output')
@CommandArgument('--with-asan', action='store_true', help="Enable AddressSanitizer")
@CommandArgument('params', nargs='...',
help="Command-line arguments to be passed through to Cargo")
@CommandBase.common_command_arguments(build_configuration=True, build_type=True)
def build(self, build_type: BuildType, jobs=None, params=None, no_package=False,
verbose=False, very_verbose=False, **kwargs):
verbose=False, very_verbose=False, with_asan=False, **kwargs):
opts = params or []

if build_type.is_release():
Expand All @@ -78,10 +80,29 @@ def build(self, build_type: BuildType, jobs=None, params=None, no_package=False,
self.ensure_bootstrapped()
self.ensure_clobbered()

build_start = time()

host = servo.platform.host_triple()
target_triple = self.cross_compile_target or servo.platform.host_triple()

if with_asan:
if target_triple not in ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu",
"x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]:
print("AddressSanitizer is currently not supported on this platform\n",
"See https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html")
sys.exit(1)
env["RUSTFLAGS"] = env.get("RUSTFLAGS", "") + " -Zsanitizer=address"
opts += ["-Zbuild-std"]
kwargs["target"] = target_triple
# sanitizers are only available on nightly
kwargs["toolchain"] = f"+{NIGHTLY_RUST}"
# do not use crown (clashes with different rust version)
env["RUSTC"] = "rustc"
# env.setdefault("CFLAGS", "")
# env.setdefault("CXXFLAGS", "")
# env["CFLAGS"] += " -fsanitize=address"
# env["CXXFLAGS"] += " -fsanitize=address"

build_start = time()

if host != target_triple and 'windows' in target_triple:
if os.environ.get('VisualStudioVersion') or os.environ.get('VCINSTALLDIR'):
print("Can't cross-compile for Windows inside of a Visual Studio shell.\n"
Expand All @@ -104,10 +125,17 @@ def build(self, build_type: BuildType, jobs=None, params=None, no_package=False,
if status == 0:
built_binary = self.get_binary_path(
build_type,
target=self.cross_compile_target,
target=target_triple if with_asan else self.cross_compile_target,
android=self.is_android_build,
)

if with_asan:
shutil.copy(built_binary, self.get_binary_path(
build_type,
target=self.cross_compile_target,
android=self.is_android_build,
))

if self.is_android_build and not no_package:
flavor = None
if "googlevr" in self.features:
Expand Down
12 changes: 9 additions & 3 deletions python/servo/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,10 @@ def is_media_enabled(self, media_stack: Optional[str]):

def run_cargo_build_like_command(
self, command: str, cargo_args: List[str],
env=None, verbose=False,
env=None, verbose=False, toolchain: Optional[str] = None,
debug_mozjs=False, with_debug_assertions=False,
with_frame_pointer=False, without_wgl=False,
target: Optional[str] = None,
**_kwargs
):
env = env or self.build_env()
Expand All @@ -843,7 +844,9 @@ def run_cargo_build_like_command(
"--manifest-path",
path.join(self.context.topdir, "ports", port, "Cargo.toml"),
]
if self.cross_compile_target:
if target:
args += ["--target", target]
elif self.cross_compile_target:
args += ["--target", self.cross_compile_target]

if "-p" not in cargo_args: # We're building specific package, that may not have features
Expand All @@ -867,7 +870,10 @@ def run_cargo_build_like_command(
if with_debug_assertions or self.config["build"]["debug-assertions"]:
env['RUSTFLAGS'] = env.get('RUSTFLAGS', "") + " -C debug_assertions"

return call(["cargo", command] + args + cargo_args, env=env, verbose=verbose)
args.insert(0, command)
if toolchain:
args.insert(0, toolchain)
return call(["cargo"] + args + cargo_args, env=env, verbose=verbose)

def android_adb_path(self, env):
if "ANDROID_SDK_ROOT" in env:
Expand Down

0 comments on commit 9d4ca94

Please sign in to comment.