microbit-clang-wasm-codal 0.305.0-alpha.2 → 0.305.0-alpha.4
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 +82 -19
- package/codal/manifest.json +16749 -6
- package/codal/payload.tar +0 -0
- package/lib/config.js +153 -0
- package/lib/core.js +181 -20
- package/lib/index.d.ts +46 -5
- package/lib/index.js +1 -0
- package/lib/node.d.ts +3 -1
- package/lib/node.js +3 -0
- package/lib/recipe.js +55 -17
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
**Builds a BBC micro:bit C++ program to a hex file, in a browser or in Node, with nothing
|
|
4
4
|
installed.** Give it your sources, get back the hex, the link map, and the compiler's output both as
|
|
5
|
-
text and read into errors and warnings.
|
|
5
|
+
text and read into errors and warnings. It also lists what can be typed at a position, for an
|
|
6
|
+
editor's completions.
|
|
6
7
|
|
|
7
8
|
It is not a copy of CODAL on npm. Three things come together here: CODAL prebuilt as static
|
|
8
9
|
libraries, **the build recipe captured from CODAL's own native CMake build** so the flags are the
|
|
9
10
|
ones the supported toolchain uses rather than a hand-written imitation, and the logic that drives
|
|
10
11
|
[microbit-clang-wasm](https://github.com/carlosperate/microbit-clang-wasm)'s WebAssembly Clang
|
|
11
|
-
through the compile, link and hex steps. The CODAL sources ship too
|
|
12
|
-
|
|
12
|
+
through the compile, link and hex steps. The CODAL sources ship too: a program can include any
|
|
13
|
+
header in the tree, and a `codal.json` with other settings has CODAL compiled from them.
|
|
13
14
|
|
|
14
15
|
On a desktop you install `arm-none-eabi-gcc` and provide CODAL yourself through
|
|
15
16
|
[microbit-v2-samples](https://github.com/lancaster-university/microbit-v2-samples). Here the
|
|
@@ -58,6 +59,36 @@ and rejects with the signal's reason.
|
|
|
58
59
|
await compile(files, { onStep: (step) => console.log(step.tool, step.exitCode), signal: controller.signal });
|
|
59
60
|
```
|
|
60
61
|
|
|
62
|
+
## Completions
|
|
63
|
+
|
|
64
|
+
`complete` lists what can go at a position in one of your files, for an editor's completion list:
|
|
65
|
+
the members after `uBit.` or `uBit.display.`, anything in scope, a call's overloads, with each
|
|
66
|
+
one's type, parameters, defaults and the first sentence of CODAL's documentation. It runs the same
|
|
67
|
+
recipe and `codal.json` settings a build would, up to the position, and compiles no CODAL, so a
|
|
68
|
+
changed `codal.json` changes the list at once.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { complete } from 'microbit-clang-wasm-codal';
|
|
72
|
+
|
|
73
|
+
const { completions } = await complete({ 'main.cpp': source }, { file: 'main.cpp', line: 7, column: 10 });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
It needs only the file, the headers it may include and `codal.json`. The line counts from 1 and the
|
|
77
|
+
column in bytes of UTF-8, as Clang does. The records are
|
|
78
|
+
[microbit-clang-wasm](https://github.com/carlosperate/microbit-clang-wasm)'s `readCompletions`,
|
|
79
|
+
with your own file names, and of the 14,000 macros CODAL brings in only the ones a program passes
|
|
80
|
+
to it or gets back: component IDs (`MICROBIT_ID_BUTTON_A`), event values
|
|
81
|
+
(`MICROBIT_BUTTON_EVT_CLICK`), listen flags (`MESSAGE_BUS_LISTENER_IMMEDIATE`), the event service's
|
|
82
|
+
(`MES_…`) and error codes (`MICROBIT_OK`, `MICROBIT_NO_DATA`). Your own `#define`s are listed too,
|
|
83
|
+
and so are the settings you write in `codal.json`'s `config`.
|
|
84
|
+
The deep-sleep members every CODAL component inherits from `CodalComponent` are left out. A
|
|
85
|
+
request takes a tenth to a quarter of a second in Node once loaded; the first after a
|
|
86
|
+
change of settings also lists CODAL's macros, about a quarter of a second more. Completions run in a filesystem of their
|
|
87
|
+
own, so one never waits for a build or changes it, and they queue only behind each other. A
|
|
88
|
+
`signal` aborted before a request starts drops it.
|
|
89
|
+
|
|
90
|
+
## Loading it
|
|
91
|
+
|
|
61
92
|
In Node the package reads its own files from disk. Anywhere else, hand it a loader for the two
|
|
62
93
|
assets it ships, `codal/manifest.json` and `codal/payload.tar`:
|
|
63
94
|
|
|
@@ -67,14 +98,42 @@ import { createCodal } from 'microbit-clang-wasm-codal';
|
|
|
67
98
|
const codal = createCodal({ loadAsset: async (name) => bytesFor(name) });
|
|
68
99
|
```
|
|
69
100
|
|
|
101
|
+
## Your `codal.json`
|
|
102
|
+
|
|
103
|
+
Put a `codal.json` at the root of the files you pass, as in
|
|
104
|
+
[microbit-v2-samples](https://github.com/lancaster-university/microbit-v2-samples), and its
|
|
105
|
+
`config` settings take effect:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
await compile({ 'main.cpp': source, 'codal.json': '{ "config": { "MICROBIT_BLE_ENABLED": 1 } }' });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
CODAL is shipped compiled with one set of settings, microbit-v2-samples' default: the SoftDevice
|
|
112
|
+
present and the BLE stack off. Every setting is a `#define` in a header that all of CODAL is
|
|
113
|
+
compiled with, so other settings mean compiling CODAL again: 199 files, about 15 to 30 seconds in a
|
|
114
|
+
browser on a recent laptop. CODAL comes first and your own files after it, so a log reads in order.
|
|
115
|
+
CODAL's steps come through `onStep` like any other, with a `codal` field naming the file each
|
|
116
|
+
built (`codal-core/source/core/CodalFiber.cpp`, `libcodal-core.a`) and how many are done. The result is kept in memory for the next build with the same settings, four sets
|
|
117
|
+
at most, and nothing is saved anywhere.
|
|
118
|
+
|
|
119
|
+
The header is made by the same rule as CODAL's CMake: your settings in the order you wrote them,
|
|
120
|
+
then the defaults of CODAL's `target-locked.json` you did not set, numbers exactly as written
|
|
121
|
+
(`52.0` stays `52.0`), and `DEVICE_BLE` set to 1 also bringing the SoftDevice and its linker script.
|
|
122
|
+
Each value is written as it is, so a setting the compiler cannot use fails in the compiler.
|
|
123
|
+
|
|
124
|
+
`compile` rejects, before compiling anything, a `codal.json` it cannot follow, and the message says
|
|
125
|
+
what to change: one that is not valid JSON; a `target` other than the CODAL in this package (leave
|
|
126
|
+
`target` out, or name exactly this one); `application` or `output_folder`, since every C++ file you
|
|
127
|
+
pass is compiled and the hex comes back to you; a `config` that is not an object; and
|
|
128
|
+
`SOFTDEVICE_PRESENT` without `DEVICE_BLE` set to 1, which CODAL's own build refuses too. The
|
|
129
|
+
message's first line says what is wrong and what to do, short enough for a notification; anything
|
|
130
|
+
longer, such as the `"target"` to paste, follows on the lines after it, JSON laid out as in
|
|
131
|
+
`codal.json`. Without a `codal.json`, the shipped settings are used.
|
|
132
|
+
|
|
70
133
|
## What it does not do yet
|
|
71
134
|
|
|
72
|
-
-
|
|
73
|
-
|
|
74
|
-
configuration means rebuilding CODAL, which comes later.
|
|
75
|
-
- **No CODAL sources are compiled.** The four archives ship prebuilt; the complete source and header
|
|
76
|
-
trees are here so that any header a program reaches is present, but nothing recompiles them.
|
|
77
|
-
- No worker pool, no object cache.
|
|
135
|
+
- **One CODAL version**, v0.3.5. A `target` naming another is refused.
|
|
136
|
+
- **CODAL compiled for your settings is not saved.** It lasts as long as the package is loaded.
|
|
78
137
|
|
|
79
138
|
## How it is built
|
|
80
139
|
|
|
@@ -86,7 +145,9 @@ toolchain files — points it at the pinned CODAL with `tools/configure-harness.
|
|
|
86
145
|
`tools/generate.mjs` over that build's own `ninja -t commands`. Everything authored is in
|
|
87
146
|
`package.json`; the ATfE release is deliberately not repeated here. The
|
|
88
147
|
recipe in `codal/manifest.json` is therefore the native build's flags, rewritten for a virtual
|
|
89
|
-
filesystem rather than written by hand
|
|
148
|
+
filesystem rather than written by hand: the compile for your files, CODAL's own 199 compiles and 4
|
|
149
|
+
archives, the link and the hex. Before that, CI builds the same checkout with the settings in
|
|
150
|
+
`test/configs/` for the tests below, each from clean.
|
|
90
151
|
|
|
91
152
|
```sh
|
|
92
153
|
node tools/configure-harness.mjs <harness checkout> # then build it with CODAL_TOOLCHAIN=CLANG
|
|
@@ -121,20 +182,22 @@ the build harness, `codalJson` the keys written over its `codal.json` — and re
|
|
|
121
182
|
## Tests
|
|
122
183
|
|
|
123
184
|
`npm test` compiles a program, checks the hex, and checks that errors in the program, in CODAL's
|
|
124
|
-
headers because of it, and at the link are read into diagnostics naming the caller's files
|
|
125
|
-
|
|
185
|
+
headers because of it, and at the link are read into diagnostics naming the caller's files; that a
|
|
186
|
+
`codal.json` with other settings compiles CODAL once and is then reused; the header rule and
|
|
187
|
+
every refusal; and what `complete` lists, which macros among it, and that a build running beside it
|
|
188
|
+
gives the same hex. It needs nothing installed.
|
|
126
189
|
|
|
127
|
-
|
|
128
|
-
one:
|
|
190
|
+
Further tests compare against native builds, and run only when pointed at them:
|
|
129
191
|
|
|
130
192
|
```sh
|
|
131
|
-
MICROBIT_SAMPLES=<built samples tree> npm test
|
|
193
|
+
MICROBIT_SAMPLES=<built samples tree> MICROBIT_CONFIGS=<one folder per test configuration> npm test
|
|
132
194
|
```
|
|
133
195
|
|
|
134
|
-
|
|
135
|
-
byte for byte
|
|
136
|
-
|
|
137
|
-
|
|
196
|
+
They compile that tree's own program through the WebAssembly compiler and require the hex to match
|
|
197
|
+
byte for byte: with the shipped CODAL, with CODAL compiled here for the same settings, and for each
|
|
198
|
+
configuration in `test/configs/`, whose header and command list must also match CMake's. That
|
|
199
|
+
agreement is what says the browser build is the same build. CI does it on every run, against native
|
|
200
|
+
builds made minutes earlier from the pinned sources, so there is no reference file here to go stale.
|
|
138
201
|
|
|
139
202
|
## Licences
|
|
140
203
|
|