Skip to content

Commit 5f7761c

Browse files
committed
Add support for dynamic target triple selection in compile and run functionality
1 parent a05200f commit 5f7761c

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

page/src/App.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Component } from "solid-js";
1+
import { createSignal, type Component } from "solid-js";
22
import { SetupMyTerminal } from "./xterm";
33
import type { WASIFarmRef } from "@oligami/browser_wasi_shim-threads";
44
import type { Ctx } from "./ctx";
@@ -22,6 +22,8 @@ const App = (props: {
2222
};
2323
let load_additional_sysroot: (string) => void;
2424

25+
const [triple, setTriple] = createSignal("wasm32-wasip1");
26+
2527
return (
2628
<>
2729
<MonacoEditor
@@ -35,14 +37,15 @@ const App = (props: {
3537
<SetupMyTerminal ctx={props.ctx} callback={props.callback} />
3638
<div class="flex">
3739
<div class="p-4 text-white">
38-
<RunButton />
40+
<RunButton triple={triple()} />
3941
</div>
4042
<div class="p-4 text-white" style={{ width: "60vw" }}>
4143
<Select
4244
options={triples}
4345
class="text-4xl text-green-700"
4446
onChange={(value) => {
4547
console.log(value);
48+
setTriple(value);
4649
if (load_additional_sysroot === undefined) {
4750
load_additional_sysroot = new SharedObjectRef(
4851
props.ctx.load_additional_sysroot_id,

page/src/btn.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { compile_and_run, download } from "./compile_and_run";
22

3-
export const RunButton = () => {
3+
export const RunButton = (props: {
4+
triple: string;
5+
}) => {
46
return (
57
<button
68
type="button"
79
onClick={() => {
810
console.log("run button clicked");
9-
compile_and_run();
11+
compile_and_run(props.triple);
1012
}}
1113
class="text-2xl text-green-700"
1214
>

page/src/compile_and_run.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export const compile_and_run_setup = (_ctx: Ctx) => {
3535

3636
let can_setup = false;
3737

38-
export const compile_and_run = async () => {
38+
export const compile_and_run = async (
39+
triple: string,
40+
) => {
3941
if (!can_setup) {
4042
if (await waiter.is_all_done()) {
4143
terminal = new SharedObjectRef(ctx.terminal_id).proxy<(string) => void>();
@@ -58,11 +60,33 @@ export const compile_and_run = async () => {
5860
"--sysroot",
5961
"/sysroot",
6062
"--target",
61-
"wasm32-wasip1",
63+
triple,
6264
"--out-dir",
6365
"/tmp",
6466
"-Ccodegen-units=1",
6567
];
68+
if (triple === "wasm32-wasip1") {
69+
exec.push("-Clinker-flavor=wasm-ld");
70+
exec.push("-Clinker=wasm-ld");
71+
} else {
72+
exec.push("-Zunstable-options");
73+
exec.push("-Clinker-flavor=gnu");
74+
exec.push("-Clinker=lld");
75+
}
76+
// const exec = [
77+
// "rustc",
78+
// "/main.rs",
79+
// "--sysroot",
80+
// "/sysroot",
81+
// "--target",
82+
// "x86_64-unknown-linux-musl",
83+
// "--out-dir",
84+
// "/linux",
85+
// "-Zunstable-options",
86+
// "-Clinker-flavor=gnu",
87+
// "-Clinker=lld",
88+
// "-Ccodegen-units=1",
89+
// ];
6690
await terminal(`${exec.join(" ")}\r\n`);
6791
await cmd_parser(...exec);
6892
while (!(await waiter.is_cmd_run_end())) {

page/src/rustc.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ globalThis.addEventListener("message", async (event) => {
6666
wasi.get_share_memory().grow(200);
6767

6868
rustc_shared = new SharedObject((...args) => {
69-
wasi.args = ["rustc", ...args];
70-
wasi.block_start_on_thread();
71-
console.log("wasi.start done");
69+
try {
70+
wasi.args = ["rustc", ...args];
71+
console.log("wasi.start");
72+
wasi.block_start_on_thread();
73+
console.log("wasi.start done");
74+
} catch (e) {
75+
terminal(e.toString());
76+
}
7277
}, ctx.rustc_id);
7378

7479
waiter.rustc();

0 commit comments

Comments
 (0)