Skip to content

Commit ca38751

Browse files
committed
Rust: Enable LTO for the extractor
1 parent fa8a287 commit ca38751

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

misc/bazel/rust.bzl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
load("@rules_rust//rust:defs.bzl", "rust_binary")
22
load("@semmle_code//buildutils-internal:glibc_symbols_check.bzl", "glibc_symbols_check")
33
load("@semmle_code//buildutils-internal:lipo.bzl", "universal_binary")
4+
load("@semmle_code//buildutils-internal:transitions.bzl", "forward_binary_from_transition", "get_transition_attrs")
5+
6+
def _full_lto_transition_impl(_settings, _attr):
7+
return {"@rules_rust//rust/settings:lto": "fat"}
8+
9+
_full_lto_transition = transition(
10+
implementation = _full_lto_transition_impl,
11+
inputs = [],
12+
outputs = ["@rules_rust//rust/settings:lto"],
13+
)
14+
15+
_full_lto_binary = rule(
16+
implementation = forward_binary_from_transition,
17+
attrs = get_transition_attrs(_full_lto_transition),
18+
)
419

520
def codeql_rust_binary(
621
name,
22+
full_lto = False,
723
target_compatible_with = None,
824
visibility = None,
925
symbols_test = True,
1026
**kwargs):
1127
rust_label_name = "single_arch/" + name
28+
binary_dep = ":" + rust_label_name
29+
if full_lto:
30+
lto_label_name = "full_lto/" + name
31+
_full_lto_binary(
32+
name = lto_label_name,
33+
dep = binary_dep,
34+
)
35+
binary_dep = ":" + lto_label_name
1236
universal_binary(
1337
name = name,
14-
dep = ":" + rust_label_name,
38+
dep = binary_dep,
1539
target_compatible_with = target_compatible_with,
1640
visibility = visibility,
1741
)

rust/extractor/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ codeql_rust_binary(
1111
"src/qltest_cargo.mustache",
1212
"src/nightly-toolchain/rust-toolchain.toml",
1313
],
14+
full_lto = True,
1415
proc_macro_deps = all_crate_deps(
1516
proc_macro = True,
1617
) + [

0 commit comments

Comments
 (0)