Skip to content

Commit

Permalink
[bazel] Patch rules_foreign_cc to clean build logs
Browse files Browse the repository at this point in the history
Move rules_foreign_cc from the root MODULE.bazel to its own
`third_party/foreign_cc` directory so that we can patch it to fix an
issue that has not yet been supported upstream yet, in the same way as
we do for e.g. `rules_rust`.

When `rules_foreign_cc` builds using tools such as e.g. Configure+Make,
output files Configure.log and BootstrapGNUMake.log are generated and
emitted which contain references to the absolute path. When building
inside Bazel's sandbox, this produces a non-determinstic output which
changes between each run, as a result, rebuilding OpenOCD will then
change the inputs of any Bazel actions that use OpenOCD, resulting in
a reduced number of cache hits and increasing build times. By making
this determinstic, we improve reproducibility and potentially reduce
build times.

To fix this, this PR introduces a simple patch to completely remove
all the content of this logging output, as it is not needed by any later
steps as part of the build.

Signed-off-by: Alex Jones <[email protected]>
  • Loading branch information
AlexJones0 authored and jwnrt committed Jan 10, 2025
1 parent 6f95ef2 commit 0e617f4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_cc", version = "0.0.14")
bazel_dep(name = "rules_foreign_cc", version = "0.9.0")
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
bazel_dep(name = "rules_pkg", version = "1.0.1")

Expand All @@ -35,6 +34,8 @@ include("//third_party/rust:rust.MODULE.bazel")

include("//third_party/python:python.MODULE.bazel")

include("//third_party/foreign_cc:foreign_cc.MODULE.bazel")

# Repository rules:
bitstreams_repo = use_repo_rule("//rules:bitstreams.bzl", "bitstreams_repo")

Expand Down
5 changes: 5 additions & 0 deletions third_party/foreign_cc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

package(default_visibility = ["//visibility:public"])
18 changes: 18 additions & 0 deletions third_party/foreign_cc/foreign_cc.MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Dependencies:
bazel_dep(name = "rules_foreign_cc", version = "0.9.0")

# Overrides and patches:
single_version_override(
module_name = "rules_foreign_cc",
patches = [
# Patch to remove all build log file output when using rules_foreign_cc
# toolchains to ensure deterministic Bazel builds. See upstream issue:
# https://github.com/bazel-contrib/rules_foreign_cc/issues/1313
"//third_party/foreign_cc/patches:rules_foreign_cc.remove_log_output.patch",
],
version = "0.9.0",
)
5 changes: 5 additions & 0 deletions third_party/foreign_cc/patches/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

package(default_visibility = ["//visibility:public"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git foreign_cc/private/framework.bzl foreign_cc/private/framework.bzl
index c84c217..f43da2c 100644
--- foreign_cc/private/framework.bzl
+++ foreign_cc/private/framework.bzl
@@ -561,7 +561,7 @@ def wrap_outputs(ctx, lib_name, configure_name, script_text, build_script_file =
cleanup_on_success_function = create_function(
ctx,
"cleanup_on_success",
- "rm -rf $BUILD_TMPDIR $EXT_BUILD_DEPS",
+ "rm -rf $BUILD_TMPDIR $EXT_BUILD_DEPS && echo > $BUILD_LOG",
)
cleanup_on_failure_function = create_function(
ctx,

0 comments on commit 0e617f4

Please sign in to comment.