diff --git a/build.py b/build.py index babcc11..ae88c67 100644 --- a/build.py +++ b/build.py @@ -148,62 +148,127 @@ def server_build(args): err("shaderc is not installed. Cannot build simulator.") sys.exit(-1) - with working_dir("."): - if config.is_windows(): - subprocess.run(["npm", "install"], shell=True).check_returncode() - else: - subprocess.run(["npm", "install"]).check_returncode() + shell = True if config.is_windows() else False + with working_dir("simulator"): + build_commands = [] if config.is_macos(): - command_x86 = [ - "cargo", - "build", - "--release", - "--target=x86_64-apple-darwin", - ] - command_aarch64 = [ - "cargo", - "build", - "--release", - "--target=aarch64-apple-darwin", - ] - - with working_dir("simulator"): - subprocess.run(command_x86).check_returncode() - subprocess.run(command_aarch64).check_returncode() - - with working_dir("SOEMAUTDServer"): - subprocess.run(command_x86).check_returncode() - subprocess.run(command_aarch64).check_returncode() - - if not args.external_only: - subprocess.run( - [ - "npm", - "run", - "tauri", - "build", - "--", - "--target", - "universal-apple-darwin", - ] - ).check_returncode() + build_commands.append( + [ + "cargo", + "build", + "--release", + "--target=x86_64-apple-darwin", + "--features", + "unity", + ] + ) + build_commands.append( + [ + "cargo", + "build", + "--release", + "--target=aarch64-apple-darwin", + "--features", + "unity", + ] + ) else: - command = ["cargo", "build", "--release"] + build_commands.append( + [ + "cargo", + "build", + "--release", + "--features", + "unity", + ] + ) + for command in build_commands: + subprocess.run(command).check_returncode() + if config.is_macos(): + shutil.copy( + "src-tauri/target/aarch64-apple-darwin/release/simulator", + "src-tauri/target/aarch64-apple-darwin/release/simulator-unity", + ) + shutil.copy( + "src-tauri/target/x86_64-apple-darwin/release/simulator", + "src-tauri/target/x86_64-apple-darwin/release/simulator-unity", + ) + elif config.is_windows(): + shutil.copy( + "src-tauri/target/release/simulator.exe", + "src-tauri/target/release/simulator-unity.exe", + ) + elif config.is_linux(): + shutil.copy( + "src-tauri/target/release/simulator", + "src-tauri/target/release/simulator-unity", + ) - with working_dir("simulator"): - subprocess.run(command).check_returncode() + with working_dir("simulator"): + build_commands = [] + if config.is_macos(): + build_commands.append( + [ + "cargo", + "build", + "--release", + "--target=x86_64-apple-darwin", + ] + ) + build_commands.append( + [ + "cargo", + "build", + "--release", + "--target=aarch64-apple-darwin", + ] + ) + else: + build_commands.append(["cargo", "build", "--release"]) + for command in build_commands: + subprocess.run(command).check_returncode() - with working_dir("SOEMAUTDServer"): - subprocess.run(command).check_returncode() + with working_dir("SOEMAUTDServer"): + build_commands = [] + if config.is_macos(): + build_commands.append( + [ + "cargo", + "build", + "--release", + "--target=x86_64-apple-darwin", + ] + ) + build_commands.append( + [ + "cargo", + "build", + "--release", + "--target=aarch64-apple-darwin", + ] + ) + else: + build_commands.append(["cargo", "build", "--release"]) + for command in build_commands: + subprocess.run(command).check_returncode() - if not args.external_only: - if config.is_windows(): - subprocess.run( - ["npm", "run", "tauri", "build"], shell=True - ).check_returncode() - else: - subprocess.run(["npm", "run", "tauri", "build"]).check_returncode() + subprocess.run(["npm", "install"], shell=shell).check_returncode() + if not args.external_only: + if config.is_macos(): + subprocess.run( + [ + "npm", + "run", + "tauri", + "build", + "--", + "--target", + "universal-apple-darwin", + ] + ).check_returncode() + else: + subprocess.run(["npm", "run", "tauri", "build"], shell=shell).check_returncode() def server_clear(args): diff --git a/simulator/Cargo.toml b/simulator/Cargo.toml index 2df4a29..7a59c01 100644 --- a/simulator/Cargo.toml +++ b/simulator/Cargo.toml @@ -41,6 +41,7 @@ tracing-core = "0.1.31" [features] default = [] -use_meter = ["autd3/use_meter"] +use_meter = ["autd3/use_meter", "autd3-driver/use_meter"] left_handed = [] enable_debug = [] +unity = ["use_meter", "left_handed"] diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 6ea7487..567df97 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -88,6 +88,37 @@ fn main() -> Result<(), Box> { )?; }; + if cfg!(target_os = "macos") { + std::fs::copy( + manifest_dir.join("./target/x86_64-apple-darwin/release/simulator-unity"), + manifest_dir.join("simulator-unity-x86_64-apple-darwin"), + )?; + std::fs::copy( + manifest_dir.join("./target/aarch64-apple-darwin/release/simulator-unity"), + manifest_dir.join("simulator-unity-aarch64-apple-darwin"), + )?; + Command::new("lipo") + .current_dir(manifest_dir) + .args([ + "-create", + "simulator-unity-x86_64-apple-darwin", + "simulator-unity-aarch64-apple-darwin", + "-output", + "simulator-unity-universal-apple-darwin", + ]) + .spawn()? + .wait()?; + } else { + std::fs::copy( + manifest_dir.join(format!("./target/release/simulator-unity{}", ext)), + manifest_dir.join(format!( + "simulator-unity-{}{}", + std::env::var("TARGET")?, + ext + )), + )?; + }; + // NOTICE let notice_path = manifest_dir.join("NOTICE"); if notice_path.exists() { diff --git a/src-tauri/src/options.rs b/src-tauri/src/options.rs index dc37243..831c533 100644 --- a/src-tauri/src/options.rs +++ b/src-tauri/src/options.rs @@ -4,7 +4,7 @@ * Created Date: 06/07/2023 * Author: Shun Suzuki * ----- - * Last Modified: 25/10/2023 + * Last Modified: 10/12/2023 * Modified By: Shun Suzuki (suzuki@hapis.k.u-tokyo.ac.jp) * ----- * Copyright (c) 2023 Shun Suzuki. All rights reserved. @@ -76,6 +76,8 @@ pub struct SimulatorOptions { pub gpu_idx: i32, pub window_width: u32, pub window_height: u32, + #[serde(default)] + pub unity: bool, } impl Default for SimulatorOptions { @@ -86,6 +88,7 @@ impl Default for SimulatorOptions { gpu_idx: -1, window_width: 800, window_height: 600, + unity: false, } } } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 2b22e2d..57603ff 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -42,6 +42,11 @@ "sidecar": true, "args": true }, + { + "name": "simulator-unity", + "sidecar": true, + "args": true + }, { "name": "SOEMAUTDServer", "sidecar": true, @@ -105,6 +110,7 @@ }, "externalBin": [ "simulator", + "simulator-unity", "SOEMAUTDServer" ], "windows": { diff --git a/src/lib/UI/Simulator.svelte b/src/lib/UI/Simulator.svelte index dae0bf8..f10b5aa 100644 --- a/src/lib/UI/Simulator.svelte +++ b/src/lib/UI/Simulator.svelte @@ -4,7 +4,7 @@ Project: AUTD Server Created Date: 06/07/2023 Author: Shun Suzuki ----- -Last Modified: 14/10/2023 +Last Modified: 10/12/2023 Modified By: Shun Suzuki (suzuki@hapis.k.u-tokyo.ac.jp) ----- Copyright (c) 2023 Shun Suzuki. All rights reserved. @@ -48,7 +48,7 @@ Copyright (c) 2023 Shun Suzuki. All rights reserved. const cachedGPUs = writable(null); let availableGpus: string[] = []; $: availableGpusNames = ["Auto"].concat( - availableGpus.map((gpu) => gpu.split(":")[1].trim()) + availableGpus.map((gpu) => gpu.split(":")[1].trim()), ); let handleRunClick = async () => { @@ -69,17 +69,19 @@ Copyright (c) 2023 Shun Suzuki. All rights reserved. args.push("-g"); args.push(simulatorOptions.gpu_idx.toString()); } - command = Command.sidecar("simulator", args); + command = simulatorOptions.unity + ? Command.sidecar("simulator-unity", args) + : Command.sidecar("simulator", args); child = await command.spawn(); command.stdout.on("data", (line) => consoleOutputQueue.update((v) => { return [...v, line.trimEnd()]; - }) + }), ); command.stderr.on("data", (line) => consoleOutputQueue.update((v) => { return [...v, line.trimEnd()]; - }) + }), ); command.on("error", () => handleCloseClick()); command.on("close", () => handleCloseClick()); @@ -109,7 +111,8 @@ Copyright (c) 2023 Shun Suzuki. All rights reserved. .map((s) => s.trim().replace(/ \(type .*\)$/g, "")); gpuName = ( availableGpus.find( - (gpu) => parseInt(gpu.split(":")[0].trim()) === simulatorOptions.gpu_idx + (gpu) => + parseInt(gpu.split(":")[0].trim()) === simulatorOptions.gpu_idx, ) ?? "0:Auto" ) .split(":")[1] @@ -149,6 +152,9 @@ Copyright (c) 2023 Shun Suzuki. All rights reserved. step="1" /> + + +