Skip to content
Merged
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
21 changes: 20 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
rustup update stable && rustup default stable
- uses: taiki-e/install-action@sccache
- uses: taiki-e/install-action@nextest
- uses: taiki-e/install-action@nextest
- name: Run Tests
run: cargo nextest run --no-fail-fast --release
- name: Doc-tests
Expand All @@ -45,3 +44,23 @@ jobs:
run: cargo fmt --check
- name: Clippy
run: cargo clippy --all -- -D warnings

template:
name: Template
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Toolchain
run: rustup update stable && rustup default stable
- uses: taiki-e/install-action@sccache
- name: Test template service
run: |
cargo install --path crates/jade && cd
jade new my-service
cd my-service
cargo build
cargo test
ls target/jam
30 changes: 15 additions & 15 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ members = ["crates/*", "crates/jade/derive", "services/*"]
resolver = "2"

[workspace.package]
version = "0.0.13"
version = "0.0.15-pre.1"
edition = "2024"
authors = ["clearloop <[email protected]>"]
license = "GPL-3.0"
homepage = "https://spacejam.app"
repository = "https://github.com/spacejamapp/jade"

[workspace.dependencies]
cjam = { path = "crates/cli", version = "0.0.13" }
jade = { path = "crates/jade", default-features = false, version = "0.0.13" }
jade-derive = { path = "crates/jade/derive", version = "0.0.13" }
spacevm = { path = "crates/sys", package = "spacevm-sys", version = "0.0.13" }
testing = { path = "crates/testing", package = "jade-testing", version = "0.0.13" }
cjam = { path = "crates/cli", version = "0.0.15-pre.1" }
jade = { path = "crates/jade", default-features = false, version = "0.0.15-pre.1" }
jade-derive = { path = "crates/jade/derive", version = "0.0.15-pre.1" }
spacevm = { path = "crates/sys", package = "spacevm-sys", version = "0.0.15-pre.1" }
testing = { path = "crates/testing", package = "jade-testing", version = "0.0.15-pre.1" }

# services
nauth = { path = "services/nauth" }
stoken = { path = "services/stoken" }

# spacejam dependencies
codec = { package = "serde-jam", version = "0.0.13", default-features = false }
service = { package = "spacejam-service", version = "0.0.13", default-features = false }
codec = { package = "serde-jam", version = "0.0.14", default-features = false }
service = { package = "spacejam-service", version = "0.0.14", default-features = false }

