Skip to content

Make build_crate use root_out_dir as its temp. #29353

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

Merged
merged 2 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions script/build_crate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2025 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

import argparse
import os
from pathlib import Path
import platform
import subprocess

parser = argparse.ArgumentParser(
description='Build crates in //brave/tools/crates/config.gni')
parser.add_argument('--temp_dir_path', required=True)
args, cargo_args = parser.parse_known_args()
env = os.environ.copy()
if platform.system() == "Windows":
env['TEMP'] = env['TMP'] = args.temp_dir_path
else:
env["TMPDIR"] = args.temp_dir_path
subprocess.check_call(cargo_args, env=env)
Path(f'{args.temp_dir_path}/.stamp').touch()
14 changes: 11 additions & 3 deletions tools/crates/build_crate.gni
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ template("build_crate") {
defined(invoker["${crate}_exe"]),
"Please add ${crate}_exe to //brave/tools/crates/config.gni (or to $crate itself)!")
crate_exe = invoker["${crate}_exe"]
crate_target_dir = get_path_info(get_path_info(crate_exe, "dir"), "dir")

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

forward_variables_from(invoker, [ "deps" ])

script = "//build/gn_run_binary.py"
script = "//brave/script/build_crate.py"

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

inputs = [
cargo_exe,
".cargo/config.toml",
"Cargo.lock",
"Cargo.toml",
]

outputs = [ crate_exe ]
outputs = [
crate_exe,
"$crate_target_dir/.stamp",
]

# To avoid irreproducible builds,
# `build_crate`s MUST always build with `cargo vendor`ed deps,
Expand All @@ -36,6 +42,8 @@ template("build_crate") {
# --frozen (--locked + --offline)
# when running `cargo build`.
args = [
"--temp_dir_path",
rebase_path(crate_target_dir),
rebase_path(cargo_exe),
"build",
"--quiet",
Expand All @@ -45,7 +53,7 @@ template("build_crate") {
"--config",
rebase_path(".cargo/config.toml"),
"--target-dir",
rebase_path(get_path_info(crate_exe, "dir") + "/.."),
rebase_path(crate_target_dir),
"--frozen",
"--package",
string_replace(crate, "_", "-"),
Expand Down
Loading