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

Use Bazel's COMPILATION_MODE var to determine opt-level and debuginfo… #97

Merged
merged 3 commits into from
Jun 19, 2018
Merged
Changes from 2 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
26 changes: 25 additions & 1 deletion rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ def _get_rustc_env(ctx):
"CARGO_PKG_HOMEPAGE=",
]

def _get_comp_mode_codegen_opts(ctx):
comp_mode = ctx.var["COMPILATION_MODE"]
opt_level = None
debug_info = None
if comp_mode == "dbg":
opt_level = 0
debug_info = 2
elif comp_mode == "opt":
opt_level = 3
debug_info = 0
elif comp_mode == "fastbuild":
opt_level = 0
debug_info = 0
else:
fail("Unrecognized COMPILATION_MODE: %s" % comp_mode)

return struct(
opt_level = opt_level,
debug_info = debug_info
)

# Utility methods that use the toolchain provider.
def build_rustc_command(ctx, toolchain, crate_name, crate_type, src, output_dir,
depinfo, output_hash=None, rust_flags=[]):
Expand Down Expand Up @@ -52,6 +73,8 @@ def build_rustc_command(ctx, toolchain, crate_name, crate_type, src, output_dir,
extra_filename = ""
if output_hash:
extra_filename = "-%s" % output_hash

codegen_opts = _get_comp_mode_codegen_opts(ctx)

return " ".join(
["set -e;"] +
Expand All @@ -68,7 +91,8 @@ def build_rustc_command(ctx, toolchain, crate_name, crate_type, src, output_dir,
src.path,
"--crate-name %s" % crate_name,
"--crate-type %s" % crate_type,
"--codegen opt-level=3", # @TODO Might not want to do -o3 on tests
"--codegen opt-level=%s" % codegen_opts.opt_level, # @TODO Might not want to do -o3 on tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove todo

"--codegen debuginfo=%s" % codegen_opts.debug_info,
# Disambiguate this crate from similarly named ones
"--codegen metadata=%s" % extra_filename,
"--codegen extra-filename='%s'" % extra_filename,
Expand Down