Skip to content

Commit

Permalink
[CodeHealth][rust] Brave BUILD.gn handlebars changes
Browse files Browse the repository at this point in the history
This change contains the handlebars changes we apply to our own
handlebars file. This commit also adds a patch that can be used to
update the handlebar files, based on new upstream additions.
  • Loading branch information
cdesouza-chromium committed Nov 4, 2024
1 parent f2a3dbf commit c991329
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 24 deletions.
44 changes: 20 additions & 24 deletions third_party/rust/chromium_crates_io/BUILD.gn.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Copyright (c) 2024 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/.

# @generated from third_party/rust/chromium_crates_io/BUILD.gn.hbs by
# tools/crates/gnrt.
Expand Down Expand Up @@ -53,14 +54,14 @@ cargo_crate("{{this.name}}") {
":lib",
{{/if}}
{{#each this.packages}}
"//third_party/rust/{{this.name}}/{{this.epoch}}:lib",
"//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib",
{{/each}}
]
{{else}}
if ({{this.cond}}) {
deps += [
{{#each this.packages}}
"//third_party/rust/{{this.name}}/{{this.epoch}}:lib",
"//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib",
{{/each}}
]
}
Expand All @@ -69,22 +70,22 @@ cargo_crate("{{this.name}}") {
{{#if aliased_deps}}
aliased_deps = {
{{#each aliased_deps}}
{{this.0}} = "{{this.1}}"
{{this.0}} = "//brave/third_party/rust/{{this.1}}:lib"
{{/each}}
}
{{/if}}
{{#each build_deps}}
{{#if @first}}
build_deps = [
{{#each this.packages}}
"//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
"//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
{{/each}}
]
{{else}}
if ({{this.cond}}) {
build_deps += [
{{#each this.packages}}
"//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
"//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
{{/each}}
]
}
Expand Down Expand Up @@ -119,23 +120,32 @@ cargo_crate("{{this.name}}") {
]
{{/with}}
{{/if}}
{{#if rustenv}}
{{#if (or rustenv extra_kv.rustenv)}}
rustenv = [
{{#each rustenv}}
"{{this}}",
{{/each}}
{{#each extra_kv.rustenv}}
"{{this}}",
{{/each}}
]
{{/if}}
{{#if rustflags}}
{{#if (or rustflags extra_kv.rustflags)}}
rustflags = [
{{#each rustflags}}
"{{this}}",
{{/each}}
{{#each extra_kv.rustflags}}
"{{this}}",
{{/each}}
]
{{/if}}
{{#if output_dir}}
output_dir = "{{output_dir}}"
{{/if}}
{{#if extra_kv.raw_gn}}
{{extra_kv.raw_gn}}
{{/if}}
{{#if native_libs}}
native_libs = [
{{#each native_libs}}
Expand All @@ -144,20 +154,6 @@ cargo_crate("{{this.name}}") {
]
{{/if}}
{{/with}}

{{#if gn_visibility.public}}
{{#if detail.extra_kv.visibility}}
visibility = []
{{/if}}
{{else}}
# Only for usage from third-party crates. Add the crate to
# //third_party/rust/chromium_crates_io/Cargo.toml to use
# it from first-party code.
visibility = [ "//third_party/rust/*" ]
{{/if}}
{{#each detail.extra_kv.visibility}}
visibility += [ "{{this}}" ]
{{/each}}
{{#if gn_visibility.testonly}}
testonly = true
{{/if}}
Expand Down
114 changes: 114 additions & 0 deletions third_party/rust/chromium_crates_io/BUILD.gn.hbs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
diff --git a/third_party/rust/chromium_crates_io/BUILD.gn.hbs b/third_party/rust/chromium_crates_io/BUILD.gn.hbs
index 4cf2f4f5f8b..aa598c2dcf1 100644
--- a/third_party/rust/chromium_crates_io/BUILD.gn.hbs
+++ b/third_party/rust/chromium_crates_io/BUILD.gn.hbs
@@ -1,6 +1,7 @@
-# Copyright 2023 The Chromium Authors
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
+# Copyright (c) 2024 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/.

# @generated from third_party/rust/chromium_crates_io/BUILD.gn.hbs by
# tools/crates/gnrt.
@@ -53,14 +54,14 @@ cargo_crate("{{this.name}}") {
":lib",
{{/if}}
{{#each this.packages}}
- "//third_party/rust/{{this.name}}/{{this.epoch}}:lib",
+ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib",
{{/each}}
]
{{else}}
if ({{this.cond}}) {
deps += [
{{#each this.packages}}
- "//third_party/rust/{{this.name}}/{{this.epoch}}:lib",
+ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib",
{{/each}}
]
}
@@ -69,7 +70,7 @@ cargo_crate("{{this.name}}") {
{{#if aliased_deps}}
aliased_deps = {
{{#each aliased_deps}}
- {{this.0}} = "{{this.1}}"
+ {{this.0}} = "//brave/third_party/rust/{{this.1}}:lib"
{{/each}}
}
{{/if}}
@@ -77,14 +78,14 @@ cargo_crate("{{this.name}}") {
{{#if @first}}
build_deps = [
{{#each this.packages}}
- "//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
+ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
{{/each}}
]
{{else}}
if ({{this.cond}}) {
build_deps += [
{{#each this.packages}}
- "//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
+ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support",
{{/each}}
]
}
@@ -119,23 +120,32 @@ cargo_crate("{{this.name}}") {
]
{{/with}}
{{/if}}
- {{#if rustenv}}
+ {{#if (or rustenv extra_kv.rustenv)}}
rustenv = [
{{#each rustenv}}
"{{this}}",
{{/each}}
+ {{#each extra_kv.rustenv}}
+ "{{this}}",
+ {{/each}}
]
{{/if}}
- {{#if rustflags}}
+ {{#if (or rustflags extra_kv.rustflags)}}
rustflags = [
{{#each rustflags}}
"{{this}}",
{{/each}}
+ {{#each extra_kv.rustflags}}
+ "{{this}}",
+ {{/each}}
]
{{/if}}
{{#if output_dir}}
output_dir = "{{output_dir}}"
{{/if}}
+ {{#if extra_kv.raw_gn}}
+ {{extra_kv.raw_gn}}
+ {{/if}}
{{#if native_libs}}
native_libs = [
{{#each native_libs}}
@@ -144,20 +154,6 @@ cargo_crate("{{this.name}}") {
]
{{/if}}
{{/with}}
-
- {{#if gn_visibility.public}}
- {{#if detail.extra_kv.visibility}}
- visibility = []
- {{/if}}
- {{else}}
- # Only for usage from third-party crates. Add the crate to
- # //third_party/rust/chromium_crates_io/Cargo.toml to use
- # it from first-party code.
- visibility = [ "//third_party/rust/*" ]
- {{/if}}
- {{#each detail.extra_kv.visibility}}
- visibility += [ "{{this}}" ]
- {{/each}}
{{#if gn_visibility.testonly}}
testonly = true
{{/if}}

0 comments on commit c991329

Please sign in to comment.