-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathBuildMenu.tsx
100 lines (89 loc) · 3.93 KB
/
BuildMenu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, { useCallback } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import * as actions from './actions';
import * as selectors from './selectors';
import ButtonMenuItem from './ButtonMenuItem';
import MenuGroup from './MenuGroup';
interface BuildMenuProps {
close: () => void;
}
const useDispatchAndClose = (action: () => void, close: () => void) => {
const dispatch = useDispatch();
return useCallback(
() => {
dispatch(action());
close();
},
[action, close, dispatch]
);
}
const BuildMenu: React.SFC<BuildMenuProps> = props => {
const isHirAvailable = useSelector(selectors.isHirAvailable);
const isWasmAvailable = useSelector(selectors.isWasmAvailable);
const isWasmPackAvailable = useSelector(selectors.isWasmPackAvailable);
const compile = useDispatchAndClose(actions.performCompile, props.close);
const compileToAssembly = useDispatchAndClose(actions.performCompileToAssembly, props.close);
const compileToLLVM = useDispatchAndClose(actions.performCompileToLLVM, props.close);
const compileToMir = useDispatchAndClose(actions.performCompileToMir, props.close);
const compileToHir = useDispatchAndClose(actions.performCompileToNightlyHir, props.close);
const compileToWasm = useDispatchAndClose(actions.performCompileToNightlyWasm, props.close);
const compileToWasmPack = useDispatchAndClose(actions.performCompileToNightlyWasmPack, props.close);
const execute = useDispatchAndClose(actions.performExecute, props.close);
const test = useDispatchAndClose(actions.performTest, props.close);
return (
<MenuGroup title="What do you want to do?">
<ButtonMenuItem name="Run" onClick={execute}>
Build and run the code, showing the output.
Equivalent to <code className="build-menu__code">cargo run</code>.
</ButtonMenuItem>
<ButtonMenuItem name="Build" onClick={compile}>
Build the code without running it.
Equivalent to <code className="build-menu__code">cargo build</code>.
</ButtonMenuItem>
<ButtonMenuItem name="Test" onClick={test}>
Build the code and run all the tests.
Equivalent to <code className="build-menu__code">cargo test</code>.
</ButtonMenuItem>
<ButtonMenuItem name="ASM" onClick={compileToAssembly}>
Build and show the resulting assembly code.
</ButtonMenuItem>
<ButtonMenuItem name="LLVM IR" onClick={compileToLLVM}>
Build and show the resulting LLVM IR, LLVM’s intermediate representation.
</ButtonMenuItem>
<ButtonMenuItem name="MIR" onClick={compileToMir}>
Build and show the resulting MIR, Rust’s control-flow-based intermediate representation.
</ButtonMenuItem>
<ButtonMenuItem name="HIR" onClick={compileToHir}>
Build and show the resulting HIR, Rust’s syntax-based intermediate representation.
{!isHirAvailable && <HirAside />}
</ButtonMenuItem>
<ButtonMenuItem name="WASM" onClick={compileToWasm}>
Build a WebAssembly module for web browsers, in the .WAT textual representation.
{!isWasmAvailable && <WasmAside />}
</ButtonMenuItem>
<ButtonMenuItem name="WASM PACK" onClick={compileToWasmPack}>
Build a WebAssembly frontend for web browsers. Rendering in Iframe
{!isWasmPackAvailable && <WasmPackAside />}
</ButtonMenuItem>
</MenuGroup>
);
};
const HirAside: React.SFC = () => (
<p className="build-menu__aside">
Note: HIR currently requires using the Nightly channel, selecting this
option will switch to Nightly.
</p>
);
const WasmAside: React.SFC = () => (
<p className="build-menu__aside">
Note: WASM currently requires using the Nightly channel, selecting this
option will switch to Nightly.
</p>
);
const WasmPackAside: React.SFC = () => (
<p className="build-menu__aside">
Note: WASM PACK currently requires using the Nightly channel, selecting this
option will switch to Nightly.
</p>
);
export default BuildMenu;