-
Notifications
You must be signed in to change notification settings - Fork 104
/
build_script.template
52 lines (51 loc) · 2.01 KB
/
build_script.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
rust_binary(
name = "{{ crate_name_sanitized }}_build_script",
srcs = glob(["**/*.rs"]),
{%- if crate.build_script_target.path %}
crate_root = "{{ crate.build_script_target.path }}",
{%- else %}
crate_root = "build.rs",
{%- endif %}
edition = "{{ crate.edition }}",
deps = [
{%- for dependency in crate.build_dependencies %}
"{{dependency.buildable_target}}",
{%- endfor %}
],
rustc_flags = [
"--cap-lints=allow",
],
crate_features = [
{%- for feature in crate.features %}
"{{feature}}",
{%- endfor %}
],
data = glob(["*"]),
version = "{{ crate.pkg_version }}",
visibility = ["//visibility:private"],
)
genrule(
name = "{{ crate_name_sanitized }}_build_script_executor",
srcs = glob(["*", "**/*.rs"]),
outs = ["{{ crate_name_sanitized }}_out_dir_outputs.tar.gz"],
tools = [
":{{ crate_name_sanitized }}_build_script",
],
local = 1,
cmd = "mkdir -p {{ crate_name_sanitized}}_out_dir_outputs/;"
+ " (export CARGO_MANIFEST_DIR=\"$$PWD/$$(dirname $(location :Cargo.toml))\";"
# TODO(acmcarther): This needs to be revisited as part of the cross compilation story.
# See also: https://github.com/google/cargo-raze/pull/54
+ " export TARGET='{{ workspace.platform_triple }}';"
+ " export RUST_BACKTRACE=1;"
{%- for feature in crate.features %}
+ " export CARGO_FEATURE_{{ feature | upper | replace(from="-", to="_") }}=1;"
{%- endfor %}
+ " export OUT_DIR=$$PWD/{{ crate_name_sanitized }}_out_dir_outputs;"
+ " export BINARY_PATH=\"$$PWD/$(location :{{ crate_name_sanitized }}_build_script)\";"
+ " export OUT_TAR=$$PWD/$@;"
{%- for environment_variable in crate.raze_settings.buildrs_additional_environment_variables %}
+ " export {{ environment_variable }};"
{%- endfor %}
+ " cd $$(dirname $(location :Cargo.toml)) && $$BINARY_PATH && tar -czf $$OUT_TAR -C $$OUT_DIR .)"
)