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

Default deploy chainmail #859

Merged
merged 23 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4543892
add cmake support for cargo-psibase packages
James-Mart Sep 6, 2024
70f85da
remove support for POSTINSTALL and UI in cargo_psibase_package CMake …
James-Mart Sep 11, 2024
8b70917
add js_target for chainmail ui
James-Mart Sep 11, 2024
e3d8c1b
rename webmail to chainmail
James-Mart Sep 23, 2024
2fc6b51
trigger build of cargo psibase package from cmake
James-Mart Sep 11, 2024
6ba7714
more webmail->chainmail renaming
James-Mart Sep 23, 2024
d2a43ed
Add UI and postinstall script to chainmail
James-Mart Sep 23, 2024
8173706
add missing 'description' property to package config docs
James-Mart Sep 24, 2024
e7c6ece
fix incorrect custom command dependency in cargo_psibase_package
James-Mart Sep 24, 2024
e3624b8
add support for cargo_psibase_packages to depend on UI targets
James-Mart Sep 24, 2024
16a4562
minor refactor of events service rust wrapper
James-Mart Sep 24, 2024
6b75b2f
finish configuring the chainmail package with dependencies/version/ui
James-Mart Sep 24, 2024
140be1a
add events service indexing configuration to chainmail initialization
James-Mart Sep 24, 2024
eafed70
use cmake code compatible with cmake 3.16.3
James-Mart Sep 24, 2024
7d30f4d
add missing dependency
James-Mart Sep 24, 2024
edad8cc
fix cargo-psibase-package target name
James-Mart Sep 24, 2024
06496e4
ensure package dependencies are listed in meta.json in sorted order
James-Mart Sep 24, 2024
1aba738
try to fix 'no rule to make target'
James-Mart Sep 24, 2024
92dfc6c
remove incorrect required cmake function annotation
James-Mart Sep 24, 2024
304eb9a
move description property to 'package' table instead of 'package.meta…
James-Mart Sep 24, 2024
bd52ef9
fix - new packages weren't getting installed
James-Mart Sep 24, 2024
66b72fb
trying to fix 'no rule to make target'
James-Mart Sep 25, 2024
8f22270
add target-level dep on external project
James-Mart Sep 26, 2024
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
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ set(JS_DIRS
services/user/Supervisor/ui:Supervisor_js
services/user/Explorer/ui:Explorer_js
services/user/Tokens/ui:Tokens_js
services/user/Chainmail/ui:Chainmail_js
)
set(ADMIN_DIR services/user/XAdmin/ui:XAdmin_js)
set(COMMON_LIB_DIR services/user/CommonApi/common/packages/common-lib/:CommonApiCommonLib_js)
Expand Down Expand Up @@ -406,6 +407,12 @@ psibase_package(
DEPENDS ${ClientDataPlugin_DEP}
)

cargo_psibase_package(
OUTPUT ${SERVICE_DIR}/Chainmail.psi
PATH services/user/Chainmail
DEPENDS ${Chainmail_js_DEP}
)

