File tree 5 files changed +54
-34
lines changed
5 files changed +54
-34
lines changed Original file line number Diff line number Diff line change @@ -43,23 +43,43 @@ const toMap = (arr: Array<[string, Inode]>) => {
43
43
return map ;
44
44
} ;
45
45
46
+ let rustlib_dir : Directory | undefined ;
47
+
46
48
export const load_default_sysroot = async ( ) : Promise < PreopenDirectory > => {
47
49
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
+ ] ) ;
48
55
const sysroot = new PreopenDirectory (
49
56
"/sysroot" ,
50
57
toMap ( [
51
58
[ "lib" , new Directory ( [
52
- [ "rustlib" , new Directory ( [
53
- [ "wasm32-wasip1" , new Directory ( [
54
- [ "lib" , sysroot_part ]
55
- ] ) ] ,
56
- ] ) ]
59
+ [ "rustlib" , rustlib_dir ] ,
57
60
] ) ]
58
61
] )
59
62
) ;
63
+ loaded_triples . add ( 'wasm32-wasip1' ) ;
60
64
return sysroot ;
61
65
} ;
62
66
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
+
63
83
export const get_default_sysroot_wasi_farm = async ( ) : Promise < WASIFarm > => {
64
84
const fds = [ await load_default_sysroot ( ) ] ;
65
85
const farm = new WASIFarm (
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { default_value, rust_file } from "./config";
7
7
import { DownloadButton , RunButton } from "./btn" ;
8
8
import { triples } from "./sysroot" ;
9
9
import { Select } from "@thisbeyond/solid-select" ;
10
+ import { SharedObjectRef } from "@oligami/shared-object" ;
10
11
11
12
const App = ( props : {
12
13
ctx : Ctx ;
@@ -19,6 +20,7 @@ const App = (props: {
19
20
// Handle editor value change
20
21
rust_file . data = new TextEncoder ( ) . encode ( value ) ;
21
22
} ;
23
+ let load_additional_sysroot : ( string ) => void ;
22
24
23
25
return (
24
26
< >
@@ -35,8 +37,20 @@ const App = (props: {
35
37
< div class = "p-4 text-white" >
36
38
< RunButton />
37
39
</ 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
+ />
40
54
</ div >
41
55
< div class = "p-4 text-white" >
42
56
< DownloadButton />
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export type Ctx = {
8
8
exec_file_id : string ;
9
9
download_id : string ;
10
10
download_by_url_id : string ;
11
+ load_additional_sysroot_id : string ;
11
12
} ;
12
13
13
14
const gen_id = ( ) => Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
@@ -23,5 +24,6 @@ export const gen_ctx = (): Ctx => {
23
24
exec_file_id : gen_id ( ) ,
24
25
download_id : gen_id ( ) ,
25
26
download_by_url_id : gen_id ( ) ,
27
+ load_additional_sysroot_id : gen_id ( ) ,
26
28
} ;
27
29
} ;
Original file line number Diff line number Diff line change 1
1
@tailwind base;
2
2
@tailwind components;
3
3
@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
- }
Original file line number Diff line number Diff line change 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" ;
3
3
import type { Ctx } from "./ctx" ;
4
4
5
5
let terminal : ( string ) => void ;
6
6
let rustc_worker : Worker ;
7
7
let ctx : Ctx ;
8
8
import RustcWorker from "./rustc?worker" ;
9
+ let shared : SharedObject ;
9
10
10
11
globalThis . addEventListener ( "message" , async ( event ) => {
11
12
if ( event . data . ctx ) {
@@ -24,6 +25,14 @@ globalThis.addEventListener("message", async (event) => {
24
25
const wasi_ref = farm . get_ref ( ) ;
25
26
26
27
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 ) ;
27
36
} else if ( event . data . wasi_ref ) {
28
37
const { wasi_ref } = event . data ;
29
38
You can’t perform that action at this time.
0 commit comments