Skip to content

Commit

Permalink
add unity option for simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
s5suzuki committed Dec 10, 2023
1 parent 84669ed commit ba5ceb7
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 59 deletions.
165 changes: 115 additions & 50 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
31 changes: 31 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;
};

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() {
Expand Down
5 changes: 4 additions & 1 deletion src-tauri/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -86,6 +88,7 @@ impl Default for SimulatorOptions {
gpu_idx: -1,
window_width: 800,
window_height: 600,
unity: false,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"sidecar": true,
"args": true
},
{
"name": "simulator-unity",
"sidecar": true,
"args": true
},
{
"name": "SOEMAUTDServer",
"sidecar": true,
Expand Down Expand Up @@ -105,6 +110,7 @@
},
"externalBin": [
"simulator",
"simulator-unity",
"SOEMAUTDServer"
],
"windows": {
Expand Down
18 changes: 12 additions & 6 deletions src/lib/UI/Simulator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -48,7 +48,7 @@ Copyright (c) 2023 Shun Suzuki. All rights reserved.
const cachedGPUs = writable<string | null>(null);
let availableGpus: string[] = [];
$: availableGpusNames = ["Auto"].concat(
availableGpus.map((gpu) => gpu.split(":")[1].trim())
availableGpus.map((gpu) => gpu.split(":")[1].trim()),
);
let handleRunClick = async () => {
Expand All @@ -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());
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -149,6 +152,9 @@ Copyright (c) 2023 Shun Suzuki. All rights reserved.
step="1"
/>

<label for="unity">Unity:</label>
<CheckBox id="unity" bind:checked={simulatorOptions.unity} />

<Button label="Run" click={handleRunClick} disabled={!!child} />
<Button label="Close" click={handleCloseClick} disabled={!child} />
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/lib/UI/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 10/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.
Expand Down Expand Up @@ -47,6 +47,7 @@ export interface SimulatorOptions {
gpu_idx: number;
window_width: number;
window_height: number;
unity: boolean;
}

export interface Options {
Expand Down

0 comments on commit ba5ceb7

Please sign in to comment.