-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix examples #3813
Merged
+430
−46
Merged
Fix examples #3813
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a9d4166
use latest wasm-opt
Madoshakalaka 64b3b2b
build examples script in rust with wasm-opt checks
Madoshakalaka fc8e7ea
only pass the getrandom_backend cfg flag when needed
Madoshakalaka 416b5ac
fix formatting and edition (why can't we use 2024..?)
Madoshakalaka 59685ab
use github api and toml crate instead of ad-hoc parsing
Madoshakalaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
2 changes: 2 additions & 0 deletions
2
examples/communication_grandchild_with_grandparent/Trunk.toml
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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,3 +1,6 @@ | ||
[tools] | ||
wasm_opt = "version_122" | ||
|
||
[[hooks]] | ||
stage = "pre_build" | ||
command = "rustc" | ||
|
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 @@ | ||
[tools] | ||
wasm_opt = "version_122" |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "build-examples" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
reqwest = { version = "0.12.12", features = ["blocking", "json"] } | ||
regex = "1.11.1" | ||
toml = "0.8.20" | ||
serde = { version = "1.0.218", features = ["derive"] } |
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,123 @@ | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::ExitCode; | ||
|
||
use build_examples::{get_latest_wasm_opt_version, is_wasm_opt_outdated, NO_TRUNK_EXAMPLES}; | ||
use regex::Regex; | ||
|
||
fn main() -> ExitCode { | ||
// Must be run from root of the repo | ||
let examples_dir = Path::new("examples"); | ||
if !examples_dir.exists() { | ||
eprintln!( | ||
"examples directory not found. Make sure you're running from the root of the repo." | ||
); | ||
return ExitCode::from(1); | ||
} | ||
|
||
let latest_wasm_opt = get_latest_wasm_opt_version(); | ||
let mut outdated_example_paths = Vec::new(); | ||
let mut outdated_examples = Vec::new(); | ||
|
||
// Get all entries in the examples directory | ||
let entries = fs::read_dir(examples_dir).expect("Failed to read examples directory"); | ||
|
||
for entry in entries { | ||
let entry = entry.expect("Failed to read directory entry"); | ||
let path = entry.path(); | ||
|
||
// Skip if not a directory | ||
if !path.is_dir() { | ||
continue; | ||
} | ||
|
||
let example = path | ||
.file_name() | ||
.expect("Failed to get directory name") | ||
.to_string_lossy() | ||
.to_string(); | ||
|
||
// Skip ssr examples as they don't need trunk | ||
if NO_TRUNK_EXAMPLES.contains(&example.as_str()) { | ||
continue; | ||
} | ||
|
||
// Check Trunk.toml for wasm_opt version and collect outdated examples | ||
if is_wasm_opt_outdated(&path, &latest_wasm_opt) { | ||
outdated_examples.push(example); | ||
outdated_example_paths.push(path); | ||
} | ||
} | ||
|
||
if outdated_examples.is_empty() { | ||
println!( | ||
"All examples are up-to-date with the latest wasm_opt version: {}", | ||
latest_wasm_opt | ||
); | ||
return ExitCode::from(0); | ||
} | ||
|
||
println!( | ||
"Found {} examples with outdated or missing wasm_opt configuration:", | ||
outdated_examples.len() | ||
); | ||
for example in &outdated_examples { | ||
println!(" - {}", example); | ||
} | ||
println!("Latest wasm_opt version is: {}", latest_wasm_opt); | ||
println!("Updating all examples..."); | ||
|
||
let updated_count = update_all_examples(&outdated_example_paths, &latest_wasm_opt); | ||
println!( | ||
"Updated {} example configurations to use {}", | ||
updated_count, latest_wasm_opt | ||
); | ||
|
||
ExitCode::from(0) | ||
} | ||
|
||
pub fn update_all_examples(outdated_paths: &[PathBuf], latest_version: &str) -> usize { | ||
let mut updated_count = 0; | ||
|
||
let re = Regex::new(r#"(?m)^\[tools\]\s*\nwasm_opt\s*=\s*"(version_\d+)""#).unwrap(); | ||
for path in outdated_paths { | ||
let trunk_toml_path = path.join("Trunk.toml"); | ||
|
||
let content = fs::read_to_string(&trunk_toml_path).unwrap_or_default(); | ||
|
||
let updated_content = if re.is_match(&content) { | ||
// Replace existing wasm_opt version | ||
re.replace(&content, |_: ®ex::Captures| { | ||
format!( | ||
r#"[tools] | ||
wasm_opt = "{}""#, | ||
latest_version | ||
) | ||
}) | ||
.to_string() | ||
} else { | ||
// Add wasm_opt configuration | ||
if content.is_empty() { | ||
format!( | ||
r#"[tools] | ||
wasm_opt = "{}""#, | ||
latest_version | ||
) | ||
} else { | ||
format!( | ||
"{}\n\n[tools]\nwasm_opt = \"{}\"", | ||
content.trim(), | ||
latest_version | ||
) | ||
} | ||
}; | ||
|
||
if let Err(e) = fs::write(&trunk_toml_path, updated_content) { | ||
println!("Failed to update {}: {}", trunk_toml_path.display(), e); | ||
} else { | ||
updated_count += 1; | ||
} | ||
} | ||
|
||
updated_count | ||
} |
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,62 @@ | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
use serde::Deserialize; | ||
use toml::Table; | ||
|
||
/// Examples that don't use Trunk for building | ||
pub const NO_TRUNK_EXAMPLES: [&str; 3] = ["simple_ssr", "ssr_router", "wasi_ssr_module"]; | ||
|
||
#[derive(Deserialize)] | ||
struct GitHubRelease { | ||
tag_name: String, | ||
} | ||
|
||
pub fn get_latest_wasm_opt_version() -> String { | ||
let url = "https://api.github.com/repos/WebAssembly/binaryen/releases/latest"; | ||
let client = reqwest::blocking::Client::new(); | ||
|
||
// github api requires a user agent | ||
// https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api?apiVersion=2022-11-28#user-agent-required | ||
let req_builder = client.get(url).header("User-Agent", "yew-wasm-opt-checker"); | ||
|
||
// Send the request | ||
let res = req_builder | ||
.send() | ||
.expect("Failed to send request to GitHub API"); | ||
|
||
if !res.status().is_success() { | ||
// Get more details about the error | ||
let status = res.status(); | ||
let error_text = res | ||
.text() | ||
.unwrap_or_else(|_| "Could not read error response".to_string()); | ||
|
||
panic!( | ||
"GitHub API request failed with status: {}. Details: {}", | ||
status, error_text | ||
); | ||
} | ||
|
||
let release: GitHubRelease = res.json().expect("Failed to parse GitHub API response"); | ||
release.tag_name | ||
} | ||
|
||
pub fn is_wasm_opt_outdated(path: &Path, latest_version: &str) -> bool { | ||
let trunk_toml_path = path.join("Trunk.toml"); | ||
|
||
if !trunk_toml_path.exists() { | ||
return true; | ||
} | ||
|
||
let content = match fs::read_to_string(&trunk_toml_path) { | ||
Ok(content) => content, | ||
Err(_) => return true, | ||
}; | ||
|
||
// Check if wasm_opt is configured and up-to-date | ||
let table: Table = toml::from_str(&content).unwrap(); | ||
let tools = table.get("tools").unwrap().as_table().unwrap(); | ||
let wasm_opt = tools.get("wasm_opt").unwrap().as_str().unwrap(); | ||
wasm_opt != latest_version | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this emits warning cuz async_closure is stablized