microbit-clang-wasm-codal 0.305.0-alpha.2 → 0.305.0-alpha.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 +49 -18
- package/codal/manifest.json +16749 -5
- package/codal/payload.tar +0 -0
- package/lib/config.js +155 -0
- package/lib/core.js +81 -14
- package/lib/index.d.ts +16 -3
- package/lib/index.js +1 -0
- package/lib/recipe.js +20 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@ It is not a copy of CODAL on npm. Three things come together here: CODAL prebuil
|
|
|
8
8
|
libraries, **the build recipe captured from CODAL's own native CMake build** so the flags are the
|
|
9
9
|
ones the supported toolchain uses rather than a hand-written imitation, and the logic that drives
|
|
10
10
|
[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
|
-
|
|
11
|
+
through the compile, link and hex steps. The CODAL sources ship too: a program can include any
|
|
12
|
+
header in the tree, and a `codal.json` with other settings has CODAL compiled from them.
|
|
13
13
|
|
|
14
14
|
On a desktop you install `arm-none-eabi-gcc` and provide CODAL yourself through
|
|
15
15
|
[microbit-v2-samples](https://github.com/lancaster-university/microbit-v2-samples). Here the
|
|
@@ -67,14 +67,42 @@ import { createCodal } from 'microbit-clang-wasm-codal';
|
|
|
67
67
|
const codal = createCodal({ loadAsset: async (name) => bytesFor(name) });
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
## Your `codal.json`
|
|
71
|
+
|
|
72
|
+
Put a `codal.json` at the root of the files you pass, as in
|
|
73
|
+
[microbit-v2-samples](https://github.com/lancaster-university/microbit-v2-samples), and its
|
|
74
|
+
`config` settings take effect:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
await compile({ 'main.cpp': source, 'codal.json': '{ "config": { "MICROBIT_BLE_ENABLED": 1 } }' });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
CODAL is shipped compiled with one set of settings, microbit-v2-samples' default: the SoftDevice
|
|
81
|
+
present and the BLE stack off. Every setting is a `#define` in a header that all of CODAL is
|
|
82
|
+
compiled with, so other settings mean compiling CODAL again: 199 files, about 15 to 30 seconds in a
|
|
83
|
+
browser on a recent laptop. CODAL comes first and your own files after it, so a log reads in order.
|
|
84
|
+
CODAL's steps come through `onStep` like any other, with a `codal` field naming the file each
|
|
85
|
+
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
|
|
86
|
+
at most, and nothing is saved anywhere.
|
|
87
|
+
|
|
88
|
+
The header is made by the same rule as CODAL's CMake: your settings in the order you wrote them,
|
|
89
|
+
then the defaults of CODAL's `target-locked.json` you did not set, numbers exactly as written
|
|
90
|
+
(`52.0` stays `52.0`), and `DEVICE_BLE` set to 1 also bringing the SoftDevice and its linker script.
|
|
91
|
+
Each value is written as it is, so a setting the compiler cannot use fails in the compiler.
|
|
92
|
+
|
|
93
|
+
`compile` rejects, before compiling anything, a `codal.json` it cannot follow, and the message says
|
|
94
|
+
what to change: one that is not valid JSON; a `target` other than the CODAL in this package (leave
|
|
95
|
+
`target` out, or name exactly this one); `application` or `output_folder`, since every C++ file you
|
|
96
|
+
pass is compiled and the hex comes back to you; a `config` that is not an object; and
|
|
97
|
+
`SOFTDEVICE_PRESENT` without `DEVICE_BLE` set to 1, which CODAL's own build refuses too. The
|
|
98
|
+
message's first line says what is wrong and what to do, short enough for a notification; anything
|
|
99
|
+
longer, such as the `"target"` to paste, follows on the lines after it, JSON laid out as in
|
|
100
|
+
`codal.json`. Without a `codal.json`, the shipped settings are used.
|
|
101
|
+
|
|
70
102
|
## What it does not do yet
|
|
71
103
|
|
|
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.
|
|
104
|
+
- **One CODAL version**, v0.3.5. A `target` naming another is refused.
|
|
105
|
+
- **CODAL compiled for your settings is not saved.** It lasts as long as the package is loaded.
|
|
78
106
|
|
|
79
107
|
## How it is built
|
|
80
108
|
|
|
@@ -86,7 +114,9 @@ toolchain files — points it at the pinned CODAL with `tools/configure-harness.
|
|
|
86
114
|
`tools/generate.mjs` over that build's own `ninja -t commands`. Everything authored is in
|
|
87
115
|
`package.json`; the ATfE release is deliberately not repeated here. The
|
|
88
116
|
recipe in `codal/manifest.json` is therefore the native build's flags, rewritten for a virtual
|
|
89
|
-
filesystem rather than written by hand
|
|
117
|
+
filesystem rather than written by hand: the compile for your files, CODAL's own 199 compiles and 4
|
|
118
|
+
archives, the link and the hex. Before that, CI builds the same checkout with the settings in
|
|
119
|
+
`test/configs/` for the tests below, each from clean.
|
|
90
120
|
|
|
91
121
|
```sh
|
|
92
122
|
node tools/configure-harness.mjs <harness checkout> # then build it with CODAL_TOOLCHAIN=CLANG
|
|
@@ -121,20 +151,21 @@ the build harness, `codalJson` the keys written over its `codal.json` — and re
|
|
|
121
151
|
## Tests
|
|
122
152
|
|
|
123
153
|
`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
|
-
|
|
154
|
+
headers because of it, and at the link are read into diagnostics naming the caller's files; that a
|
|
155
|
+
`codal.json` with other settings compiles CODAL once and is then reused; and the header rule and
|
|
156
|
+
every refusal. It needs nothing installed.
|
|
126
157
|
|
|
127
|
-
|
|
128
|
-
one:
|
|
158
|
+
Further tests compare against native builds, and run only when pointed at them:
|
|
129
159
|
|
|
130
160
|
```sh
|
|
131
|
-
MICROBIT_SAMPLES=<built samples tree> npm test
|
|
161
|
+
MICROBIT_SAMPLES=<built samples tree> MICROBIT_CONFIGS=<one folder per test configuration> npm test
|
|
132
162
|
```
|
|
133
163
|
|
|
134
|
-
|
|
135
|
-
byte for byte
|
|
136
|
-
|
|
137
|
-
|
|
164
|
+
They compile that tree's own program through the WebAssembly compiler and require the hex to match
|
|
165
|
+
byte for byte: with the shipped CODAL, with CODAL compiled here for the same settings, and for each
|
|
166
|
+
configuration in `test/configs/`, whose header and command list must also match CMake's. That
|
|
167
|
+
agreement is what says the browser build is the same build. CI does it on every run, against native
|
|
168
|
+
builds made minutes earlier from the pinned sources, so there is no reference file here to go stale.
|
|
138
169
|
|
|
139
170
|
## Licences
|
|
140
171
|
|