Skip to content

Commit

Permalink
Get linux and windows builds working
Browse files Browse the repository at this point in the history
  • Loading branch information
smj-edison committed Feb 9, 2024
1 parent 83dfc36 commit ca8c514
Show file tree
Hide file tree
Showing 21 changed files with 234 additions and 121 deletions.
40 changes: 40 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

ROOT=$(pwd)
VERSION="v0.1.0-alpha"

# part 0, make sure targets are present
rustup target add x86_64-unknown-linux-gnu
rustup target add x86_64-pc-windows-gnu

# part 1, setup
mkdir -p build
rm -Rf build/*
mkdir -p build/linux
mkdir -p build/windows

# part 2, build the backend
cd "$ROOT/vpo-backend"

cargo build --release
cargo build --release --target x86_64-pc-windows-gnu

cp target/release/vpo-backend $ROOT/build/linux
cp target/x86_64-pc-windows-gnu/release/vpo-backend.exe $ROOT/build/windows

# part 3, build the frontend
cd $ROOT/vpo-frontend

npm run build

cp -R build $ROOT/build/linux/frontend
cp -R build $ROOT/build/windows/frontend

# part 4, package everything up
cd $ROOT/build/linux
tar -czvf "mjuo-linux-$VERSION.tar.gz" ./*
mv "mjuo-linux-$VERSION.tar.gz" ..

cd $ROOT/build/windows
zip -r "mjuo-windows-$VERSION.zip" .
mv "mjuo-windows-$VERSION.zip" ..
11 changes: 1 addition & 10 deletions vpo-backend/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
[target.wasm32-unknown-unknown]
rustflags = [
"-C",
"link-arg=--initial-memory=327680000",
]

[target.x86_64-unknown-linux-gnu]
rustflags = [
"-C",
"link-arg=-fuse-ld=lld",
]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
7 changes: 7 additions & 0 deletions vpo-backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vpo-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ddgg = { git = "https://github.com/smj-edison/ddgg", features = [
"serde",
"serde_string_indexes",
] }
path-slash = "0.2.1"

[lib]
crate-type = ["cdylib", "lib"]
Expand All @@ -69,7 +70,6 @@ walkdir = "2"


[profile.release]
lto = "thin"
opt-level = 3

[profile.dev]
Expand Down
16 changes: 12 additions & 4 deletions vpo-backend/ipc/src/file_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ use std::{
use tokio::runtime;
use tower_http::services::ServeDir;

pub fn start_file_server(root_folder: flume::Receiver<PathBuf>) -> JoinHandle<()> {
pub fn start_file_server_in(root_folder: PathBuf, port: u16) -> JoinHandle<()> {
let (sender, receiver) = flume::unbounded();
sender.send(root_folder).unwrap();

start_file_server(receiver, port)
}

pub fn start_file_server(root_folder: flume::Receiver<PathBuf>, port: u16) -> JoinHandle<()> {
thread::spawn(move || {
let rt = runtime::Builder::new_current_thread().enable_io().build().unwrap();

rt.block_on(async {
// wait for the first folder
let mut project_dir = root_folder.recv_async().await.expect("not closed");

loop {
let service = ServeDir::new(project_dir.clone());

let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 26643));
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], port));
let server = async {
hyper::Server::bind(&addr)
.serve(tower::make::Shared::new(service))
Expand All @@ -26,8 +34,8 @@ pub fn start_file_server(root_folder: flume::Receiver<PathBuf>) -> JoinHandle<()

// use select to terminate the server early
tokio::select! {
new_project_dir = root_folder.recv_async() => {
project_dir = new_project_dir.expect("not closed");
Ok(new_project_dir) = root_folder.recv_async() => {
project_dir = new_project_dir;
// if a new project dir comes in, it'll drop the file server
}
_ = server => {
Expand Down
23 changes: 22 additions & 1 deletion vpo-backend/node-engine/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use common::resource_manager::ResourceId;
use ddgg::GraphError;
use rhai::{EvalAltResult, ParseError};
use serde::Serialize;
use snafu::Snafu;

use crate::connection::{Socket, SocketType};
Expand Down Expand Up @@ -74,6 +75,15 @@ impl From<GraphError> for NodeError {
}
}

impl Serialize for NodeError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}

#[derive(Snafu, Debug)]
pub enum NodeWarning {
#[snafu(display("Value of type `{return_type}` was returned, ignoring"))]
Expand All @@ -84,11 +94,22 @@ pub enum NodeWarning {
RhaiParserFailure { parser_error: ParseError },
#[snafu(display("Internal node errors/warnings: {errors_and_warnings:?}"))]
InternalErrorsAndWarnings { errors_and_warnings: ErrorsAndWarnings },
#[snafu(display("Resource missing: {resource:?}"))]
ResourceMissing { resource: ResourceId },
}

impl Serialize for NodeWarning {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}

pub type NodeResult<T> = Result<NodeOk<T>, NodeError>;

#[derive(Debug, Default)]
#[derive(Debug, Default, Serialize)]
pub struct ErrorsAndWarnings {
pub errors: Vec<(NodeIndex, NodeError)>,
pub warnings: Vec<(NodeIndex, NodeWarning)>,
Expand Down
9 changes: 9 additions & 0 deletions vpo-backend/node-engine/src/node/calculate_traversal_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ pub fn generate_io_spec(
for needed_resource in &needed_resources {
let resource_index = resources.get_resource_index(needed_resource);

if resource_index.is_none() {
warnings.push((
*node_index,
NodeWarning::ResourceMissing {
resource: needed_resource.clone(),
},
));
}

resources_tracking.push((needed_resource.clone(), resource_index));
}

Expand Down
2 changes: 1 addition & 1 deletion vpo-backend/node-engine/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl NodeIo {
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct InitResult {
pub changed_properties: Option<SeaHashMap<String, Property>>,
pub needed_resources: Vec<ResourceId>,
Expand Down
38 changes: 20 additions & 18 deletions vpo-backend/node-engine/src/nodes/rank_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@ impl NodeRuntime for RankPlayerNode {
self.polyphony = polyphony as usize;
}

let rank_resource = params
.props
.get("rank")
.and_then(|x| x.clone().as_resource())
.and_then(|resource_id| {
params
.resources
.ranks
.borrow_resource_by_id(&resource_id.resource)
.map(|resource| (resource_id.clone(), resource))
});

let needed_resources = if let Some((id, rank)) = rank_resource {
let (player, needed_resources) = RankPlayer::new(id, rank, self.polyphony, params.sound_config.sample_rate);

self.player = player;

needed_resources
let rank_resource_id = params.props.get("rank").and_then(|x| x.clone().as_resource());

let rank = rank_resource_id
.as_ref()
.and_then(|resource_id| params.resources.ranks.borrow_resource_by_id(&resource_id.resource));

let needed_resources = if let Some(resource_id) = rank_resource_id {
if let Some(rank) = rank {
let (player, needed_resources) =
RankPlayer::new(resource_id, rank, self.polyphony, params.sound_config.sample_rate);

self.player = player;

needed_resources
} else {
return Ok(NodeOk {
value: InitResult::default(),
warnings: vec![NodeWarning::ResourceMissing { resource: resource_id }],
});
}
} else {
vec![]
};
Expand Down
39 changes: 27 additions & 12 deletions vpo-backend/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use log::info;
use node_engine::resources::Resources;
use node_engine::state::GraphState;
use notify::{Config, Error, Event, RecommendedWatcher, RecursiveMode, Watcher};
use path_slash::PathExt;
use rayon::iter::{ParallelBridge, ParallelIterator};
use semver::Version;
use serde_json::{json, Value};
Expand Down Expand Up @@ -83,7 +84,11 @@ where
None
})
.map(|asset| {
let asset_key = asset.path().strip_prefix(path).unwrap().to_string_lossy().to_string();
let asset_path = asset.path().strip_prefix(path).unwrap();
let asset_key = get_resource_key(asset_path);

println!("path: {asset_path:?}, key: {asset_key}");

(asset_key, PathBuf::from(asset.path()))
});

Expand Down Expand Up @@ -115,34 +120,34 @@ pub fn load_single(
.whatever_context(format!("Could not strip \"{:?}\" of \"{:?}\"", file, root))?;

let resource_type = relative_file.iter().next().unwrap();
let resource = relative_file.strip_prefix(resource_type).unwrap().to_string_lossy();
let resource_key = get_resource_key(relative_file.strip_prefix(resource_type).unwrap());

info!("loading resource: `{:?}` of type {:?}", resource, resource_type);
info!("loading resource: `{:?}` of type {:?}", resource_key, resource_type);

match resource_type.to_string_lossy().as_ref() {
"ranks" => {
if resources.ranks.get_index(resource.as_ref()).is_some() {
resources.ranks.remove_resource(resource.as_ref());
if resources.ranks.get_index(resource_key.as_ref()).is_some() {
resources.ranks.remove_resource(resource_key.as_ref());
}

let rank = load_rank_from_file(file, &resources.samples)?;
resources.ranks.add_resource(resource.into_owned(), rank);
resources.ranks.add_resource(resource_key, rank);
}
"samples" => {
if resources.samples.get_index(resource.as_ref()).is_some() {
resources.samples.remove_resource(resource.as_ref());
if resources.samples.get_index(resource_key.as_ref()).is_some() {
resources.samples.remove_resource(resource_key.as_ref());
}

let sample = load_sample(file, &config)?;
resources.samples.add_resource(resource.into_owned(), sample);
resources.samples.add_resource(resource_key, sample);
}
"ui" => {
if resources.ui.get_index(resource.as_ref()).is_some() {
resources.ui.remove_resource(resource.as_ref());
if resources.ui.get_index(resource_key.as_ref()).is_some() {
resources.ui.remove_resource(resource_key.as_ref());
}

let ui_element = load_ui_from_file(file)?;
resources.ui.add_resource(resource.into_owned(), ui_element);
resources.ui.add_resource(resource_key, ui_element);
}
_ => {}
}
Expand Down Expand Up @@ -212,3 +217,13 @@ pub fn load_state(

Ok(rx)
}

fn get_resource_key(path: &Path) -> String {
#[cfg(windows)]
let asset_key = path.to_slash_lossy().to_string();

#[cfg(unix)]
let asset_key = path.to_string_lossy().to_string();

asset_key
}
6 changes: 0 additions & 6 deletions vpo-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ pub async fn handle_msg(

match result {
Ok(route_result) => {
if !route_result.engine_updates.is_empty() {
for update in route_result.engine_updates {
to_audio_thread.send(update).unwrap();
}
}

if route_result.new_project {
let _ = project_dir_sender.send(
global_state
Expand Down
10 changes: 7 additions & 3 deletions vpo-backend/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cell::RefCell;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use std::thread;

Expand All @@ -7,7 +8,7 @@ use futures::executor::LocalPool;
use futures::join;
use futures::task::LocalSpawnExt;
use futures::StreamExt;
use ipc::file_server::start_file_server;
use ipc::file_server::{start_file_server, start_file_server_in};

use node_engine::resources::Resources;
use node_engine::state::{FromNodeEngine, GraphState};
Expand All @@ -22,7 +23,7 @@ use vpo_backend::util::{send_graph_updates, send_resource_updates};
use vpo_backend::{handle_msg, start_ipc};

fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init();

let (to_server, from_server, _ipc_handle) = start_ipc(26642);

Expand All @@ -35,7 +36,10 @@ fn main() {
let (project_dir_sender, project_dir_receiver) = flume::unbounded();

let (mut file_watcher, mut from_file_watcher) = FileWatcher::new().unwrap();
let _file_server_handle = start_file_server(project_dir_receiver);
let _project_files_handle = start_file_server(project_dir_receiver, 26643);
let _frontend_server_handle = start_file_server_in(PathBuf::from("./frontend"), 26644);

println!("Welcome to MJUO! Please go to http://localhost:26644 in your browser to see the UI");

let resources_for_audio_thread = resources.clone();

Expand Down
1 change: 0 additions & 1 deletion vpo-backend/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use serde_json::Value;
use crate::{engine::ToAudioThread, errors::EngineError, state::GlobalState, Sender};
#[derive(Default)]
pub struct RouteReturn {
pub engine_updates: Vec<ToAudioThread>,
pub new_project: bool,
}

Expand Down
Loading

0 comments on commit ca8c514

Please sign in to comment.