Skip to content

Commit 6e743db

Browse files
Merge pull request #29353 from brave/szilard/46505-build_crate-temp-dir
Make `build_crate` use `root_out_dir` as its temp.
2 parents 7bcbc8b + 568a52a commit 6e743db

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

script/build_crate.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2025 The Brave Authors. All rights reserved.
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
# You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
import argparse
7+
import os
8+
from pathlib import Path
9+
import platform
10+
import subprocess
11+
12+
parser = argparse.ArgumentParser(
13+
description='Build crates in //brave/tools/crates/config.gni')
14+
parser.add_argument('--temp_dir_path', required=True)
15+
args, cargo_args = parser.parse_known_args()
16+
env = os.environ.copy()
17+
if platform.system() == "Windows":
18+
env['TEMP'] = env['TMP'] = args.temp_dir_path
19+
else:
20+
env["TMPDIR"] = args.temp_dir_path
21+
subprocess.check_call(cargo_args, env=env)
22+
Path(f'{args.temp_dir_path}/.stamp').touch()

tools/crates/build_crate.gni

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ template("build_crate") {
99
defined(invoker["${crate}_exe"]),
1010
"Please add ${crate}_exe to //brave/tools/crates/config.gni (or to $crate itself)!")
1111
crate_exe = invoker["${crate}_exe"]
12+
crate_target_dir = get_path_info(get_path_info(crate_exe, "dir"), "dir")
1213

1314
action("build_$crate") {
1415
assert(current_toolchain == host_toolchain)
1516

1617
forward_variables_from(invoker, [ "deps" ])
1718

18-
script = "//build/gn_run_binary.py"
19+
script = "//brave/script/build_crate.py"
1920

2021
cargo_exe = "//third_party/rust-toolchain/bin/cargo"
2122
if (host_os == "win") {
@@ -24,10 +25,15 @@ template("build_crate") {
2425

2526
inputs = [
2627
cargo_exe,
28+
".cargo/config.toml",
2729
"Cargo.lock",
30+
"Cargo.toml",
2831
]
2932

30-
outputs = [ crate_exe ]
33+
outputs = [
34+
crate_exe,
35+
"$crate_target_dir/.stamp",
36+
]
3137

3238
# To avoid irreproducible builds,
3339
# `build_crate`s MUST always build with `cargo vendor`ed deps,
@@ -36,6 +42,8 @@ template("build_crate") {
3642
# --frozen (--locked + --offline)
3743
# when running `cargo build`.
3844
args = [
45+
"--temp_dir_path",
46+
rebase_path(crate_target_dir),
3947
rebase_path(cargo_exe),
4048
"build",
4149
"--quiet",
@@ -45,7 +53,7 @@ template("build_crate") {
4553
"--config",
4654
rebase_path(".cargo/config.toml"),
4755
"--target-dir",
48-
rebase_path(get_path_info(crate_exe, "dir") + "/.."),
56+
rebase_path(crate_target_dir),
4957
"--frozen",
5058
"--package",
5159
string_replace(crate, "_", "-"),

0 commit comments

Comments
 (0)