virtual-machine 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ import {
2
+ NetworkStatus,
3
+ WasmVm,
4
+ initSync,
5
+ riscv_vm_default
6
+ } from "./chunk-GZ343GYI.mjs";
7
+ export {
8
+ NetworkStatus,
9
+ WasmVm,
10
+ riscv_vm_default as default,
11
+ initSync
12
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ NetworkStatus,
3
+ WasmVm,
4
+ initSync,
5
+ riscv_vm_default
6
+ } from "./chunk-LJUNPJTY.mjs";
7
+ export {
8
+ NetworkStatus,
9
+ WasmVm,
10
+ riscv_vm_default as default,
11
+ initSync
12
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ NetworkStatus,
3
+ WasmVm,
4
+ initSync,
5
+ riscv_vm_default
6
+ } from "./chunk-Q7TFYQ5G.mjs";
7
+ export {
8
+ NetworkStatus,
9
+ WasmVm,
10
+ riscv_vm_default as default,
11
+ initSync
12
+ };
package/build.sh CHANGED
@@ -5,14 +5,21 @@ is_mac() {
5
5
  [[ "$OSTYPE" == "darwin"* ]]
6
6
  }
7
7
 
8
-
9
8
  PACKAGEJSON=./pkg/package.json
10
9
  IMPORTFILE=./pkg/riscv_vm.js
11
10
 
12
11
  echo "Building the rust library"
13
12
  RUSTFLAGS=--cfg=web_sys_unstable_apis npx wasm-pack build --target web
14
13
 
14
+ if is_mac; then
15
+ sed -i '' 's/"module": "ridb_core.js",/"main": "ridb_core.js",/' $PACKAGEJSON
16
+ sed -i '' "/if (typeof module_or_path === 'undefined') {/,/}/d" $IMPORTFILE
17
+ else
18
+ sed -i 's/"module": "ridb_core.js",/"main": "ridb_core.js",/' $PACKAGEJSON
19
+ sed -i "/if (typeof module_or_path === 'undefined') {/,/}/d" $IMPORTFILE
20
+ fi
21
+
15
22
  npx tsup --config tsup/tsup.cli.ts
16
23
  npx tsup --config tsup/tsup.core.cjs.ts
17
24
  npx tsup --config tsup/tsup.core.esm.ts
18
- npx tsup --config tsup/tsup.core.cjs.ts --dts-only
25
+ npx tsup --config tsup/tsup.core.cjs.ts --dts-only
package/cli.ts CHANGED
@@ -38,9 +38,26 @@ async function createVm(
38
38
  certHash?: string;
39
39
  },
40
40
  ) {
41
- const resolvedKernel = path.resolve(kernelPath);
42
- const kernelBuf = fs.readFileSync(resolvedKernel);
43
- const kernelBytes = new Uint8Array(kernelBuf);
41
+ let kernelBytes: Uint8Array;
42
+
43
+ if (kernelPath.startsWith('http://') || kernelPath.startsWith('https://')) {
44
+ console.error(`[CLI] Downloading kernel from ${kernelPath}...`);
45
+ const response = await fetch(kernelPath);
46
+ if (!response.ok) {
47
+ throw new Error(
48
+ `Failed to fetch kernel from ${kernelPath}: ${response.statusText}`,
49
+ );
50
+ }
51
+ const arrayBuffer = await response.arrayBuffer();
52
+ kernelBytes = new Uint8Array(arrayBuffer);
53
+ } else {
54
+ const resolvedKernel = path.resolve(kernelPath);
55
+ if (!fs.existsSync(resolvedKernel)) {
56
+ throw new Error(`Kernel file not found at ${resolvedKernel}`);
57
+ }
58
+ const kernelBuf = fs.readFileSync(resolvedKernel);
59
+ kernelBytes = new Uint8Array(kernelBuf);
60
+ }
44
61
 
45
62
  const { WasmInternal } = await import('./');
46
63
  const wasm = await WasmInternal();
package/index.ts CHANGED
@@ -13,4 +13,4 @@ export async function WasmInternal() {
13
13
  }
14
14
 
15
15
 
16
- export type * from "./pkg/riscv_vm";
16
+ export { NetworkStatus, WasmVm } from "./pkg/riscv_vm";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtual-machine",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "bin": "build/cli.js",
6
6
  "publishConfig": {
package/src/main.rs CHANGED
@@ -13,9 +13,9 @@ use riscv_vm::console::Console;
13
13
  #[derive(Parser, Debug)]
14
14
  #[command(author, version, about, long_about = None)]
15
15
  struct Args {
16
- /// Path to binary to load
16
+ /// Path or URL to binary to load
17
17
  #[arg(short, long)]
18
- kernel: PathBuf,
18
+ kernel: String,
19
19
 
20
20
  /// Address to load kernel at (default 0x8000_0000)
21
21
  #[arg(long, default_value_t = 0x8000_0000)]
@@ -74,9 +74,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
74
74
  env_logger::init();
75
75
  let args = Args::parse();
76
76
 
77
- let mut file = File::open(&args.kernel)?;
78
- let mut buffer = Vec::new();
79
- file.read_to_end(&mut buffer)?;
77
+ let buffer = if args.kernel.starts_with("http://") || args.kernel.starts_with("https://") {
78
+ println!("Downloading kernel from {}...", args.kernel);
79
+ let response = reqwest::blocking::get(&args.kernel)?;
80
+ if !response.status().is_success() {
81
+ return Err(format!("Failed to download kernel: {}", response.status()).into());
82
+ }
83
+ response.bytes()?.to_vec()
84
+ } else {
85
+ let mut file = File::open(&args.kernel)?;
86
+ let mut buffer = Vec::new();
87
+ file.read_to_end(&mut buffer)?;
88
+ buffer
89
+ };
80
90
 
81
91
  let dram_size_bytes = args
82
92
  .mem_mib
package/tsup/index.ts CHANGED
@@ -73,7 +73,6 @@ export default function createConfig({
73
73
  "react-server-dom-webpack",
74
74
  "tsup",
75
75
  "react-server-dom-webpack/client.edge",
76
- "@trust0/ridb/worker",
77
76
  ...(external ?? [])
78
77
  ],
79
78
  }));