Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move common build code to sails-builder #157

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
657 changes: 376 additions & 281 deletions Cargo.lock

Large diffs are not rendered by default.

124 changes: 63 additions & 61 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
[workspace.package]
version = "0.0.1"
authors = ["Gear Technologies"]
edition = "2021"
license = "GPL-3.0"

[workspace]
resolver = "2"
members = [
"client-gen",
"examples/puppeteer/app",
"examples/puppeteer/wasm",
"examples/rmrk/catalog/app",
"examples/rmrk/catalog/wasm",
"examples/rmrk/resource/app",
"examples/rmrk/resource/wasm",
"examples/this-that-svc/app",
"examples/this-that-svc/wasm",
"idl-gen",
"idl-parser",
"macros",
"macros/core",
"rtl",
]

[workspace.dependencies]
anyhow = "1"
convert-case = { package = "convert_case", version = "0.6" }
futures = { version = "0.3", default-features = false }
gear-core-errors = "1.4.0"
git-download = "0.1"
gstd = "1.4.0"
gtest = "1.4.0"
gwasm-builder = { package = "gear-wasm-builder", version = "1.4.0" }
handlebars = "4.4"
hashbrown = "0.14"
hex = { version = "0.4", default-features = false }
insta = "1.38"
itertools = "0.12"
lalrpop = { version = "0.20", default-features = false }
lalrpop-util = "0.20"
logos = "0.13"
parity-scale-codec = { version = "3.6", default-features = false }
prettyplease = "0.2"
primitive-types = { version = "0.12", default-features = false }
proc-macro-error = "1.0"
proc-macro2 = { version = "1", default-features = false }
quote = "1.0"
sails-client-gen = { path = "client-gen" }
sails-idl-gen = { path = "idl-gen" }
sails-idl-parser = { path = "idl-parser" }
sails-macros = { path = "macros" }
sails-rtl = { path = "rtl" }
scale-info = { version = "2.11", default-features = false }
serde = "1.0"
serde-json = { package = "serde_json", version = "1.0" }
syn = "2.0"
thiserror = "1.0"
thiserror-no-std = "2.0"
tokio = "1.37"
trybuild = "1"
[workspace.package]
version = "0.0.1"
authors = ["Gear Technologies"]
edition = "2021"
license = "GPL-3.0"

[workspace]
resolver = "2"
members = [
"builder",
"client-gen",
"examples/puppeteer/app",
"examples/puppeteer/wasm",
"examples/rmrk/catalog/app",
"examples/rmrk/catalog/wasm",
"examples/rmrk/resource/app",
"examples/rmrk/resource/wasm",
"examples/this-that-svc/app",
"examples/this-that-svc/wasm",
"idl-gen",
"idl-parser",
"macros",
"macros/core",
"rtl",
]

[workspace.dependencies]
anyhow = "1"
convert-case = { package = "convert_case", version = "0.6" }
futures = { version = "0.3", default-features = false }
gear-core-errors = "1.4.0"
git-download = "0.1"
gstd = "1.4.0"
gtest = "1.4.0"
gwasm-builder = { package = "gear-wasm-builder", version = "1.4.0" }
handlebars = "4.4"
hashbrown = "0.14"
hex = { version = "0.4", default-features = false }
insta = "1.38"
itertools = "0.12"
lalrpop = { version = "0.20", default-features = false }
lalrpop-util = "0.20"
logos = "0.13"
parity-scale-codec = { version = "3.6", default-features = false }
prettyplease = "0.2"
primitive-types = { version = "0.12", default-features = false }
proc-macro-error = "1.0"
proc-macro2 = { version = "1", default-features = false }
quote = "1.0"
sails-builder = { path = "builder" }
sails-client-gen = { path = "client-gen" }
sails-idl-gen = { path = "idl-gen" }
sails-idl-parser = { path = "idl-parser" }
sails-macros = { path = "macros" }
sails-rtl = { path = "rtl" }
scale-info = { version = "2.11", default-features = false }
serde = "1.0"
serde-json = { package = "serde_json", version = "1.0" }
syn = "2.0"
thiserror = "1.0"
thiserror-no-std = "2.0"
tokio = "1.37"
trybuild = "1"
13 changes: 13 additions & 0 deletions builder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "sails-builder"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sails-idl-gen.workspace = true
sails-rtl.workspace = true
gwasm-builder.workspace = true
43 changes: 43 additions & 0 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use sails_rtl::meta::{ProgramMeta, ServiceMeta};
use std::{env, fs::File, path::PathBuf};

