Misc Go interop fixes
This commit is contained in:
@ -3,8 +3,7 @@ use std::{fs::File, io::Read, path::{Path, PathBuf}, process::Command};
|
||||
use viperid::VResult;
|
||||
|
||||
pub struct GoBuilder {
|
||||
project_directory: PathBuf,
|
||||
entry_point: PathBuf
|
||||
project_directory: PathBuf
|
||||
}
|
||||
|
||||
impl GoBuilder {
|
||||
@ -27,15 +26,9 @@ impl GoBuilder {
|
||||
anyhow::bail!("project directory must exist: {}", project_directory.to_string_lossy())
|
||||
}
|
||||
|
||||
let entry_point = project_directory.join("main.go");
|
||||
if !entry_point.exists() {
|
||||
anyhow::bail!("entry point must exist: {}", entry_point.to_string_lossy())
|
||||
}
|
||||
|
||||
// OK, we should be able to do things with Go without any errors
|
||||
Ok(GoBuilder {
|
||||
project_directory: PathBuf::from(project_directory),
|
||||
entry_point
|
||||
})
|
||||
}
|
||||
|
||||
@ -47,24 +40,17 @@ impl GoBuilder {
|
||||
self.project_directory.to_string_lossy()
|
||||
);
|
||||
}
|
||||
if !self.entry_point.exists() {
|
||||
anyhow::bail!(
|
||||
"entry point disappeared: {}",
|
||||
self.entry_point.to_string_lossy()
|
||||
);
|
||||
}
|
||||
|
||||
let project_directory = &self.project_directory;
|
||||
let entry_point = &self.entry_point;
|
||||
let build_directory = project_directory.join("build");
|
||||
let build_directory = self.project_directory.join("build");
|
||||
let wasm_name = build_directory.join("game.wasm");
|
||||
|
||||
let mut child = Command::new("go")
|
||||
.args(["build", "-o"]).arg(&wasm_name)
|
||||
.arg("-C").arg(self.project_directory.clone())
|
||||
.args(["build", "-o"]).arg("build/game.wasm")
|
||||
.env("GOOS", "wasip1")
|
||||
.env("GOARCH", "wasm")
|
||||
.arg("-trimpath")
|
||||
.arg(entry_point)
|
||||
.arg(".")
|
||||
.spawn()?;
|
||||
let status = child.wait()?;
|
||||
if !status.success() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use viperid::{Device, VResult};
|
||||
use player::HOSTED_DEVICE;
|
||||
use viperid::VResult;
|
||||
|
||||
use crate::go_builder::GoBuilder;
|
||||
|
||||
@ -10,11 +11,10 @@ fn main() -> VResult<()> {
|
||||
let builder = GoBuilder::new(
|
||||
&PathBuf::from("example_project"))?;
|
||||
let wasm = builder.build()?;
|
||||
let device = Device::new();
|
||||
|
||||
let mut executor = player::Executor::new(device.share(), &wasm)?;
|
||||
let mut executor = player::Executor::new(&wasm)?;
|
||||
|
||||
minifb_host::host(device, || {
|
||||
minifb_host::host(HOSTED_DEVICE.with(|d| d.share()), || {
|
||||
executor.update();
|
||||
executor.get_error()?;
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user