Skip to content

Commit

Permalink
Include dapp and executor in rust-executor on crate level
Browse files Browse the repository at this point in the history
  • Loading branch information
lucksus committed Mar 21, 2024
1 parent 67e0af5 commit 7548928
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"scripts": {
"dev": "vite",
"build": "tsc && vite build && cp -r ./dist ../rust-executor/dapp",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
Expand Down
3 changes: 1 addition & 2 deletions rust-executor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ schema.gql
!src/js_core/pubsub_extension.js
!src/js_core/jwt_extension.js
!src/prolog_service/prolog_service_extension.js
!src/holochain_service/holochain_service_extension.js
dapp
!src/holochain_service/holochain_service_extension.js
8 changes: 8 additions & 0 deletions rust-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ repository = "https://github.com/perspect3vism/ad4m"
documentation = "https://docs.ad4m.dev"
readme = "README.md"

include = [
"src/**/*",
"dapp", # Symlink to the dapp directory
"executor", # Symlink to the executor directory
"build.rs",
"Cargo.toml"
]

[lib]
name = "rust_executor"
path = "src/lib.rs"
Expand Down
16 changes: 3 additions & 13 deletions rust-executor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use std::process::Command;

fn build_dapp() -> std::io::Result<()> {
let dapp_dir = Path::new("../dapp");
let dapp_dir = Path::new("./dapp");

// Navigate to the dapp directory
std::env::set_current_dir(&dapp_dir)?;
Expand All @@ -30,6 +30,7 @@ fn build_dapp() -> std::io::Result<()> {
Ok(())
}

#[allow(dead_code)]
fn copy_dir_recursive(source: &Path, target: &Path) -> std::io::Result<()> {
if source.is_dir() {
fs::create_dir_all(target)?;
Expand All @@ -45,7 +46,7 @@ fn copy_dir_recursive(source: &Path, target: &Path) -> std::io::Result<()> {
}

fn build_js_executor() -> std::io::Result<()> {
let executor_dir = Path::new("../executor");
let executor_dir = Path::new("./executor");

// Navigate to the executor directory
std::env::set_current_dir(&executor_dir)?;
Expand Down Expand Up @@ -83,17 +84,6 @@ fn main() {
std::process::exit(1);
}

let source_dir = "../dapp/public";
let target_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/dapp");

println!("Copying from {} to {}", source_dir, target_dir);


if let Err(err) = copy_dir_recursive(Path::new(source_dir), Path::new(target_dir)) {
eprintln!("Error copying directory: {}", err);
std::process::exit(1); // Exit with an error code to fail the build if the copy fails
}

if let Err(err) = build_js_executor() {
eprintln!("Error building JS executor: {}", err);
std::process::exit(1);
Expand Down
1 change: 1 addition & 0 deletions rust-executor/dapp
1 change: 1 addition & 0 deletions rust-executor/executor
4 changes: 2 additions & 2 deletions rust-executor/src/dapp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub(crate) async fn serve_dapp(port: u16) -> Result<(), Box<dyn std::error::Erro
..Config::debug_default()
};

let dir = relative!("dapp");
let dir = relative!("dapp/dist");
if !Path::new(dir).exists() {
return Err("Dapp directory not found".into());
}

rocket::build()
.configure(&config)
.mount("/", FileServer::from(relative!("dapp")))
.mount("/", FileServer::from(dir))
.launch()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion rust-executor/src/js_core/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn module_map() -> HashMap<String, String> {
);
map.insert(
"https://ad4m.runtime/executor".to_string(),
include_str!("../../../executor/lib/bundle.js").to_string(),
include_str!("../../executor/lib/bundle.js").to_string(),
);
map
}
Expand Down

0 comments on commit 7548928

Please sign in to comment.