@yowasp/clang 0.0.0 → 21.1.4-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.
- package/README.md +47 -5
- package/gen/bundle.js +8044 -0
- package/gen/llvm-resources.tar +0 -0
- package/gen/llvm.core.wasm +0 -0
- package/gen/llvm.core2.wasm +0 -0
- package/gen/llvm.core3.wasm +0 -0
- package/gen/llvm.core4.wasm +0 -0
- package/package.json +25 -2
- package/lib/api.js +0 -217
- package/package-in.json +0 -38
- package/prepare.py +0 -34
- package/test/test_api.js +0 -17
package/README.md
CHANGED
|
@@ -3,19 +3,61 @@ YoWASP Clang/LLD package
|
|
|
3
3
|
|
|
4
4
|
This package provides a complete [Clang/LLD][] toolchain built for [WebAssembly][] and targeting WebAssembly as well. See the [overview of the YoWASP project][yowasp] for details.
|
|
5
5
|
|
|
6
|
-
At the moment, this package only
|
|
6
|
+
At the moment, this package only offers an API allowing to run Clang and LLD in a virtual filesystem; no executables are provided.
|
|
7
7
|
|
|
8
|
-
[
|
|
9
|
-
[
|
|
8
|
+
[Clang/LLD]: https://llvm.org/
|
|
9
|
+
[WebAssembly]: https://webassembly.org/
|
|
10
10
|
[yowasp]: https://yowasp.github.io/
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
Examples
|
|
14
|
+
--------
|
|
15
|
+
|
|
16
|
+
All examples below are written for Node.js; to run them, install `@yowasp/clang` first. The C/C++ code can be compiled equally well in the browser and other runtimes, but WASI is unevenly supported.
|
|
17
|
+
|
|
18
|
+
### Hosted C++ executable
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { runClang } from '@yowasp/clang';
|
|
22
|
+
const { meow } = await runClang(['clang++', 'test.cc', '-o', 'meow'],
|
|
23
|
+
{"test.cc": `#include <iostream>\nint main() { std::cout << "meow++" << std::endl; }`});
|
|
24
|
+
|
|
25
|
+
import { WASI } from 'node:wasi';
|
|
26
|
+
const wasi = new WASI({ version: 'preview1' });
|
|
27
|
+
const module = await WebAssembly.compile(meow);
|
|
28
|
+
const instance = await WebAssembly.instantiate(module,
|
|
29
|
+
{wasi_snapshot_preview1: wasi.wasiImport});
|
|
30
|
+
wasi.start(instance);
|
|
31
|
+
// prints "meow++"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Freestanding C library
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import { runClang } from '@yowasp/clang';
|
|
39
|
+
const { 'a.out': wasm } = await runClang(['clang', '-nostdlib', '-Wl,--no-entry', 'test.c'], {
|
|
40
|
+
'test.c': 'int add(int a, int b) __attribute__((export_name("add"))) { return a + b; }'});
|
|
41
|
+
|
|
42
|
+
const module = await WebAssembly.compile(wasm);
|
|
43
|
+
const instance = await WebAssembly.instantiate(module);
|
|
44
|
+
console.log('add(1, 2) =', instance.exports.add(1, 2));
|
|
45
|
+
// prints "add(1, 2) = 3"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
13
49
|
API reference
|
|
14
50
|
-------------
|
|
15
51
|
|
|
16
|
-
This package provides
|
|
52
|
+
This package provides two functions:
|
|
17
53
|
|
|
18
54
|
- `runLLVM`
|
|
55
|
+
- The first argument is the utility to run: one of `addr2line`, `ar`, `c++filt`, `dwarfdump`, `nm`, `objcopy`, `objdump`, `readobj`, `ranlib`, `size`, `strip`, `symbolizer`, `wasm-ld`.
|
|
56
|
+
- `runClang`
|
|
57
|
+
- The first argument is either `clang` or `clang++`.
|
|
58
|
+
- Due to WASI limitations (an inability to spawn subprocesses), this function is a wrapper that parses the output of `clang -###` or `clang++ -###` to determine the sequence of processes to run. The parser was written with great care and handles many common exceptional conditions (e.g. the `-help` option), but the resulting function still deviates from how a standard Clang compiler driver would behave. Please report any deviations that impact your workflow as [issues].
|
|
59
|
+
|
|
60
|
+
[issues]: https://github.com/YoWASP/clang/issues
|
|
19
61
|
|
|
20
62
|
For more detail, see the documentation for [the JavaScript YoWASP runtime](https://github.com/YoWASP/runtime-js#api-reference).
|
|
21
63
|
|
|
@@ -39,4 +81,4 @@ With this scheme, there is a direct correspondence between upstream versions and
|
|
|
39
81
|
License
|
|
40
82
|
-------
|
|
41
83
|
|
|
42
|
-
This package is covered by the [
|
|
84
|
+
This package is covered by the [Apache 2 license](LICENSE.txt), which is the same as the (base) [LLVM license](https://github.com/llvm/llvm-project/blob/main/LICENSE.TXT).
|