Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into use-sites-for-storesys
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Mart committed Sep 27, 2024
2 parents f33fc6b + 13fb8f4 commit 26f32b7
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 42 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,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 @@ -417,6 +418,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 @@ -738,7 +745,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 @@ -748,7 +755,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 @@ -777,7 +784,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 @@ -787,6 +794,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
39 changes: 39 additions & 0 deletions libraries/psibase/sdk/pack_service.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,42 @@ 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 ${ARG_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PACKAGE_OUTPUT} ${ARG_OUTPUT}
DEPENDS ${PACKAGE_OUTPUT}
DEPENDS ${TARGET_NAME}_ext
VERBATIM
)
add_custom_target(${TARGET_NAME} ALL DEPENDS ${ARG_OUTPUT} cargo-psibase)
endfunction()
2 changes: 1 addition & 1 deletion libraries/psio/include/psio/check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace psio
template <typename T>
[[noreturn]] void abort_error(const T& msg)
{
#ifdef __cpp_exceptions
#ifndef COMPILING_WASM
throw std::runtime_error((std::string)error_to_str(msg));
#else
psibase::abortMessage(error_to_str(msg));
Expand Down
10 changes: 5 additions & 5 deletions libraries/psio/include/psio/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ namespace psio
(void)unpack_numeric<false>(&offset, this->data, pos, 4);
if (offset == 1)
{
#ifdef __cpp_exceptions
#ifndef COMPILING_WASM
throw std::bad_optional_access{};
#else
abort_error("bad optional access");
Expand Down Expand Up @@ -340,7 +340,7 @@ namespace psio
}
else
{
#ifdef __cpp_exceptions
#ifndef COMPILING_WASM
throw std::bad_variant_access{};
#else
abort_error("bad variant access");
Expand All @@ -358,7 +358,7 @@ namespace psio
}
else
{
#ifdef __cpp_exceptions
#ifndef COMPILING_WASM
throw std::bad_variant_access{};
#else
abort_error("bad variant access");
Expand Down Expand Up @@ -556,7 +556,7 @@ namespace psio
}
else
{
#ifdef __cpp_exceptions
#ifndef COMPILING_WASM
throw std::out_of_range("view<vector> our of range");
#else
abort_error("view<vector> our of range");
Expand Down Expand Up @@ -625,7 +625,7 @@ namespace psio
}
else
{
#ifdef __cpp_exceptions
#ifndef COMPILING_WASM
throw std::out_of_range("view<string> out of range");
#else
abort_error("view<string> out of range");
Expand Down
11 changes: 7 additions & 4 deletions programs/psinode/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,9 @@ void to_config(const PsinodeConfig& config, ConfigFile& file)
if (!config.tls.trustfiles.empty())
{
file.set(
"", "tls-trustfile", config.tls.trustfiles, [](std::string_view text)
{ return std::string(text); }, "A file containing trusted certificate authorities");
"", "tls-trustfile", config.tls.trustfiles,
[](std::string_view text) { return std::string(text); },
"A file containing trusted certificate authorities");
}
#endif
if (!config.services.empty())
Expand All @@ -1451,8 +1452,9 @@ void to_config(const PsinodeConfig& config, ConfigFile& file)
services.push_back(to_string(service));
}
file.set(
"", "service", services, [](std::string_view text)
{ return service_from_string(text).host; }, "Native service root directory");
"", "service", services,
[](std::string_view text) { return service_from_string(text).host; },
"Native service root directory");
}
if (!std::holds_alternative<http::admin_none>(config.admin))
{
Expand Down Expand Up @@ -1480,6 +1482,7 @@ void to_config(const PsinodeConfig& config, ConfigFile& file)
// private keys.
file.keep("", "key");
file.keep("", "leeway");
file.keep("", "database-cache-size");
//
to_config(config.loggers, file);
}
Expand Down
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
3 changes: 1 addition & 2 deletions services/user/Branding/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export const App = () => {

const init = async () => {
await supervisor.onLoaded();
supervisor.preLoadPlugins([{ service: "branding" }]);
setTimeout(getNetworkName, 1500);
await getNetworkName();
};

useEffect(() => {
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" }
Loading

0 comments on commit 26f32b7

Please sign in to comment.