psibase_package(
OUTPUT ${SERVICE_DIR}/AuthSig.psi
NAME AuthSig
Expand Down Expand Up @@ -725,7 +732,7 @@ psibase_package(
NAME DevDefault
VERSION ${PSIBASE_VERSION}
DESCRIPTION "All development services"
PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate ClientData CommonApi CpuLimit
PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate Chainmail ClientData CommonApi CpuLimit
Docs Events Explorer Fractal Invite Nft Packages Producers HttpServer
Sites SetCode Supervisor Symbol TokenUsers Tokens Transact Homepage
)
Expand All @@ -735,7 +742,7 @@ psibase_package(
NAME ProdDefault
VERSION ${PSIBASE_VERSION}
DESCRIPTION "All production services"
PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate ClientData CommonApi CpuLimit
PACKAGE_DEPENDS Accounts AuthAny AuthSig AuthDelegate Chainmail ClientData CommonApi CpuLimit
Docs Events Explorer Fractal Invite Nft Packages Producers HttpServer
Sites SetCode Supervisor Symbol Tokens Transact Homepage
)
Expand Down Expand Up @@ -764,7 +771,7 @@ function(write_package_index target dir)
endfunction()

write_package_index(package-index ${SERVICE_DIR}
Accounts AuthAny AuthSig ClientData CommonApi CpuLimit DevDefault ProdDefault
Accounts AuthAny AuthSig Chainmail ClientData CommonApi CpuLimit DevDefault ProdDefault
Docs Events Explorer Fractal Invite Nft Nop Minimal Packages Producers HttpServer
Sites SetCode Supervisor Symbol TokenUsers Tokens Transact Homepage)

Expand All @@ -774,6 +781,7 @@ install(
${SERVICE_DIR}/AuthAny.psi
${SERVICE_DIR}/AuthDelegate.psi
${SERVICE_DIR}/AuthSig.psi
${SERVICE_DIR}/Chainmail.psi
${SERVICE_DIR}/ClientData.psi
${SERVICE_DIR}/CommonApi.psi
${SERVICE_DIR}/DevDefault.psi
Expand Down
1 change: 1 addition & 0 deletions doc/psidk/src/development/services/rust-service/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Example:
[package]
name = "example"
version = "0.1.0"
description = "An example package"

[package.metadata.psibase]
# Builds example.psi
Expand Down
44 changes: 44 additions & 0 deletions libraries/psibase/sdk/pack_service.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,47 @@ function(psibase_package)
)
add_custom_target(${_NAME} ALL DEPENDS ${_OUTPUT})
endfunction()

# Description: - Use this function when you want to add additional details to a package that is
# built/managed by cargo-psibase, as opposed to packages built entirely using CMake.
# OUTPUT <filename> - [Required] The package file.
# PATH <filepath> - [Required] The path to the cargo workspace (e.g. `services/user/Branding`).
# DEPENDS <targets>... - Targets that this target depends on
function(cargo_psibase_package)
cmake_parse_arguments(ARG "" "PATH;OUTPUT;DEPENDS" "" ${ARGN})

if(NOT ARG_PATH OR NOT ARG_OUTPUT)
message(FATAL_ERROR "Both PATH and OUTPUT must be specified for cargo_psibase_package")
endif()

# Set variables
get_filename_component(PACKAGE_NAME ${ARG_OUTPUT} NAME)
get_filename_component(TARGET_NAME ${ARG_OUTPUT} NAME_WE)
set(PACKAGE_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_PATH}/target/wasm32-wasi/release/packages/${PACKAGE_NAME})

# Build the package if needed
ExternalProject_Add(${TARGET_NAME}_ext
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_PATH}
BUILD_BYPRODUCTS ${PACKAGE_OUTPUT}
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/rust/release/cargo-psibase package
--manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_PATH}/Cargo.toml
INSTALL_COMMAND ""
BUILD_ALWAYS 1
DEPENDS ${ARG_DEPENDS} cargo-psibase
)

add_custom_command(
OUTPUT ${PACKAGE_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E true
DEPENDS ${TARGET_NAME}_ext
)
swatanabe marked this conversation as resolved.
Show resolved Hide resolved

add_custom_command(
OUTPUT ${ARG_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PACKAGE_OUTPUT} ${ARG_OUTPUT}
DEPENDS ${PACKAGE_OUTPUT}
VERBATIM
)
add_custom_target(${TARGET_NAME} ALL DEPENDS ${ARG_OUTPUT} cargo-psibase)
endfunction()
3 changes: 2 additions & 1 deletion rust/cargo-psibase/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,14 @@ pub async fn build_package(
}
};

