Skip to content

Commit

Permalink
Rust-to-WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
szilardszaloki committed Feb 20, 2025
1 parent 979db35 commit 01f74cf
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { getCss } from './brave_account_create_dialog.css.js'
import { getHtml } from './brave_account_create_dialog.html.js'
import { isEmailValid } from './brave_account_common.js'

// @ts-ignore
import { return42, return24 } from 'chrome://resources/brave/some_resource.bundle.js'
console.log(return42(), return24())

class PasswordStrengthMeter extends I18nMixinLit(CrLitElement) {
static get is() {
return 'password-strength-meter'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<style include="settings-shared md-select">
</style>
<settings-brave-account-row></settings-brave-account-row>
<settings-people-page prefs="{{prefs}}"
page-visibility="[[pageVisibility]]">
</settings-people-page>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'

import './brave_account_row.js'
import '../people_page/people_page.js'
import '../settings_page/settings_animated_pages.js'
import '../default_browser_page/default_browser_page.js'
Expand Down
2 changes: 1 addition & 1 deletion chromium_src/ui/webui/webui_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool IsChromeUntrustedDataSource(content::WebUIDataSource* source) {

constexpr char kBraveCSP[] =
"script-src chrome://resources chrome://webui-test "
"'self';";
"'wasm-unsafe-eval' 'self';";

constexpr char kBraveUntrustedCSP[] =
"script-src chrome-untrusted://resources "
Expand Down
12 changes: 12 additions & 0 deletions patches/tools-grit-grit-format-minifier.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/tools/grit/grit/format/minifier.py b/tools/grit/grit/format/minifier.py
index bd2dc7f9936a3c3a1d892be3b05be02a6910c571..1cfc9b0031fff73eac149eea137f10c10a0d9b96 100644
--- a/tools/grit/grit/format/minifier.py
+++ b/tools/grit/grit/format/minifier.py
@@ -13,6 +13,7 @@ __css_minifier = None
js_minifier_ignore_list = [
# TODO(crbug.com/339686362): Excluded because Terser throws an error.
'gen/chrome/browser/resources/omnibox/tsc/',
+ 'gen/brave/web-ui-some_resource/',
]


4 changes: 2 additions & 2 deletions patches/ui-webui-resources-tools-bundle_js_excludes.gni.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
diff --git a/ui/webui/resources/tools/bundle_js_excludes.gni b/ui/webui/resources/tools/bundle_js_excludes.gni
index 544a35127374b54700255f5902e881fc5fb89d7d..31ceaa0ee30563ce5fb74bcad9dd39a8aece9507 100644
index 544a35127374b54700255f5902e881fc5fb89d7d..08abc21bfdec4ca042158a4513fed32ff179d68e 100644
--- a/ui/webui/resources/tools/bundle_js_excludes.gni
+++ b/ui/webui/resources/tools/bundle_js_excludes.gni
@@ -14,6 +14,7 @@ foreach(excluded_file,
"resources/js/load_time_data.js",
"resources/ash/common/load_time_data.m.js",
"resources/mwc/lit/index.js",
+ "resources/brave/leo.bundle.js",
+ "resources/brave/leo.bundle.js", "resources/brave/some_resource.bundle.js",
]) {
# Exclude both the chrome://resources form and the scheme-relative form.
BUNDLE_JS_EXCLUDES += [
20 changes: 20 additions & 0 deletions ui/webui/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ group("grdp") {
":fonts_grdp",
":icons_grdp",
":leo_web_components",
":some_resource",
":static_grdp",
]
if (include_polymer) {
Expand Down Expand Up @@ -101,6 +102,25 @@ transpile_web_ui("leo_web_components") {
resource_name = "leo"
}

transpile_web_ui("some_resource") {
resource_name = "some_resource"
generate_grdp = true
resource_path_prefix = "brave"

entry_points = [ [
"some_resource",
rebase_path("some_resource/index.js"),
] ]

rust_packages = [
rebase_path("some_resource/rust_package_1/Cargo.toml"),
rebase_path("some_resource/rust_package_2/Cargo.toml"),
]

output_module = true
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"
Expand Down
8 changes: 8 additions & 0 deletions ui/webui/resources/some_resource/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* 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 { return42 } from 'gen/brave/ui/webui/resources/some_resource/rust_package_1/bundler/pkg'
import { return24 } from 'gen/brave/ui/webui/resources/some_resource/rust_package_2/bundler/pkg'
export { return42, return24 }
133 changes: 133 additions & 0 deletions ui/webui/resources/some_resource/rust_package_1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions ui/webui/resources/some_resource/rust_package_1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rust_package_1"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "=0.2.100" # Must match the version of brave/tools/crates/wasm_bindgen!
11 changes: 11 additions & 0 deletions ui/webui/resources/some_resource/rust_package_1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* 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/. */

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn return42() -> i32 {
return 42;
}
133 changes: 133 additions & 0 deletions ui/webui/resources/some_resource/rust_package_2/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 01f74cf

Please sign in to comment.