From 7835eabead1a9752501f619aa1a92481c54744dc Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Wed, 18 Sep 2024 13:44:21 +0900 Subject: [PATCH 1/6] Propagate exit code from Dart command --- rust_crate/src/main.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/rust_crate/src/main.rs b/rust_crate/src/main.rs index 4c6347e8..319f7a4d 100644 --- a/rust_crate/src/main.rs +++ b/rust_crate/src/main.rs @@ -8,36 +8,32 @@ fn main() -> Result<(), String> { // Ensure Protobuf compiler. let protoc_path = if let Ok(installed) = which::which("protoc") { // Get the path of Protobuf compiler that's already installed. - println!("Detected `protoc`, skipping auto installation."); + println!("Detected `protoc`, skipping auto installation"); installed .parent() - .ok_or("Could not get the parent of `protoc` path.")? + .ok_or("Could not get the parent of `protoc` path")? .to_path_buf() } else { // Install Protobuf compiler and get the path. let home_path = home::home_dir() - .ok_or("Could not get home directory for `protoc` installation.")?; + .ok_or("Could not get home directory for `protoc` installation")?; let out_path = home_path.join(".local").join("bin"); fs::create_dir_all(&out_path).map_err(|_| { - "Could not create the folder for `protoc` installation." + "Could not create the folder for `protoc` installation" })?; env::set_var( "OUT_DIR", out_path .to_str() - .ok_or("Could not set the path for `protoc` installation.")?, + .ok_or("Could not set the path for `protoc` installation")?, ); let install_result = protoc_prebuilt::init("25.2"); - let (protoc_binary_path, _) = install_result.map_err(|_| { - format!( - "{}\n{}", - "Automatic installation of `protoc` failed.", - "Try installing `protoc` manually and adding it to PATH." - ) - })?; + let (protoc_binary_path, _) = install_result.map_err(|_| + "Automatic installation of `protoc` failed, try installing it manually" + )?; protoc_binary_path .parent() - .ok_or("Could not get the parent of installed `protoc` path.")? + .ok_or("Could not get the parent of newly installed `protoc` path")? .to_path_buf() }; @@ -45,14 +41,14 @@ fn main() -> Result<(), String> { #[cfg(target_family = "windows")] let pub_cache_bin_path = path::PathBuf::from( env::var("LOCALAPPDATA") - .map_err(|_| "Could not get `LOCALAPPDATA` path.")?, + .map_err(|_| "Could not get `LOCALAPPDATA` path")?, ) .join("Pub") .join("Cache") .join("bin"); #[cfg(target_family = "unix")] let pub_cache_bin_path = path::PathBuf::from( - env::var("HOME").map_err(|_| "Could get find `HOME` path.")?, + env::var("HOME").map_err(|_| "Could get find `HOME` path")?, ) .join(".pub-cache") .join("bin"); @@ -67,7 +63,7 @@ fn main() -> Result<(), String> { env::set_var( "PATH", env::join_paths(path_var) - .map_err(|_| "Could not push required values to `PATH`.")?, + .map_err(|_| "Could not push required values to `PATH`")?, ); // Get command-line arguments excluding the program name. @@ -75,11 +71,15 @@ fn main() -> Result<(), String> { // Run the Dart script. let dart_path = which::which("dart") - .map_err(|_| "Could not find where Dart is located.")?; + .map_err(|_| "Could not find where Dart is located")?; let mut command = process::Command::new(dart_path); command.args(["run", "rinf"]); command.args(&dart_command_args); - command.status().map_err(|_| "Rinf command has failed.")?; + let exit_status = command.status().map_err(|_| "Could not run Rinf command")?; + let exit_code = exit_status.code().ok_or("Could not get Rinf command exit code")?; + if exit_code != 0 { + process::exit(exit_code); + } Ok(()) } From 005b3df260b5554762677549ad64ac10e80f8c55 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Wed, 18 Sep 2024 13:51:48 +0900 Subject: [PATCH 2/6] Fix formatting --- rust_crate/src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rust_crate/src/main.rs b/rust_crate/src/main.rs index 319f7a4d..561c164d 100644 --- a/rust_crate/src/main.rs +++ b/rust_crate/src/main.rs @@ -28,7 +28,7 @@ fn main() -> Result<(), String> { .ok_or("Could not set the path for `protoc` installation")?, ); let install_result = protoc_prebuilt::init("25.2"); - let (protoc_binary_path, _) = install_result.map_err(|_| + let (protoc_binary_path, _) = install_result.map_err(|_| "Automatic installation of `protoc` failed, try installing it manually" )?; protoc_binary_path @@ -75,8 +75,11 @@ fn main() -> Result<(), String> { let mut command = process::Command::new(dart_path); command.args(["run", "rinf"]); command.args(&dart_command_args); - let exit_status = command.status().map_err(|_| "Could not run Rinf command")?; - let exit_code = exit_status.code().ok_or("Could not get Rinf command exit code")?; + let exit_status = + command.status().map_err(|_| "Could not run Rinf command")?; + let exit_code = exit_status + .code() + .ok_or("Could not get Rinf command exit code")?; if exit_code != 0 { process::exit(exit_code); } From c7a1f6e54cf25a44b27b084ad02d0548355ebc82 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Wed, 18 Sep 2024 14:05:39 +0900 Subject: [PATCH 3/6] Use exit code 2 for Dart command errors --- flutter_package/bin/rinf.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flutter_package/bin/rinf.dart b/flutter_package/bin/rinf.dart index 7c76c3ce..ccbf9b17 100644 --- a/flutter_package/bin/rinf.dart +++ b/flutter_package/bin/rinf.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:args/command_runner.dart'; import 'package:chalkdart/chalkstrings.dart'; @@ -34,6 +36,8 @@ Future main(List args) async { } catch (error) { // Print the error gracefully without backtrace. print(error.toString().trim().red); + // Exit code 1 is assigned to Rust-side wrapper executable. + exit(2); } } From 526f2c5e6b4e2d0446bf2a29adb5ab666334a28c Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Wed, 18 Sep 2024 14:06:13 +0900 Subject: [PATCH 4/6] Format a comment --- flutter_package/bin/rinf.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter_package/bin/rinf.dart b/flutter_package/bin/rinf.dart index ccbf9b17..a2d405ce 100644 --- a/flutter_package/bin/rinf.dart +++ b/flutter_package/bin/rinf.dart @@ -12,7 +12,7 @@ import 'src/common.dart'; Future main(List args) async { // When running `dart run rinf`, // Unnecessary two lines of - //`Building package executable...\nBuilt rinf:rinf.` appear. + // `Building package executable...\nBuilt rinf:rinf.` appear. // Remove those before proceeding. removeCliLines(2); From 25e48d08c05cf36b53572045e5751483ad6f4e59 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Wed, 18 Sep 2024 14:07:45 +0900 Subject: [PATCH 5/6] Fix a sentence --- rust_crate/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust_crate/src/main.rs b/rust_crate/src/main.rs index 561c164d..891370e8 100644 --- a/rust_crate/src/main.rs +++ b/rust_crate/src/main.rs @@ -33,7 +33,7 @@ fn main() -> Result<(), String> { )?; protoc_binary_path .parent() - .ok_or("Could not get the parent of newly installed `protoc` path")? + .ok_or("Could not get the parent of newly-installed `protoc` path")? .to_path_buf() }; From f495cf59521c21211f7c5b7f99629f3845a4c4a7 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Wed, 18 Sep 2024 15:18:29 +0900 Subject: [PATCH 6/6] Update docs --- documentation/docs/running-and-building.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/documentation/docs/running-and-building.md b/documentation/docs/running-and-building.md index 26165297..7d4517eb 100644 --- a/documentation/docs/running-and-building.md +++ b/documentation/docs/running-and-building.md @@ -29,8 +29,8 @@ To serve[^3] the web application: [^3]: Note that Flutter apps in debug mode are known to be quite slow on the web. It is recommended to use release mode when testing on a web browser. Debug mode can be used if you need to analyze the code more deeply, without the `--release` argument. ```bash title="CLI" -rinf wasm --release -flutter run --release # Choose a browser +rinf wasm +flutter run --web-header=Cross-Origin-Opener-Policy=same-origin --web-header=Cross-Origin-Embedder-Policy=require-corp ``` To build the optimized release version of the web application[^4]: @@ -42,6 +42,12 @@ rinf wasm --release flutter build web ``` +Since repeatedly writing web header arguments during development can be overwhelming, Rinf provides a convenient command that prints the full Flutter web command. + +```bash title="CLI" +rinf server +``` + When deploying your web app on a web server, ensure that your web server is configured to include cross-origin-related HTTP headers in its responses. These headers enable web browsers using your website to gain access to `SharedArrayBuffer` web API, which is something similar to shared memory on the web. - [`Cross-Origin-Opener-Policy`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy): `same-origin`