let meta = Meta {
let mut meta = Meta {
name: package_name.to_string(),
version: package_version.to_string(),
description: package_description.unwrap_or_else(|| package_name.to_string()),
depends,
accounts,
};
meta.depends.sort_by(|a, b| a.name.cmp(&b.name));

let mut service_wasms = Vec::new();
for (service, info, id) in services {
Expand Down
10 changes: 3 additions & 7 deletions rust/psibase/src/services/events.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#[crate::service(name = "events", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
mod service {
use crate::{AccountNumber, DbId, MethodNumber, Schema};

#[action]
fn setSchema(schema: crate::Schema) {
fn setSchema(schema: Schema) {
unimplemented!()
}

#[action]
fn addIndex(
db_id: crate::DbId,
service: crate::AccountNumber,
event: crate::MethodNumber,
column: u8,
) {
fn addIndex(db_id: DbId, service: AccountNumber, event: MethodNumber, column: u8) {
unimplemented!()
}
}
2 changes: 1 addition & 1 deletion rust/test_package/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "test_package"
description = "Test for package building"
version.workspace = true
rust-version.workspace = true
repository.workspace = true
Expand All @@ -9,7 +10,6 @@ publish = false

[package.metadata.psibase]
package-name = "TestPackage"
description = "Test for package building"
services = ["tpack"]

[lib]
Expand Down
6 changes: 3 additions & 3 deletions services/user/Chainmail/Cargo.lock

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

22 changes: 14 additions & 8 deletions services/user/Chainmail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["service", "plugin"]

[workspace.package]
version = "0.1.0"
version = "0.12.0"
rust-version = "1.64"
edition = "2021"
repository = "https://github.com/gofractally/psibase"
Expand All @@ -12,6 +12,17 @@ publish = false

[package]
name = "chainmail_package"
description = "Message-sending application"
version.workspace = true
rust-version.workspace = true
edition.workspace = true
repository.workspace = true
homepage.workspace = true
publish.workspace = true

[package.metadata.psibase]
package-name = "Chainmail"
services = ["chainmail"]

[profile.release]
codegen-units = 1
Expand All @@ -20,14 +31,9 @@ debug = false
strip = true
lto = true

[package.metadata.psibase]
package-name = "Chainmail"
description = "Basic email app"
services = ["chainmail"]

[lib]
crate-type = ["rlib"]

[dependencies]
chainmail = { path = "service" }
plugin = { path = "plugin" }
chainmail = { path = "service", version = "0.12.0" }
plugin = { path = "plugin", version = "0.12.0" }
2 changes: 1 addition & 1 deletion services/user/Chainmail/plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ world = "impl"
"transact:plugin" = { path = "../../../system/Transact/plugin/wit/world.wit" }

[dev-dependencies]
chainmail_package = { path = ".." }
chainmail_package = { path = "..", version = "0.12.0" }
14 changes: 13 additions & 1 deletion services/user/Chainmail/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ publish = false
[package.metadata.psibase]
server = "chainmail"
plugin = "plugin"
data = [{ src = "../ui/dist/", dst = "/" }]
postinstall = [
{ sender = "chainmail", service = "chainmail", method = "init", rawData = "0000" },
]

[package.metadata.psibase.dependencies]
Accounts = "0.12.0"
CommonApi = "0.12.0"
SetCode = "0.12.0"
HttpServer = "0.12.0"
Supervisor = "0.12.0"
Events = "0.12.0"

[dependencies]
psibase = { path = "../../../../rust/psibase/" }
async-graphql = "7.0.7"
serde = { version = "1.0.209", features = ["derive"] }

[dev-dependencies]
chainmail_package = { path = ".." }
chainmail_package = { path = "..", version = "0.12.0" }
31 changes: 26 additions & 5 deletions services/user/Chainmail/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,38 @@ fn serve_rest_api(request: &HttpRequest) -> Option<HttpReply> {

#[psibase::service]
mod service {
use psibase::services::accounts::Wrapper as AccountsSvc;
use psibase::{
anyhow, check, get_sender, get_service, serve_content, serve_simple_ui, store_content,
AccountNumber, HexBytes, HttpReply, HttpRequest, Table, WebContentRow,
};
use psibase::*;
use serde::{Deserialize, Serialize};
use services::accounts::Wrapper as AccountsSvc;
use services::events::Wrapper as EventsSvc;

use crate::serve_rest_api;

#[table(record = "WebContentRow")]
struct WebContentTable;

#[table(name = "InitTable", index = 1)]
#[derive(Serialize, Deserialize, ToSchema, Fracpack)]
struct InitRow {}
impl InitRow {
#[primary_key]
fn pk(&self) {}
}

#[action]
fn init() {
let table = InitTable::new();
check(
table.get_index_pk().get(&()).is_none(),
"Service already initialized",
);
table.put(&InitRow {}).unwrap();

EventsSvc::call().setSchema(create_schema::<Wrapper>());
EventsSvc::call().addIndex(DbId::HistoryEvent, SERVICE, MethodNumber::from("sent"), 0);
EventsSvc::call().addIndex(DbId::HistoryEvent, SERVICE, MethodNumber::from("sent"), 1);
}

#[action]
fn send(receiver: AccountNumber, subject: String, body: String) {
check(
Expand Down
Loading