diff --git a/.gitignore b/.gitignore index 835db166..a4ba062d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Rust output directory /target +# Headers for clibrojo +/include + # Roblox model and place files in the root, used for debugging /*.rbxm /*.rbxmx diff --git a/Cargo.lock b/Cargo.lock index 524044bd..c7fcbe40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,6 +181,13 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clibrojo" +version = "0.1.0" +dependencies = [ + "rojo 0.6.0-dev", +] + [[package]] name = "clicolors-control" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index f37be268..eb234dfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,12 +26,14 @@ user-plugins = [] members = [ "rojo-test", "rojo-insta-ext", + "clibrojo", ] default-members = [ ".", "rojo-test", "rojo-insta-ext", + "clibrojo", ] [lib] diff --git a/clibrojo/Cargo.toml b/clibrojo/Cargo.toml new file mode 100644 index 00000000..19420607 --- /dev/null +++ b/clibrojo/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "clibrojo" +version = "0.1.0" +authors = ["Lucien Greathouse "] +edition = "2018" + +[lib] +crate-type = ["cdylib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rojo = { path = ".." } diff --git a/clibrojo/README.md b/clibrojo/README.md new file mode 100644 index 00000000..3c315c55 --- /dev/null +++ b/clibrojo/README.md @@ -0,0 +1,4 @@ +# Rojo as a C Library +This is an experiment to expose a C API for Rojo that would be suitable for embedding it into an existing C/C++ application. + +I'm hoping to expand it to drop the HTTP layer and communicate through a channel, which could make it feasible to embed into an existing Roblox IDE with minimal changes or additional code. \ No newline at end of file diff --git a/clibrojo/src/lib.rs b/clibrojo/src/lib.rs new file mode 100644 index 00000000..0c3dbbf7 --- /dev/null +++ b/clibrojo/src/lib.rs @@ -0,0 +1,14 @@ +use std::{ffi::CStr, os::raw::c_char, path::PathBuf}; + +use librojo::commands::{serve, ServeOptions}; + +#[no_mangle] +pub extern "C" fn rojo_serve(path: *const c_char) { + let path = unsafe { PathBuf::from(CStr::from_ptr(path).to_str().unwrap()) }; + + serve(&ServeOptions { + fuzzy_project_path: path, + port: None, + }) + .unwrap(); +}