Move WASM crates next to their consumer components (#34574)
* Move opaque_ke WASM crate next to its consumer component Move opaque_ke from third_party/wasm/ to components/brave_account/resources/opaque_ke/ so it lives next to the component that consumes it. - Move crate directory with index.js as-is - Add workspace key to Cargo.toml for workspace discovery - Update .cargo/config.toml vendor path - Add transpile_web_ui target in resources/opaque_ke/BUILD.gn - Update workspace Cargo.toml member path - Update update.py to use make_config_toml for relative vendor paths * Move candle_embedding_gemma WASM crate next to its consumer component Move candle_embedding_gemma from third_party/wasm/ to components/local_ai/resources/candle_embedding_gemma/ so it lives next to the component that consumes it. - Move crate directory - Add workspace key to Cargo.toml for workspace discovery - Update .cargo/config.toml vendor path - Update workspace Cargo.toml member path - Update update.py PRESERVE_PATTERNS for new config location
This commit is contained in:
+1
-1
@@ -2,4 +2,4 @@
|
||||
replace-with = "vendored-sources"
|
||||
|
||||
[source.vendored-sources]
|
||||
directory = "../vendor"
|
||||
directory = "../../../../third_party/wasm/vendor"
|
||||
@@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2026 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("//brave/components/common/typescript.gni")
|
||||
|
||||
transpile_web_ui("opaque_ke") {
|
||||
resource_name = "opaque_ke"
|
||||
generate_grdp = true
|
||||
resource_path_prefix = "brave"
|
||||
|
||||
entry_points = [ [
|
||||
"opaque_ke",
|
||||
rebase_path("index.js"),
|
||||
] ]
|
||||
|
||||
inputs = [
|
||||
rebase_path("//brave/third_party/wasm/Cargo.lock"),
|
||||
rebase_path("src/lib.rs"),
|
||||
]
|
||||
|
||||
imports_from = [ "//brave/components/brave_account/resources/opaque_ke/" ]
|
||||
|
||||
rust_packages = [ rebase_path("Cargo.toml") ]
|
||||
|
||||
public_asset_path = "chrome://resources/brave/"
|
||||
}
|
||||
+1
@@ -2,6 +2,7 @@
|
||||
name = "opaque-ke-wasm"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
workspace = "../../../../third_party/wasm"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
+1
-1
@@ -6,4 +6,4 @@
|
||||
export {
|
||||
Login,
|
||||
Registration,
|
||||
} from 'gen/brave/third_party/wasm/opaque_ke/bundler/pkg'
|
||||
} from 'gen/brave/components/brave_account/resources/opaque_ke/bundler/pkg'
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
replace-with = "vendored-sources"
|
||||
|
||||
[source.vendored-sources]
|
||||
directory = "../vendor"
|
||||
directory = "../../../../third_party/wasm/vendor"
|
||||
|
||||
[target.wasm32-unknown-unknown]
|
||||
rustflags = [
|
||||
+1
@@ -2,6 +2,7 @@
|
||||
name = "candle_embedding_gemma"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
workspace = "../../../../third_party/wasm"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
Vendored
+4
-1
@@ -1,3 +1,6 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = ["opaque_ke", "candle_embedding_gemma"]
|
||||
members = [
|
||||
"../../components/brave_account/resources/opaque_ke",
|
||||
"../../components/local_ai/resources/candle_embedding_gemma",
|
||||
]
|
||||
|
||||
Vendored
+21
-15
@@ -19,7 +19,6 @@ import toml
|
||||
import brave_chromium_utils
|
||||
|
||||
PRESERVE_PATTERNS = [
|
||||
'candle_embedding_gemma/.cargo/config.toml',
|
||||
'vendor/.clang-format',
|
||||
'vendor/*/README.chromium',
|
||||
]
|
||||
@@ -55,30 +54,37 @@ def clean_up_files(patterns):
|
||||
path.unlink()
|
||||
|
||||
|
||||
def make_config_toml(member):
|
||||
"""Build a cargo config that points to the shared vendor dir."""
|
||||
vendor_rel = os.path.relpath('vendor', member)
|
||||
vendor_rel = vendor_rel.replace(os.sep, '/')
|
||||
return {
|
||||
'source': {
|
||||
'crates-io': {
|
||||
'replace-with': 'vendored-sources'
|
||||
},
|
||||
'vendored-sources': {
|
||||
'directory': vendor_rel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
with brave_chromium_utils.sys_path('//tools/rust'):
|
||||
import update_rust
|
||||
CARGO = os.path.join(update_rust.RUST_TOOLCHAIN_OUT_DIR, 'bin',
|
||||
'cargo' + ('.exe' if sys.platform == 'win32' else ''))
|
||||
|
||||
CONFIG_TOML = {
|
||||
'source': {
|
||||
'crates-io': {
|
||||
'replace-with': 'vendored-sources'
|
||||
},
|
||||
'vendored-sources': {
|
||||
'directory': '../vendor'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
backed_up_files = back_up_files(PRESERVE_PATTERNS)
|
||||
|
||||
members = toml.load('Cargo.toml')['workspace']['members']
|
||||
|
||||
preserve = ([f'{m}/.cargo/config.toml'
|
||||
for m in members] + PRESERVE_PATTERNS)
|
||||
backed_up_files = back_up_files(preserve)
|
||||
|
||||
shutil.rmtree('vendor', ignore_errors=True)
|
||||
for member in members:
|
||||
Path(f'{member}/.cargo/config.toml').unlink(missing_ok=True)
|
||||
@@ -87,7 +93,7 @@ def main():
|
||||
for member in members:
|
||||
Path(f'{member}/.cargo').mkdir(exist_ok=True)
|
||||
with open(Path(f'{member}/.cargo/config.toml'), 'w') as f:
|
||||
toml.dump(CONFIG_TOML, f)
|
||||
toml.dump(make_config_toml(member), f)
|
||||
|
||||
restore_files(backed_up_files)
|
||||
clean_up_files(CLEANUP_PATTERNS)
|
||||
|
||||
@@ -29,8 +29,8 @@ group("grdp") {
|
||||
":fonts_grdp",
|
||||
":icons_grdp",
|
||||
":leo_bundle",
|
||||
":opaque_ke",
|
||||
":static_grdp",
|
||||
"//brave/components/brave_account/resources/opaque_ke",
|
||||
]
|
||||
if (include_polymer) {
|
||||
public_deps += [ ":build_grdp" ]
|
||||
@@ -104,29 +104,6 @@ transpile_web_ui("leo_bundle") {
|
||||
resource_name = "leo"
|
||||
}
|
||||
|
||||
transpile_web_ui("opaque_ke") {
|
||||
resource_name = "opaque_ke"
|
||||
generate_grdp = true
|
||||
resource_path_prefix = "brave"
|
||||
|
||||
entry_points = [ [
|
||||
"opaque_ke",
|
||||
rebase_path("//brave/third_party/wasm/opaque_ke/index.js"),
|
||||
] ]
|
||||
|
||||
inputs = [
|
||||
rebase_path("//brave/third_party/wasm/Cargo.lock"),
|
||||
rebase_path("//brave/third_party/wasm/opaque_ke/src/lib.rs"),
|
||||
]
|
||||
|
||||
imports_from = [ "//brave/third_party/wasm/" ]
|
||||
|
||||
rust_packages =
|
||||
[ rebase_path("//brave/third_party/wasm/opaque_ke/Cargo.toml") ]
|
||||
|
||||
public_asset_path = "chrome://resources/brave/"
|
||||
}
|
||||
|
||||
# Create a grdp that //ui/webui/resources can include in its main resources GRD
|
||||
generate_grd("static_grdp") {
|
||||
grd_prefix = "brave_webui"
|
||||
|
||||
Reference in New Issue
Block a user