-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,425 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist/ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Required on windows | ||
common --enable_platform_specific_config | ||
startup --windows_enable_symlinks | ||
build:windows --enable_runfiles | ||
|
||
build --experimental_enable_bzlmod | ||
|
||
# This isn't currently the defaut in Bazel, but we enable it to test we'll be ready if/when it flips. | ||
build --incompatible_disallow_empty_glob | ||
|
||
# Required for cargo_build_script support before Bazel 7 | ||
build --incompatible_merge_fixed_and_default_shell_env | ||
|
||
# Use a static value for `PATH` and does not inherit `LD_LIBRARY_PATH`. Doesn't let environment | ||
# variables like `PATH` sneak into the build, which can cause massive cache misses when they change. | ||
# Use `--action_env=ENV_VARIABLE` if you want to inherit specific environment variables from the | ||
# client, but note that doing so can prevent cross-user caching if a shared cache is used. | ||
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env | ||
build --incompatible_strict_action_env | ||
|
||
# Speed up all builds by not checking if external repository files have been modified. | ||
# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244 | ||
build --noexperimental_check_external_repository_files | ||
fetch --noexperimental_check_external_repository_files | ||
query --noexperimental_check_external_repository_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.bazelversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/dist/ | ||
/target/ | ||
|
||
/bazel-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") | ||
load("@crates_ui//:defs.bzl", "all_crate_deps") | ||
load("@rules_rust//rust:defs.bzl", "rust_binary") | ||
load("@rules_rust//wasm_bindgen:defs.bzl", "rust_wasm_bindgen") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
rust_binary( | ||
name = "ui-wasm", | ||
srcs = [ | ||
"src/app.rs", | ||
"src/main.rs", | ||
], | ||
target_compatible_with = [ | ||
"@platforms//cpu:wasm32", | ||
], | ||
deps = all_crate_deps(normal = True), | ||
) | ||
|
||
rust_wasm_bindgen( | ||
name = "ui-bindgen", | ||
target = "web", | ||
wasm_file = "ui-wasm", | ||
) | ||
|
||
copy_to_directory( | ||
name = "ui-http-root", | ||
srcs = [ | ||
"index.css", | ||
"index.html", | ||
":ui-bindgen", | ||
], | ||
include_srcs_patterns = [ | ||
"ui-bindgen_bg.wasm", | ||
"ui-bindgen.js", | ||
"index*", | ||
], | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
[package] | ||
name = "trunk-template" | ||
name = "wasm-ui" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "Template for starting a Yew project using Trunk" | ||
description = "From template for starting a Yew project using Trunk" | ||
readme = "README.md" | ||
repository = "https://github.com/yewstack/yew-trunk-minimal-template" | ||
license = "MIT OR Apache-2.0" | ||
keywords = ["yew", "trunk"] | ||
keywords = ["yew", "trunk", "bazel"] | ||
categories = ["gui", "wasm", "web-programming"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[dependencies] | ||
yew = { version="0.20", features=["csr"] } | ||
yew = { version = "0.20", features = ["csr"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""bazelbuild/rules_rust - bzlmod example""" | ||
|
||
module( | ||
name = "all_crate_deps_bzlmod_example", | ||
version = "0.0.0", | ||
) | ||
|
||
bazel_dep(name = "platforms", version = "0.0.10") | ||
bazel_dep( | ||
name = "bazel_skylib", | ||
version = "1.6.1", | ||
) | ||
bazel_dep(name = "aspect_bazel_lib", version = "2.9.1") | ||
bazel_dep( | ||
name = "rules_rust", | ||
version = "0.0.0", | ||
) | ||
local_path_override( | ||
module_name = "rules_rust", | ||
path = "../../..", | ||
) | ||
|
||
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") | ||
rust.toolchain(edition = "2021") | ||
use_repo( | ||
rust, | ||
"rust_toolchains", | ||
) | ||
|
||
register_toolchains("@rust_toolchains//:all") | ||
|
||
wasm_bindgen = use_extension("@rules_rust//wasm_bindgen:extensions.bzl", "wasm_bindgen") | ||
use_repo( | ||
wasm_bindgen, | ||
) | ||
|
||
register_toolchains( | ||
"@rules_rust//wasm_bindgen:default_wasm_bindgen_toolchain", | ||
"@rules_rust//rust/private/dummy_cc_toolchain:dummy_cc_wasm32_toolchain", | ||
) | ||
|
||
crate = use_extension( | ||
"@rules_rust//crate_universe:extension.bzl", | ||
"crate", | ||
) | ||
crate.from_cargo( | ||
name = "crates_serve", | ||
cargo_lockfile = "//serve:Cargo.lock", | ||
manifests = ["//serve:Cargo.toml"], | ||
) | ||
crate.from_cargo( | ||
name = "crates_ui", | ||
cargo_lockfile = "//:Cargo.lock", | ||
manifests = ["//:Cargo.toml"], | ||
) | ||
use_repo(crate, "crates_serve", "crates_ui") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
# Yew Trunk Template | ||
# Yew Template - with Bazel/Trunk | ||
|
||
This is a fairly minimal template for a Yew app that's built with [Trunk]. | ||
This was generated according to the getting started instructions of [yew](https://yew.rs/) | ||
and then enriched with Bazel build rules. | ||
|
||
## Usage | ||
## Bazel | ||
|
||
For a more thorough explanation of Trunk and its features, please head over to the [repository][trunk]. | ||
Build and serve the UI with: | ||
|
||
```bash | ||
bazel run //serve | ||
``` | ||
|
||
This also builds a small rust server application to serve the files. | ||
|
||
## Usage (Trunk) | ||
|
||
For a more thorough explanation of Trunk and its features, please head over to the [Trunk](https://trunkrs.dev/). | ||
|
||
### Installation | ||
|
||
|
@@ -18,7 +29,7 @@ If you don't already have it, install it with the following command: | |
rustup target add wasm32-unknown-unknown | ||
``` | ||
|
||
Now that we have our basics covered, it's time to install the star of the show: [Trunk]. | ||
Now that we have our basics covered, it's time to install the star of the show: [Trunk](https://trunkrs.dev/). | ||
Simply run the following command to install it: | ||
|
||
```bash | ||
|
@@ -63,12 +74,3 @@ Update the `name`, `version`, `description` and `repository` fields in the [Carg | |
The [index.html](index.html) file also contains a `<title>` tag that needs updating. | ||
|
||
Finally, you should update this very `README` file to be about your app. | ||
|
||
### License | ||
|
||
The template ships with both the Apache and MIT license. | ||
If you don't want to have your app dual licensed, just remove one (or both) of the files and update the `license` field in `Cargo.toml`. | ||
|
||
There are two empty spaces in the MIT license you need to fill out: `` and `Peter Kolloch <[email protected]>`. | ||
|
||
[trunk]: https://github.com/thedodd/trunk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intentionally blank; using bzlmod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intentionally blank; enable strict mode for bzlmod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Trunk Template</title> | ||
<link data-trunk rel="sass" href="index.scss" /> | ||
</head> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Yew build with bazel</title> | ||
<link | ||
rel="icon" | ||
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚀</text></svg>" | ||
/> | ||
<link rel="stylesheet" href="/index.css" /> | ||
<link | ||
rel="preload" | ||
href="/ui-bindgen_bg.wasm" | ||
as="fetch" | ||
type="application/wasm" | ||
crossorigin="" | ||
/> | ||
<link rel="modulepreload" href="/ui-bindgen.js" /> | ||
</head> | ||
<body> | ||
<script type="module"> | ||
import init from "/ui-bindgen.js"; | ||
init("/ui-bindgen_bg.wasm"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@crates_serve//:defs.bzl", "all_crate_deps") | ||
load("@rules_rust//rust:defs.bzl", "rust_binary") | ||
load(":binary_runner.bzl", "binary_runner") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
binary_runner( | ||
name = "serve", | ||
binary = ":serve_bin", | ||
data = [ | ||
"//:ui-http-root", | ||
], | ||
env = { | ||
"HTTP_ROOT": "$(rootpath //:ui-http-root)", | ||
}, | ||
) | ||
|
||
rust_binary( | ||
name = "serve_bin", | ||
srcs = [ | ||
"src/main.rs", | ||
], | ||
deps = all_crate_deps(normal = True), | ||
) |
Oops, something went wrong.