Skip to content

Commit a05200f

Browse files
committed
Add support for loading additional sysroots and integrate with UI
1 parent b173d4f commit a05200f

File tree

5 files changed

+54
-34
lines changed

5 files changed

+54
-34
lines changed

lib/src/sysroot.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,43 @@ const toMap = (arr: Array<[string, Inode]>) => {
4343
return map;
4444
};
4545

46+
let rustlib_dir: Directory | undefined;
47+
4648
export const load_default_sysroot = async (): Promise<PreopenDirectory> => {
4749
const sysroot_part = await load_sysroot_part('wasm32-wasip1');
50+
rustlib_dir = new Directory([
51+
["wasm32-wasip1", new Directory([
52+
["lib", sysroot_part]
53+
])],
54+
]);
4855
const sysroot = new PreopenDirectory(
4956
"/sysroot",
5057
toMap([
5158
["lib", new Directory([
52-
["rustlib", new Directory([
53-
["wasm32-wasip1", new Directory([
54-
["lib", sysroot_part]
55-
])],
56-
])]
59+
["rustlib", rustlib_dir],
5760
])]
5861
])
5962
);
63+
loaded_triples.add('wasm32-wasip1');
6064
return sysroot;
6165
};
6266

67+
const loaded_triples: Set<string> = new Set();
68+
69+
export const load_additional_sysroot = async (triple: string) => {
70+
if (loaded_triples.has(triple)) {
71+
return;
72+
}
73+
const sysroot_part = await load_sysroot_part(triple);
74+
if (!rustlib_dir) {
75+
throw new Error("Default sysroot not loaded");
76+
}
77+
rustlib_dir.contents.set(triple, new Directory([
78+
["lib", sysroot_part]
79+
]));
80+
loaded_triples.add(triple);
81+
}
82+
6383
export const get_default_sysroot_wasi_farm = async (): Promise<WASIFarm> => {
6484
const fds = [await load_default_sysroot()];
6585
const farm = new WASIFarm(

page/src/App.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { default_value, rust_file } from "./config";
77
import { DownloadButton, RunButton } from "./btn";
88
import { triples } from "./sysroot";
99
import { Select } from "@thisbeyond/solid-select";
10+
import { SharedObjectRef } from "@oligami/shared-object";
1011

1112
const App = (props: {
1213
ctx: Ctx;
@@ -19,6 +20,7 @@ const App = (props: {
1920
// Handle editor value change
2021
rust_file.data = new TextEncoder().encode(value);
2122
};
23+
let load_additional_sysroot: (string) => void;
2224

2325
return (
2426
<>
@@ -35,8 +37,20 @@ const App = (props: {
3537
<div class="p-4 text-white">
3638
<RunButton />
3739
</div>
38-
<div class="p-4 text-white">
39-
<Select options={triples} class="text-4xl text-green-700" />
40+
<div class="p-4 text-white" style={{ width: "60vw" }}>
41+
<Select
42+
options={triples}
43+
class="text-4xl text-green-700"
44+
onChange={(value) => {
45+
console.log(value);
46+
if (load_additional_sysroot === undefined) {
47+
load_additional_sysroot = new SharedObjectRef(
48+
props.ctx.load_additional_sysroot_id,
49+
).proxy<(string) => void>();
50+
}
51+
load_additional_sysroot(value);
52+
}}
53+
/>
4054
</div>
4155
<div class="p-4 text-white">
4256
<DownloadButton />

page/src/ctx.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type Ctx = {
88
exec_file_id: string;
99
download_id: string;
1010
download_by_url_id: string;
11+
load_additional_sysroot_id: string;
1112
};
1213

1314
const gen_id = () => Math.random().toString(36).substring(7);
@@ -23,5 +24,6 @@ export const gen_ctx = (): Ctx => {
2324
exec_file_id: gen_id(),
2425
download_id: gen_id(),
2526
download_by_url_id: gen_id(),
27+
load_additional_sysroot_id: gen_id(),
2628
};
2729
};

page/src/index.css

-25
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4-
5-
.custom {
6-
&.solid-select-container {
7-
color: #fa7f25;
8-
}
9-
.solid-select-control {
10-
border-color: #fca560;
11-
&:focus-within {
12-
outline-color: #fca560;
13-
}
14-
}
15-
.solid-select-placeholder {
16-
color: #fca560;
17-
}
18-
.solid-select-option {
19-
&:hover {
20-
background-color: #fa7f25;
21-
color: #fff;
22-
}
23-
&[data-focused="true"] {
24-
background-color: #fca560;
25-
color: #fff;
26-
}
27-
}
28-
}

page/src/worker.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { SharedObjectRef } from "@oligami/shared-object";
2-
import { get_default_sysroot_wasi_farm } from "../../lib/src/sysroot";
1+
import { SharedObject, SharedObjectRef } from "@oligami/shared-object";
2+
import { get_default_sysroot_wasi_farm, load_additional_sysroot } from "../../lib/src/sysroot";
33
import type { Ctx } from "./ctx";
44

55
let terminal: (string) => void;
66
let rustc_worker: Worker;
77
let ctx: Ctx;
88
import RustcWorker from "./rustc?worker";
9+
let shared: SharedObject;
910

1011
globalThis.addEventListener("message", async (event) => {
1112
if (event.data.ctx) {
@@ -24,6 +25,14 @@ globalThis.addEventListener("message", async (event) => {
2425
const wasi_ref = farm.get_ref();
2526

2627
rustc_worker.postMessage({ wasi_ref });
28+
29+
shared = new SharedObject((triple) => {
30+
(async () => {
31+
terminal(`loading sysroot ${triple}\r\n`);
32+
await load_additional_sysroot(triple);
33+
terminal(`loaded sysroot ${triple}\r\n`);
34+
})();
35+
}, ctx.load_additional_sysroot_id);
2736
} else if (event.data.wasi_ref) {
2837
const { wasi_ref } = event.data;
2938

0 commit comments

Comments
 (0)