aboutsummaryrefslogtreecommitdiff
path: root/bundle/src-tauri
diff options
context:
space:
mode:
Diffstat (limited to 'bundle/src-tauri')
-rw-r--r--bundle/src-tauri/Cargo.lock1
-rw-r--r--bundle/src-tauri/Cargo.toml3
-rw-r--r--bundle/src-tauri/build.rs2
-rw-r--r--bundle/src-tauri/src/compiler.rs41
-rw-r--r--bundle/src-tauri/src/main.rs9
-rw-r--r--bundle/src-tauri/tauri.conf.json14
-rw-r--r--bundle/src-tauri/tauri.windows.conf.json8
7 files changed, 74 insertions, 4 deletions
diff --git a/bundle/src-tauri/Cargo.lock b/bundle/src-tauri/Cargo.lock
index 7fa057e..c461524 100644
--- a/bundle/src-tauri/Cargo.lock
+++ b/bundle/src-tauri/Cargo.lock
@@ -392,6 +392,7 @@ dependencies = [
name = "cpsc-bundle"
version = "0.1.0"
dependencies = [
+ "flate2",
"serde",
"tauri",
"tauri-build",
diff --git a/bundle/src-tauri/Cargo.toml b/bundle/src-tauri/Cargo.toml
index 4a61998..573db28 100644
--- a/bundle/src-tauri/Cargo.toml
+++ b/bundle/src-tauri/Cargo.toml
@@ -13,6 +13,9 @@ tauri-plugin-dialog = "2"
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["process", "io-util", "sync", "macros", "rt-multi-thread", "time"] }
+[target.'cfg(windows)'.dependencies]
+flate2 = "1"
+
[profile.release]
strip = true
lto = true
diff --git a/bundle/src-tauri/build.rs b/bundle/src-tauri/build.rs
index d860e1e..bf7e5df 100644
--- a/bundle/src-tauri/build.rs
+++ b/bundle/src-tauri/build.rs
@@ -1,3 +1,5 @@
fn main() {
+ #[cfg(windows)]
+ println!("cargo:rerun-if-changed=binaries/cpsc.exe.gz");
tauri_build::build()
}
diff --git a/bundle/src-tauri/src/compiler.rs b/bundle/src-tauri/src/compiler.rs
new file mode 100644
index 0000000..275a707
--- /dev/null
+++ b/bundle/src-tauri/src/compiler.rs
@@ -0,0 +1,41 @@
+use std::path::PathBuf;
+
+// Keep startup failures available to the UI, including an unwritable working directory.
+pub struct Compiler(pub Result<PathBuf, String>);
+
+impl Compiler {
+ pub fn load() -> Self {
+ Self(executable().map_err(|error| format!("Cannot load compiler: {error}")))
+ }
+}
+
+#[cfg(not(windows))]
+fn executable() -> std::io::Result<PathBuf> {
+ Ok(std::env::current_exe()?.with_file_name("cpsc"))
+}
+
+#[cfg(windows)]
+fn executable() -> std::io::Result<PathBuf> {
+ use std::{
+ fs::{self, File},
+ io,
+ };
+
+ let directory = std::env::current_dir()?;
+ let destination = directory.join("cpsc.exe");
+ let staged = directory.join(format!(".cpsc-{}.tmp", std::process::id()));
+ let result = (|| {
+ let mut compressed = flate2::read::GzDecoder::new(
+ &include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/binaries/cpsc.exe.gz"))[..],
+ );
+ let mut file = File::create(&staged)?;
+ io::copy(&mut compressed, &mut file)?;
+ drop(file);
+ fs::rename(&staged, &destination)?;
+ Ok(destination)
+ })();
+ if result.is_err() {
+ let _ = fs::remove_file(staged);
+ }
+ result
+}
diff --git a/bundle/src-tauri/src/main.rs b/bundle/src-tauri/src/main.rs
index 96f040c..07f25b3 100644
--- a/bundle/src-tauri/src/main.rs
+++ b/bundle/src-tauri/src/main.rs
@@ -1,6 +1,8 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
+mod compiler;
mod runner;
+use compiler::Compiler;
use runner::{OutputEvent, Runner};
use tauri::{ipc::Channel, Manager, State};
@@ -20,10 +22,9 @@ async fn run_file(
input: String,
output: Channel<OutputEvent>,
runner: State<'_, Runner>,
+ compiler: State<'_, Compiler>,
) -> Result<(), String> {
- let executable = std::env::current_exe()
- .map_err(|error| error.to_string())?
- .with_file_name(if cfg!(windows) { "cpsc.exe" } else { "cpsc" });
+ let executable = compiler.inner().0.clone()?;
let result = runner
.run(executable, path.into(), input, |stream, bytes| {
let _ = output.send(OutputEvent::Data {
@@ -47,9 +48,11 @@ async fn stop_run(runner: State<'_, Runner>) -> Result<(), String> {
}
fn main() {
+ let compiler = Compiler::load();
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.manage(Runner::default())
+ .manage(compiler)
.invoke_handler(tauri::generate_handler![
read_file, write_file, run_file, stop_run
])
diff --git a/bundle/src-tauri/tauri.conf.json b/bundle/src-tauri/tauri.conf.json
index 3d2e88a..d343e51 100644
--- a/bundle/src-tauri/tauri.conf.json
+++ b/bundle/src-tauri/tauri.conf.json
@@ -18,8 +18,20 @@
"bundle": {
"active": true,
"icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"],
- "targets": ["nsis", "dmg"],
+ "targets": ["app"],
"externalBin": ["binaries/cpsc"],
+ "resources": {
+ "../../LICENSE": "LICENSE",
+ "../ThirdPartyNotices.md": "ThirdPartyNotices.md",
+ "../../plugin/ThirdPartyNotices.md": "licenses/plugin.md",
+ "../vendor/vscode/LICENSE.txt": "licenses/vscode.txt",
+ "../node_modules/monaco-editor/LICENSE": "licenses/monaco-editor.txt",
+ "../node_modules/vscode-textmate/LICENSE.md": "licenses/vscode-textmate.txt",
+ "../node_modules/vscode-oniguruma/LICENSE.txt": "licenses/vscode-oniguruma.txt",
+ "../node_modules/jsonc-parser/LICENSE.md": "licenses/jsonc-parser.txt",
+ "../node_modules/@tauri-apps/api/LICENSE-MIT": "licenses/tauri-mit.txt",
+ "../node_modules/@tauri-apps/api/LICENSE-APACHE-2.0": "licenses/tauri-apache.txt"
+ },
"macOS": { "minimumSystemVersion": "15.0" }
}
}
diff --git a/bundle/src-tauri/tauri.windows.conf.json b/bundle/src-tauri/tauri.windows.conf.json
new file mode 100644
index 0000000..c0b39f5
--- /dev/null
+++ b/bundle/src-tauri/tauri.windows.conf.json
@@ -0,0 +1,8 @@
+{
+ "$schema": "https://schema.tauri.app/config/2",
+ "bundle": {
+ "active": false,
+ "externalBin": [],
+ "resources": []
+ }
+}