# crates.io
anyhow = { version = "1.0.93", default-features = false }
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ Jade framework for building JAM services by [SpaceJam](https://spacejam.app).

## Quick Start

```bash
```
cargo install jade
jade new my-service
cd my-service
jade build
cargo build
cargo test
```

See also our template at [service-template](https://github.com/spacejamapp/service-template).
- See [the scripts in the CI][CI_TPL] for a working example
- For the template service generated via `jade new`, check [service-template][template]

## License

GPL-3.0

[CI_TPL]: https://github.com/spacejamapp/service-template/blob/main/.github/workflows/main.yml#L62-L66
[template]: https://github.com/spacejamapp/service-template
39 changes: 17 additions & 22 deletions crates/cli/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ pub fn build_pvm_blob(
crate_dir: &Path,
blob_type: BlobType,
out_dir: &Path,
install_rustc: bool,
profile: ProfileType,
) -> (String, PathBuf) {
let (target_name, target_json_path) = (
Expand Down Expand Up @@ -117,28 +116,24 @@ pub fn build_pvm_blob(
.split(|x| *x == b'\n')
.any(|x| x[..] == b"rust-src"[..])
{
if install_rustc {
println!("Installing rustc dependencies...");
let mut child = Command::new("rustup")
.args(["toolchain", "install", TOOLCHAIN, "-c", "rust-src"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()
.unwrap_or_else(|_| {
panic!(
"Failed to execute `rustup toolchain install {TOOLCHAIN} -c rust-src`.\n\
println!("Installing rustc dependencies...");
let mut child = Command::new("rustup")
.args(["toolchain", "install", TOOLCHAIN, "-c", "rust-src"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()
.unwrap_or_else(|_| {
panic!(
"Failed to execute `rustup toolchain install {TOOLCHAIN} -c rust-src`.\n\
Please install `rustup` to continue."
)
});
if !child
.wait()
.expect("Failed to execute rustup process")
.success()
{
panic!("Failed to install `rust-src` component of {TOOLCHAIN}.");
}
} else {
panic!("`rust-src` component of {TOOLCHAIN} is required to build the PVM binary.",);
)
});
if !child
.wait()
.expect("Failed to execute rustup process")
.success()
{
panic!("Failed to install `rust-src` component of {TOOLCHAIN}.");
}
}
println!("ℹ️ `rustup` and toolchain installed. Continuing build process...");
Expand Down
17 changes: 10 additions & 7 deletions crates/cli/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
manifest::{ModuleType, Profile},
};
use clap::Parser;
use std::path::PathBuf;
use std::{fs, path::PathBuf};

/// CLI utility for building PVM code blobs, particularly services and authorizers.
#[derive(Parser, Debug, Default)]
Expand All @@ -19,11 +19,8 @@ pub struct Build {
/// Module type to build.
#[arg(short, long, value_enum, default_value_t = ModuleType::Automatic)]
pub module: ModuleType,
/// Install rustc dependencies if missing.
#[arg(long)]
auto_install: bool,
/// The build profile to use.
#[arg(short, long, value_enum, default_value_t = Profile::Release)]
#[arg(long, value_enum, default_value_t = Profile::Release)]
profile: Profile,
/// The target directory to build to.
#[arg(short, long)]
Expand Down Expand Up @@ -61,13 +58,19 @@ impl Build {
ModuleType::CoreVmGuest => builder::BlobType::CoreVmGuest,
};

let target = etc::find_up("target")?;
let target = etc::find_up("Cargo.toml")?
.parent()
.expect("Could not find the workspace root")
.join("target");
if !target.exists() {
fs::create_dir_all(&target)?;
}

let out_dir = self.target.clone().unwrap_or(target);
let (crate_name, pvm_path) = builder::build_pvm_blob(
&crate_dir,
blob_type,
out_dir.as_path(),
self.auto_install,
self.profile.clone().into(),
);

Expand Down
4 changes: 2 additions & 2 deletions crates/jade/derive/src/accumulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub fn accumulate(_args: TokenStream, input: TokenStream) -> TokenStream {
let buf = unsafe { core::slice::from_raw_parts(ptr as *const u8, size as usize) };
let jade::service::vm::AccumulateParams {slot, id, results} =
jade::codec::decode(buf).expect("failed to decode accumulate parameters");
let operands = jade::host::fetch::operands().expect("failed to fetch operands");
if let Some(result) = #funame(slot, id, operands) {
let items = jade::host::fetch::items().expect("failed to fetch accumulate items");
if let Some(result) = #funame(slot, id, items) {
((&result).as_ptr() as u64, result.len() as u64)
} else {
(0, 0)
Expand Down
4 changes: 2 additions & 2 deletions crates/jade/src/host/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub mod fetch {
use super::*;
use crate::prelude::{Vec, vec};
use anyhow::Result;
use service::vm::Operand;
use service::vm::AccumulateItem;

/// Fetch a value from the storage
pub fn operands() -> Result<Vec<Operand>> {
pub fn items() -> Result<Vec<AccumulateItem>> {
let len = unsafe { import::fetch(core::ptr::null_mut(), 0, 0, 14, 0, 0) };
let mut target = vec![0; len as usize];
let _ = unsafe { import::fetch(target.as_mut_ptr(), 0, len as u64, 14, 0, 0) };
Expand Down
4 changes: 2 additions & 2 deletions crates/sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::{
process::{Command, Stdio},
};

const LIB_BASE: &str = "https://github.com/spacejamapp/specjam/releases/download/0.7.0-pre.9";
const LIB_NAME: &str = "spacevm-0.7.0";
const LIB_BASE: &str = "https://github.com/spacejamapp/specjam/releases/download/0.7.1-pre.1";
const LIB_NAME: &str = "spacevm-0.7.1";
const PLATFORMS: [&str; 4] = ["linux-amd64", "linux-arm64", "macos-amd64", "macos-arm64"];

fn main() -> std::io::Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions crates/testing/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use service::{
ValidatorData,
},
service::{
Privileges, RefineLoad, ServiceAccount, WorkExecResult, WorkPackage, WorkResult,
Privileges, RefineLoad, ServiceAccount, WorkDigest, WorkExecResult, WorkPackage,
result::Executed,
},
vm::Operand,
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Jam {
///
/// NOTE: run refine for all work items
#[tracing::instrument(name = "refine", skip_all)]
pub fn refine(&mut self, work: &WorkPackage) -> Result<Vec<WorkResult>> {
pub fn refine(&mut self, work: &WorkPackage) -> Result<Vec<WorkDigest>> {
tracing::debug!("package: items={}", work.items.len());
if work.items.is_empty() {
anyhow::bail!("no work items");
Expand All @@ -114,7 +114,7 @@ impl Jam {
));
}

result.push(WorkResult {
result.push(WorkDigest {
service_id: item.service,
code_hash: item.code_hash,
payload_hash: Default::default(),
Expand All @@ -139,7 +139,7 @@ impl Jam {
/// 2. run accumulate for all work items
/// 3. return the accumulated result
#[tracing::instrument(name = "accumulate", skip_all)]
pub fn accumulate(&mut self, results: Vec<WorkResult>) -> Result<Vec<Accumulated>> {
pub fn accumulate(&mut self, results: Vec<WorkDigest>) -> Result<Vec<Accumulated>> {
tracing::debug!("work: items={}", results.len());
if results.is_empty() {
anyhow::bail!("no results");
Expand Down
Loading