From a25e1e73f48cf19f2f9b1f4dae0042ecdb3feae6 Mon Sep 17 00:00:00 2001 From: Pawel Rutka Date: Wed, 18 Feb 2026 13:07:51 +0100 Subject: [PATCH] Use Kyron examples from module itself --- images/autosd_x86_64/BUILD.bazel | 6 +-- images/qnx_x86_64/build/init.build | 2 + score_starter | 2 +- showcases/BUILD | 4 +- showcases/cli/README.md | 30 ++++++++++- showcases/cli/main.rs | 12 ++++- showcases/kyron/BUILD | 22 -------- showcases/kyron/kyron.score.json | 13 ----- showcases/kyron/main.rs | 50 ------------------- showcases/orchestration_persistency/main.rs | 15 +++++- .../orch_per.score.json | 2 +- showcases/standalone/BUILD | 10 ++++ showcases/standalone/kyron.score.json | 35 +++++++++++++ 13 files changed, 106 insertions(+), 97 deletions(-) delete mode 100644 showcases/kyron/BUILD delete mode 100644 showcases/kyron/kyron.score.json delete mode 100644 showcases/kyron/main.rs create mode 100644 showcases/standalone/kyron.score.json diff --git a/images/autosd_x86_64/BUILD.bazel b/images/autosd_x86_64/BUILD.bazel index 6c71e0e90e..9e8806ba98 100644 --- a/images/autosd_x86_64/BUILD.bazel +++ b/images/autosd_x86_64/BUILD.bazel @@ -25,13 +25,11 @@ rpm_package( version = "0.6.0", binaries = [ "//showcases/cli:cli", - "//showcases/kyron:kyron_example", - "//showcases/orchestration_persistency:orch_per_example", + "//showcases/orchestration_persistency:orch_per_example", ], config_dir = "/etc/score", data = [ - "//showcases/kyron:kyron.score.json", - "//showcases/orchestration_persistency:orch_per.score.json" + "//showcases/orchestration_persistency:orch_per.score.json" ], data_dir = "/usr/share/score/examples", ) diff --git a/images/qnx_x86_64/build/init.build b/images/qnx_x86_64/build/init.build index bbec098e03..fdc1d27339 100644 --- a/images/qnx_x86_64/build/init.build +++ b/images/qnx_x86_64/build/init.build @@ -95,5 +95,7 @@ libslog2.so.1 # System logging library (slog2_* functions) devb-eide # Block device driver for IDE/SATA hard drives and SSDs # Required for mounting QNX6 file systems from disk partitions +# Orchestrator example needed +[type=link] /data=/tmp_ram [+include] ${MAIN_BUILD_FILE_DIR}/system.build # Include additional system build configurations diff --git a/score_starter b/score_starter index 716b7720ad..545b2187ae 100755 --- a/score_starter +++ b/score_starter @@ -14,7 +14,7 @@ mEntries = [ ("Run Elektrobit Corbos aarch64 QEMU", "bazel --output_base=build/eb-aarch64 build --config eb-aarch64 //images/ebclfsa_aarch64/scrample_integration:run", "eb-aarch64"), ("Run Autosd x86_64 QEMU", - "bazel --output_base=build/autosd-x86_64 build --config autosd-x86_64 //images/autosd_x86_64:image", "autosd-x86_64"), + "bazel --output_base=build/autosd-x86_64 run --config autosd-x86_64 //images/autosd_x86_64:run", "autosd-x86_64"), ("Exit", "exit 0", "exit"), ] diff --git a/showcases/BUILD b/showcases/BUILD index a110fe8d22..01395893a6 100644 --- a/showcases/BUILD +++ b/showcases/BUILD @@ -16,8 +16,8 @@ score_pkg_bundle( name = "showcases_all", bins = ["//showcases/cli" ], other_package_files = [ - "//showcases/standalone:comm_pkg_files", - "//showcases/kyron:kyron_pkg_files", + "//showcases/standalone:comm_pkg_files", + "//showcases/standalone:kyron_pkg_files", "//showcases/orchestration_persistency:orch_per_pkg_files", "//showcases/simple_lifecycle:simple_lifecycle_pkg_files", ], diff --git a/showcases/cli/README.md b/showcases/cli/README.md index 99c1c69a0e..65d5d4e595 100644 --- a/showcases/cli/README.md +++ b/showcases/cli/README.md @@ -22,7 +22,7 @@ To make this work each example shall deploy configuration file `name.score.json` "env": { // env to be used when running }, - "delay": "number" // Optional delay between two consecutive apps + "delay": "number" // Optional delay between two consecutive apps }, { // ... @@ -30,9 +30,37 @@ To make this work each example shall deploy configuration file `name.score.json` ] } +``` Each example can run multiple executables, providing additional `apps` configs. This will be started one after another but not blocking each-other. +Alternatively, the configuration file can contain a top-level array of configs, allowing multiple examples to be defined in a single file: + +```json +[ + { + "name": "First example", + "description": "Description of first example", + "apps": [ + { + "path": "exec_path", + "args": [], + "env": {} + } + ] + }, + { + "name": "Second example", + "description": "Description of second example", + "apps": [ + { + "path": "exec_path", + "args": [], + "env": {} + } + ] + } +] ``` You can customize where to look for examples using env `SCORE_CLI_INIT_DIR`. \ No newline at end of file diff --git a/showcases/cli/main.rs b/showcases/cli/main.rs index cb95f4302d..d0ba283a54 100644 --- a/showcases/cli/main.rs +++ b/showcases/cli/main.rs @@ -111,9 +111,17 @@ fn visit_dir(dir: &Path, configs: &mut Vec) -> Result<()> { if is_score_file(&path) { let content = fs::read_to_string(&path) .with_context(|| format!("Failed reading {:?}", path))?; - let config: ScoreConfig = serde_json::from_str(&content) + let value: serde_json::Value = serde_json::from_str(&content) .with_context(|| format!("Invalid JSON in {:?}", path))?; - configs.push(config); + if value.is_array() { + let found: Vec = serde_json::from_value(value) + .with_context(|| format!("Invalid JSON array in {:?}", path))?; + configs.extend(found); + } else { + let config: ScoreConfig = serde_json::from_value(value) + .with_context(|| format!("Invalid JSON in {:?}", path))?; + configs.push(config); + } } } Ok(()) diff --git a/showcases/kyron/BUILD b/showcases/kyron/BUILD deleted file mode 100644 index a39af18d5b..0000000000 --- a/showcases/kyron/BUILD +++ /dev/null @@ -1,22 +0,0 @@ -load("@rules_rust//rust:defs.bzl", "rust_binary") -load("//bazel_common:bundlers.bzl", "score_pkg_bundle") - -exports_files(["kyron.score.json"]) - -rust_binary( - name = "kyron_example", - srcs = ["main.rs"], - deps = [ - "@score_kyron//src/kyron:libkyron", - "@score_kyron//src/kyron-foundation:libkyron_foundation", - "@score_crates//:tracing_subscriber", - ], - visibility = ["//visibility:public"], -) - - -score_pkg_bundle( - name = "kyron", - bins = [":kyron_example"], - config_data = ["//showcases/kyron:kyron.score.json"], -) diff --git a/showcases/kyron/kyron.score.json b/showcases/kyron/kyron.score.json deleted file mode 100644 index 910ce37f77..0000000000 --- a/showcases/kyron/kyron.score.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "Kyron example", - "description": "Example for channel communication using safe async runtime - Kyron", - "apps":[ - { - "path": "/showcases/bin/kyron_example", - "args": [ - ], - "env": { - } - } - ] -} diff --git a/showcases/kyron/main.rs b/showcases/kyron/main.rs deleted file mode 100644 index cf644c73ae..0000000000 --- a/showcases/kyron/main.rs +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright (c) 2025 Contributors to the Eclipse Foundation -// -// See the NOTICE file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// This program and the accompanying materials are made available under the -// terms of the Apache License Version 2.0 which is available at -// -// -// SPDX-License-Identifier: Apache-2.0 -// - -use kyron::channels::spsc::*; -use kyron::spawn; -use kyron_foundation::prelude::*; - -/// Example entry point demonstrating the usage of the kyron async runtime -/// -/// This example shows how to set up a Kyron async runtime with default engine parameters. -/// It spawns a sender and receiver task using Kyron's channel and spawn utilities. -/// Useful for learning how to structure Kyron async applications and macro usage. -/// For more visit https://github.com/eclipse-score/orchestrator -#[kyron::main] -async fn main() { - tracing_subscriber::fmt() - .with_target(false) - .with_max_level(Level::INFO) - .init(); - - let (sender, mut receiver) = create_channel_default::(); - - let r = spawn(async move { - while let Some(value) = receiver.recv().await { - info!("Received {}", value); - } - }); - - let s = spawn(async move { - info!("Hello from Kyron sender!"); - - for i in 0..5_u32 { - info!("Sending {}", i); - sender.send(&i).unwrap(); - } - }); - - s.await.unwrap(); - r.await.unwrap(); -} diff --git a/showcases/orchestration_persistency/main.rs b/showcases/orchestration_persistency/main.rs index 1d61254d6f..f9bf644600 100644 --- a/showcases/orchestration_persistency/main.rs +++ b/showcases/orchestration_persistency/main.rs @@ -62,7 +62,7 @@ async fn on_shutdown() -> InvokeResult { // Configure backend with directory path (workaround: KvsBuilder::dir() not available in Rust) // change back to dir, if https://github.com/eclipse-score/persistency/issues/222 is resolved. let backend = JsonBackendBuilder::new() - .working_dir(PathBuf::from("./")) + .working_dir(PathBuf::from("/tmp")) .build(); let builder = KvsBuilder::new(instance_id) @@ -75,6 +75,19 @@ async fn on_shutdown() -> InvokeResult { kvs.flush().unwrap(); + let instance_id = kvs.parameters().instance_id; + let snapshot_id = SnapshotId(0); + match kvs.parameters().backend.as_any().downcast_ref(){ + Some(backend ) => { + let backend = backend as &JsonBackend; + let filename = backend.kvs_file_path(instance_id, snapshot_id); + info!("KVS snapshot saved to file: {:?}", filename); + }, + None => { + + }, + }; + Ok(()) } diff --git a/showcases/orchestration_persistency/orch_per.score.json b/showcases/orchestration_persistency/orch_per.score.json index 70fdab837c..f3eb27c670 100644 --- a/showcases/orchestration_persistency/orch_per.score.json +++ b/showcases/orchestration_persistency/orch_per.score.json @@ -1,5 +1,5 @@ { - "name": "Orchestration persistency - Kyron example", + "name": "Orchestration persistency example", "description": "Example for running orchestration graph with Kyron runtime and saving the state to disk", "apps":[ { diff --git a/showcases/standalone/BUILD b/showcases/standalone/BUILD index ad5cc22a48..e19ef0efa0 100644 --- a/showcases/standalone/BUILD +++ b/showcases/standalone/BUILD @@ -12,3 +12,13 @@ score_pkg_bundle( "//showcases/standalone:com.score.json", ], ) + +score_pkg_bundle( + name = "kyron", + package_dir = "standalone", + bins = ["@score_kyron//src/kyron:select", "@score_kyron//src/kyron:safety_task", "@score_kyron//src/kyron:main_macro"], # TODO: kyron shall have public examples in examples folder + + config_data = [ + "//showcases/standalone:kyron.score.json", + ], +) diff --git a/showcases/standalone/kyron.score.json b/showcases/standalone/kyron.score.json new file mode 100644 index 0000000000..631f55fcdc --- /dev/null +++ b/showcases/standalone/kyron.score.json @@ -0,0 +1,35 @@ +[ + { + "name": "Kyron select example", + "description": "Example for select! macro using safe async runtime", + "apps": [ + { + "path": "/showcases/bin/select", + "args": [], + "env": {} + } + ] + }, + { + "name": "Kyron safety task example", + "description": "Example assuring that errors in safety task will always get reaction runtime even if worker can be blocked", + "apps": [ + { + "path": "/showcases/bin/safety_task", + "args": [], + "env": {} + } + ] + }, + { + "name": "Kyron basic example", + "description": "Example running async code via main! macro", + "apps": [ + { + "path": "/showcases/bin/main_macro", + "args": [], + "env": {} + } + ] + } +]