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: Zinnia.versions.{zinnia,v8} #261

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 9 additions & 10 deletions daemon/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,24 @@ async fn run(config: CliArgs) -> Result<()> {
)?;
let module_root = get_module_root(&main_module)?;

let config = BootstrapOptions {
agent_version: format!("zinniad/{} {module_name}", env!("CARGO_PKG_VERSION")),
wallet_address: config.wallet_address,
reporter: Rc::new(StationReporter::new(
let mut runtime_config = BootstrapOptions::new(
format!("zinniad/{} {module_name}", env!("CARGO_PKG_VERSION")),
Rc::new(StationReporter::new(
state_file,
Duration::from_millis(200),
module_name.into(),
)),
lassie_daemon,
module_root: Some(module_root),
no_color: true,
is_tty: false,
rng_seed: None,
};
Some(module_root),
);
runtime_config.wallet_address = config.wallet_address;
runtime_config.no_color = true;
runtime_config.is_tty = false;

// TODO: handle module exit and restart it
// https://github.com/filecoin-station/zinnia/issues/146
log::info!("Starting module {main_module}");
run_js_module(&main_module, &config).await?;
run_js_module(&main_module, &runtime_config).await?;

Ok(())
}
Expand Down
11 changes: 11 additions & 0 deletions docs/building-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import * as code from "../../other/code.js";
- [libp2p](#libp2p)
- [Integration with Filecoin Station](#integration-with-filecoin-station)
- [IPFS retrieval client](#ipfs-retrieval-client)
- [Miscelaneous APIs]()

### Standard JavaScript APIs

Expand Down Expand Up @@ -361,6 +362,16 @@ possible error status codes in
The format of CAR data returned by the retrieval client is described in
[Lassie's Returned CAR Specification](https://github.com/filecoin-project/lassie/blob/main/docs/CAR.md).

### Miscelaneous APIs

#### `Zinnia.versions.zinna`

The version of Zinnia runtime, e.g. `"0.11.0"`.

#### `Zinnia.versions.v8`

The version of V8 engine, e.g. `"11.5.150.2"`.

## Testing Guide

Zinnia provides lightweight tooling for writing and running automated tests.
Expand Down
17 changes: 15 additions & 2 deletions runtime/js/90_zinnia_apis.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
const primordials = globalThis.__bootstrap.primordials;
const { ObjectDefineProperties, ObjectCreate } = primordials;
const { ObjectDefineProperties, ObjectCreate, ObjectFreeze } = primordials;

const { ops } = globalThis.Deno.core;

import { readOnly } from "ext:zinnia_runtime/06_util.js";
import * as libp2p from "ext:zinnia_libp2p/01_peer.js";

const versions = {
zinnia: "",
v8: "",
};

function setVersions(zinniaVersion, v8Version) {
versions.zinnia = zinniaVersion;
versions.v8 = v8Version;

ObjectFreeze(versions);
}

const zinniaNs = ObjectCreate(null);
ObjectDefineProperties(zinniaNs, libp2p.defaultPeerProps);

Expand All @@ -18,6 +30,7 @@ ObjectDefineProperties(activityApi, {
ObjectDefineProperties(zinniaNs, {
activity: readOnly(activityApi),
jobCompleted: readOnly(reportJobCompleted),
versions: readOnly(versions),
});

function reportInfoActivity(msg) {
Expand All @@ -39,4 +52,4 @@ function log(msg, level) {
ops.op_zinnia_log(msg, level);
}

export { zinniaNs, log };
export { zinniaNs, log, setVersions };
2 changes: 2 additions & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
windowOrWorkerGlobalScope,
} from "ext:zinnia_runtime/98_global_scope.js";
import { setLassieUrl } from "ext:zinnia_runtime/fetch.js";
import { setVersions } from "ext:zinnia_runtime/90_zinnia_apis.js";

function formatException(error) {
if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, error)) {
Expand Down Expand Up @@ -69,6 +70,7 @@ function runtimeStart(runtimeOptions) {
Error.prepareStackTrace = core.prepareStackTrace;

setLassieUrl(runtimeOptions.lassieUrl);
setVersions(runtimeOptions.zinniaVersion, runtimeOptions.v8Version);
}

let hasBootstrapped = false;
Expand Down
8 changes: 8 additions & 0 deletions runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub struct BootstrapOptions {
/// Lassie daemon to use as the IPFS retrieval client. We must use Arc here to allow sharing of
/// the singleton Lassie instance between multiple threads spawned by Rust's test runner.
pub lassie_daemon: Arc<lassie::Daemon>,

zinnia_version: &'static str,
v8_version: &'static str,
}

impl BootstrapOptions {
Expand All @@ -59,6 +62,9 @@ impl BootstrapOptions {
wallet_address: String::from("t1abjxfbp274xpdqcpuaykwkfb43omjotacm2p3za"),
reporter,
lassie_daemon,
// FIXME: add ".1-dev" unless we are building a release
zinnia_version: env!("CARGO_PKG_VERSION"),
bajtos marked this conversation as resolved.
Show resolved Hide resolved
v8_version: deno_core::v8_version(),
}
}

Expand All @@ -68,6 +74,8 @@ impl BootstrapOptions {
"isTty": self.is_tty,
"walletAddress": self.wallet_address,
"lassieUrl": format!("http://127.0.0.1:{}/", self.lassie_daemon.port()),
"zinniaVersion": self.zinnia_version,
"v8Version": self.v8_version,
});
serde_json::to_string_pretty(&payload).unwrap()
}
Expand Down
19 changes: 19 additions & 0 deletions runtime/tests/js/versions_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test } from "zinnia:test";
import { assertMatch, assertEquals, assertArrayIncludes } from "zinnia:assert";

console.log(Zinnia.versions);

test("Zinnia.versions", () => {
assertArrayIncludes(Object.keys(Zinnia), ["versions"], "Zinnia properties");
assertEquals(typeof Zinnia.versions, "object", "typeof Zinnia.versions");
});

test("Zinnia.versions.zinnia", () => {
assertArrayIncludes(Object.keys(Zinnia.versions), ["zinnia"], "Zinnia.versions properties");
assertMatch(Zinnia.versions?.zinnia, /^\d+\.\d+\.\d+$/);
bajtos marked this conversation as resolved.
Show resolved Hide resolved
});

test("Zinnia.versions.v8", () => {
assertArrayIncludes(Object.keys(Zinnia.versions), ["v8"], "Zinnia.versions properties");
assertMatch(Zinnia.versions.v8, /^\d+\.\d+\.\d+\.\d+$/);
});
1 change: 1 addition & 0 deletions runtime/tests/runtime_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ macro_rules! test_runner_tests(
);

js_tests!(globals_tests);
js_tests!(versions_tests);
js_tests!(timers_tests);
js_tests!(webapis_tests);
js_tests!(webcrypto_tests);
Expand Down