diff --git a/third_party/wasm/opaque_ke/.cargo/config.toml b/components/brave_account/resources/opaque_ke/.cargo/config.toml similarity index 61% rename from third_party/wasm/opaque_ke/.cargo/config.toml rename to components/brave_account/resources/opaque_ke/.cargo/config.toml index dd5b91b5e97..af21dd4d941 100644 --- a/third_party/wasm/opaque_ke/.cargo/config.toml +++ b/components/brave_account/resources/opaque_ke/.cargo/config.toml @@ -2,4 +2,4 @@ replace-with = "vendored-sources" [source.vendored-sources] -directory = "../vendor" +directory = "../../../../third_party/wasm/vendor" diff --git a/components/brave_account/resources/opaque_ke/BUILD.gn b/components/brave_account/resources/opaque_ke/BUILD.gn new file mode 100644 index 00000000000..88803812e6e --- /dev/null +++ b/components/brave_account/resources/opaque_ke/BUILD.gn @@ -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/" +} diff --git a/third_party/wasm/opaque_ke/Cargo.toml b/components/brave_account/resources/opaque_ke/Cargo.toml similarity index 90% rename from third_party/wasm/opaque_ke/Cargo.toml rename to components/brave_account/resources/opaque_ke/Cargo.toml index 3ab10d828f6..f7efc84a563 100644 --- a/third_party/wasm/opaque_ke/Cargo.toml +++ b/components/brave_account/resources/opaque_ke/Cargo.toml @@ -2,6 +2,7 @@ name = "opaque-ke-wasm" version = "0.1.0" edition = "2021" +workspace = "../../../../third_party/wasm" [lib] crate-type = ["cdylib"] diff --git a/third_party/wasm/opaque_ke/index.js b/components/brave_account/resources/opaque_ke/index.js similarity index 79% rename from third_party/wasm/opaque_ke/index.js rename to components/brave_account/resources/opaque_ke/index.js index 3bef7b9f253..82338648733 100644 --- a/third_party/wasm/opaque_ke/index.js +++ b/components/brave_account/resources/opaque_ke/index.js @@ -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' diff --git a/third_party/wasm/opaque_ke/src/lib.rs b/components/brave_account/resources/opaque_ke/src/lib.rs similarity index 100% rename from third_party/wasm/opaque_ke/src/lib.rs rename to components/brave_account/resources/opaque_ke/src/lib.rs diff --git a/third_party/wasm/candle_embedding_gemma/.cargo/config.toml b/components/local_ai/resources/candle_embedding_gemma/.cargo/config.toml similarity index 80% rename from third_party/wasm/candle_embedding_gemma/.cargo/config.toml rename to components/local_ai/resources/candle_embedding_gemma/.cargo/config.toml index 0110776972b..2818c53a603 100644 --- a/third_party/wasm/candle_embedding_gemma/.cargo/config.toml +++ b/components/local_ai/resources/candle_embedding_gemma/.cargo/config.toml @@ -2,7 +2,7 @@ replace-with = "vendored-sources" [source.vendored-sources] -directory = "../vendor" +directory = "../../../../third_party/wasm/vendor" [target.wasm32-unknown-unknown] rustflags = [ diff --git a/third_party/wasm/candle_embedding_gemma/Cargo.toml b/components/local_ai/resources/candle_embedding_gemma/Cargo.toml similarity index 92% rename from third_party/wasm/candle_embedding_gemma/Cargo.toml rename to components/local_ai/resources/candle_embedding_gemma/Cargo.toml index 8e2492b7e65..f6c91b79aef 100644 --- a/third_party/wasm/candle_embedding_gemma/Cargo.toml +++ b/components/local_ai/resources/candle_embedding_gemma/Cargo.toml @@ -2,6 +2,7 @@ name = "candle_embedding_gemma" version = "0.1.0" edition = "2021" +workspace = "../../../../third_party/wasm" [lib] crate-type = ["cdylib"] diff --git a/third_party/wasm/candle_embedding_gemma/src/lib.rs b/components/local_ai/resources/candle_embedding_gemma/src/lib.rs similarity index 100% rename from third_party/wasm/candle_embedding_gemma/src/lib.rs rename to components/local_ai/resources/candle_embedding_gemma/src/lib.rs diff --git a/third_party/wasm/Cargo.toml b/third_party/wasm/Cargo.toml index 0265788e4c9..402d557c992 100644 --- a/third_party/wasm/Cargo.toml +++ b/third_party/wasm/Cargo.toml @@ -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", +] diff --git a/third_party/wasm/update.py b/third_party/wasm/update.py index 3363fec9fcb..2749efb6bcb 100755 --- a/third_party/wasm/update.py +++ b/third_party/wasm/update.py @@ -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) diff --git a/ui/webui/resources/BUILD.gn b/ui/webui/resources/BUILD.gn index f4c20e10966..599e12f4a3d 100644 --- a/ui/webui/resources/BUILD.gn +++ b/ui/webui/resources/BUILD.gn @@ -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"