fix: Child process termination, workspaces, gitignore, logger

* Now using cargo workspaces, means you can `cargo run` from toplevel.
* Command execution now is cwd independent.
+ Added pretty_env_logger which lets us leverage log crate for easy
  logging.
* Windows now uses the win32job crate to ensure that all child processes
  will properly terminate when the parent process does.
+ Added empty rustfmt.toml to ensure everyone uses default rustfmt
  settings.
* Gitignore now ignores more stuff.
This commit is contained in:
Ryan Butler
2022-04-24 01:04:44 -04:00
parent 9fc9b66745
commit 90144f13c8
11 changed files with 6296 additions and 6933 deletions

8
.gitignore vendored
View File

@@ -1,6 +1,6 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
# JS/TS dependencies
/node_modules
/.pnp
.pnp.js
@@ -8,8 +8,9 @@
# testing
/coverage
# production
# Build artifacts
/build
/target
# misc
.DS_Store
@@ -22,5 +23,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
*.log
*.log

4117
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

3
Cargo.toml Normal file
View File

@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["src-tauri"]

9001
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@
"react-modal": "^3.14.4",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"slimevr-protocol": "file:../SlimeVR-Server/soloarxr-protocol",
"slimevr-protocol": "file:../SolarXR-Protocol",
"typescript": "^4.6.3",
"web-vitals": "^2.1.4"
},

0
rustfmt.toml Normal file
View File

11
src-tauri/Cargo.lock generated
View File

@@ -61,6 +61,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-build",
"win32job",
]
[[package]]
@@ -3640,6 +3641,16 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6c48bd20df7e4ced539c12f570f937c6b4884928a87fee70a479d72f031d4e0"
[[package]]
name = "win32job"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a14136f6c8be9146ac6345774ab32cb93e7985319b4a1b42abb663bd64235"
dependencies = [
"thiserror",
"winapi",
]
[[package]]
name = "winapi"
version = "0.3.9"

View File

@@ -7,7 +7,7 @@ license = ""
repository = ""
default-run = "app"
edition = "2021"
rust-version = "1.57"
rust-version = "1.59"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -15,14 +15,19 @@ rust-version = "1.57"
tauri-build = { version = "1.0.0-rc.5", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-rc.5", features = ["api-all"] }
serde_json = "1"
serde = { version = "1", features = ["derive"] }
tauri = { version = "1.0.0-rc.6", features = ["api-all"] }
pretty_env_logger = "0.4"
log = "0.4"
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
default = ["custom-protocol"]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]
custom-protocol = ["tauri/custom-protocol"]
[target.'cfg(windows)'.dependencies]
win32job = "1"

View File

@@ -1,3 +1,3 @@
fn main() {
tauri_build::build()
tauri_build::build()
}

View File

@@ -1,42 +1,50 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::path::PathBuf;
use std::process::Command;
use std::path::Path;
// the payload type must implement `Serialize` and `Clone`.
fn main() {
// Set up loggers and global handlers
{
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "info")
}
pretty_env_logger::init();
}
let child = if Path::new("run.bat").exists() {
let child = Command::new("cmd")
.args(["/C", "run.bat"])
.spawn()
.expect("sh command failed to start");
Some(child)
} else {
println!("No run.bat found, SKIP");
None
};
// Ensure child processes die when spawned on windows
#[cfg(target_os = "windows")]
{
use win32job::{ExtendedLimitInfo, Job};
tauri::Builder::default()
.on_window_event(|event| match event.event() {
tauri::WindowEvent::Destroyed => {
println!("DESTROYED");
let mut info = ExtendedLimitInfo::new();
info.limit_kill_on_job_close();
let job = Job::create_with_limit_info(&mut info).expect("Failed to create Job");
job.assign_current_process()
.expect("Failed to assign current process to Job");
}
_ => {}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
// We don't do anything with the job anymore, but we shouldn't drop it because that would
// terminate our process tree. So we intentionally leak it instead.
std::mem::forget(job);
}
child.map(|mut child| {
child.wait().unwrap();
println!("STOP?");
});
// Spawn server process
let runfile_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("run.bat");
if runfile_path.exists() {
Command::new("cmd")
.args(["/C", runfile_path.to_str().unwrap()])
.spawn()
.expect("sh command failed to start");
} else {
log::warn!("No run.bat found, SKIP");
}
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -64,4 +64,4 @@
"csp": null
}
}
}
}