pub struct Builder {
idl_file_path: PathBuf,
}

impl Default for Builder {
fn default() -> Self {
Self::new()
}
}

impl Builder {
pub fn new() -> Self {
let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();

let idl_file_path = PathBuf::from(manifest_dir).join(format!("{}.idl", pkg_name));

Self { idl_file_path }
}

pub fn build(self) -> Self {
gwasm_builder::build();

self
}

pub fn generate_service_idl<S: ServiceMeta>(self) -> Self {
let idl_file = File::create(&self.idl_file_path).unwrap();
sails_idl_gen::service::generate_idl::<S>(idl_file).unwrap();

self
}

pub fn generate_program_idl<P: ProgramMeta>(self) -> Self {
let idl_file = File::create(&self.idl_file_path).unwrap();
sails_idl_gen::program::generate_idl::<P>(idl_file).unwrap();

self
}
}
2 changes: 1 addition & 1 deletion examples/puppeteer/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ sails-rtl.workspace = true
puppeteer-app = { path = "../app" }

[build-dependencies]
gwasm-builder.workspace = true
sails-builder.workspace = true
sails-idl-gen.workspace = true
puppeteer-app = { path = "../app" }
4 changes: 3 additions & 1 deletion examples/puppeteer/wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use sails_builder::Builder;

fn main() {
gwasm_builder::build();
Builder::new().build();
}
3 changes: 1 addition & 2 deletions examples/rmrk/catalog/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ edition = "2021"
rmrk-catalog-app = { path = "../app" }

[build-dependencies]
gwasm-builder.workspace = true
sails-idl-gen.workspace = true
rmrk-catalog-app = { path = "../app" } # Used for generating IDL (service metadata)
sails-builder.workspace = true
13 changes: 2 additions & 11 deletions examples/rmrk/catalog/wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
use rmrk_catalog_app::Program;
use sails_idl_gen::program;
use std::{env, fs::File, path::PathBuf};
use sails_builder::Builder;

fn main() {
gwasm_builder::build();

let manifest_dir_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let idl_file_path = manifest_dir_path.join("rmrk-catalog.idl");

let idl_file = File::create(idl_file_path).unwrap();

program::generate_idl::<Program>(idl_file).unwrap();
Builder::new().build().generate_program_idl::<Program>();
}
3 changes: 1 addition & 2 deletions examples/rmrk/resource/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ edition = "2021"
rmrk-resource-app = { path = "../app" }

[build-dependencies]
gwasm-builder.workspace = true
rmrk-resource-app = { path = "../app" }
sails-idl-gen.workspace = true
sails-builder.workspace = true

[dev-dependencies]
gtest.workspace = true
Expand Down
13 changes: 2 additions & 11 deletions examples/rmrk/resource/wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
use rmrk_resource_app::Program;
use sails_idl_gen::program;
use std::{env, fs::File, path::PathBuf};
use sails_builder::Builder;

fn main() {
gwasm_builder::build();

let manifest_dir_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let idl_file_path = manifest_dir_path.join("rmrk-resource.idl");

let idl_file = File::create(idl_file_path).unwrap();

program::generate_idl::<Program>(idl_file).unwrap();
Builder::new().build().generate_program_idl::<Program>();
}
3 changes: 1 addition & 2 deletions examples/this-that-svc/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ sails-rtl.workspace = true
this-that-svc-app = { path = "../app" }

[build-dependencies]
gwasm-builder.workspace = true
sails-idl-gen.workspace = true
sails-builder.workspace = true
this-that-svc-app = { path = "../app" }
13 changes: 2 additions & 11 deletions examples/this-that-svc/wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
use sails_idl_gen::service;
use std::{env, fs::File, path::PathBuf};
use sails_builder::Builder;
use this_that_svc_app::MyService;

fn main() {
gwasm_builder::build();

let manifest_dir_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let idl_file_path = manifest_dir_path.join("this-that-svc.idl");

let idl_file = File::create(idl_file_path).unwrap();

service::generate_idl::<MyService>(idl_file).unwrap();
Builder::new().build().generate_service_idl::<MyService>();
}