microbit-clang-wasm-codal 0.305.0-alpha.1 → 0.305.0-alpha.2

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 CHANGED
@@ -1,7 +1,8 @@
1
1
  # microbit-clang-wasm-codal
2
2
 
3
3
  **Builds a BBC micro:bit C++ program to a hex file, in a browser or in Node, with nothing
4
- installed.** Give it your sources, get back the hex, the link map and the compiler's output.
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
6
 
6
7
  It is not a copy of CODAL on npm. Three things come together here: CODAL prebuilt as static
7
8
  libraries, **the build recipe captured from CODAL's own native CMake build** so the flags are the
@@ -15,19 +16,30 @@ On a desktop you install `arm-none-eabi-gcc` and provide CODAL yourself through
15
16
  compiler is the toolchain package and CODAL is this one, so a browser, Node or a VS Code extension
16
17
  can build a micro:bit program with nothing else installed and nothing downloaded at run time.
17
18
 
18
- Status: pre-release, work in progress. Nothing is published yet.
19
+ Status: pre-release, work in progress.
19
20
 
20
21
  ## Using it
21
22
 
22
23
  ```js
23
24
  import { compile } from 'microbit-clang-wasm-codal';
24
25
 
25
- const { ok, hex, map, output } = await compile({ 'main.cpp': source });
26
+ const { ok, hex, map, output, diagnostics } = await compile({ 'main.cpp': source });
26
27
  ```
27
28
 
28
29
  `compile` takes the user's files, keyed by workspace-relative path, and returns the Intel hex to
29
30
  flash, the link map, and everything the tools wrote to stderr. On a compile or link error `ok` is
30
31
  false, `hex` is null, and `output` names the file, by the path you gave, with its line and column.
32
+ Every source is compiled even after one fails, so each file's errors are there; the link runs only
33
+ once they all compiled.
34
+
35
+ `diagnostics` holds the errors and warnings, read by
36
+ [microbit-clang-wasm](https://github.com/carlosperate/microbit-clang-wasm)'s `readDiagnostics`:
37
+ file, line, column, message, the warning option, the notes and the include chain. Your files are
38
+ named as you named them, the linker's references included; CODAL's own headers appear as
39
+ `codal/...` and the C and C++ libraries as `/usr/...`. A linker note pointing into CODAL's prebuilt
40
+ libraries, such as where a symbol you also defined lives, names the path they were built at, which
41
+ exists on no machine you have. Each of `steps` carries its own output read the same way, summary
42
+ lines included, so joining their `text` gives that step's `stderr` back.
31
43
 
32
44
  **Key order is link order.** The objects are numbered in the order the sources arrive and linked in
33
45
  that order, so hand them over sorted, or in whatever fixed order you choose, if you want the same
@@ -62,7 +74,7 @@ const codal = createCodal({ loadAsset: async (name) => bytesFor(name) });
62
74
  configuration means rebuilding CODAL, which comes later.
63
75
  - **No CODAL sources are compiled.** The four archives ship prebuilt; the complete source and header
64
76
  trees are here so that any header a program reaches is present, but nothing recompiles them.
65
- - No diagnostics beyond the compiler's own text, no worker pool, no object cache.
77
+ - No worker pool, no object cache.
66
78
 
67
79
  ## How it is built
68
80
 
@@ -94,13 +106,13 @@ of this package's own build logic, where:
94
106
 
95
107
  ```
96
108
  0 . 305 . 2
97
- │ └┬┘ └┬┘
98
- │ │ └── packaging version
99
- │ └──────── CODAL minor.patch (3.05)
109
+ │ └┬┘ └┬┘
110
+ │ │ └─── JS package version
111
+ │ └──────── CODAL combined minor.patch (3.05)
100
112
  └───────────── CODAL major
101
113
  ```
102
114
 
103
- So `~0.305.0` locks to CODAL 0.3.5 while taking packaging fixes. While the packaging of a CODAL
115
+ So `~0.305.0` locks to CODAL v0.3.5 while taking packaging fixes. While the packaging of a CODAL
104
116
  release is still changing it is published as a prerelease, `0.305.0-alpha.1`, under the `next`
105
117
  dist-tag. Which CODAL is inside is pinned in `package.json` under `codal` — `buildSystem` names
106
118
  the build harness, `codalJson` the keys written over its `codal.json` — and recorded in
@@ -108,8 +120,9 @@ the build harness, `codalJson` the keys written over its `codal.json` — and re
108
120
 
109
121
  ## Tests
110
122
 
111
- `npm test` compiles a program, checks the hex and checks an error is reported usefully. It needs
112
- nothing installed.
123
+ `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. It
125
+ needs nothing installed.
113
126
 
114
127
  One further test compares against the hex a native build produced, and runs only when pointed at
115
128
  one:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schema": 1,
3
- "generated": "2026-09-10",
3
+ "generated": "2026-10-01",
4
4
  "codal": {
5
5
  "version": "0.3.5",
6
6
  "versionHash": "f5d1682",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "toolchain": {
36
36
  "package": "microbit-clang-wasm",
37
- "version": "21.11.0-alpha.1",
37
+ "version": "21.11.0-alpha.2",
38
38
  "llvm": {
39
39
  "version": "21.1.1",
40
40
  "repository": "https://github.com/arm/arm-toolchain.git",
package/lib/core.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // The recipes come from `codal/manifest.json`, generated from the native build's own command list,
4
4
  // so this runs the flags the native toolchain runs.
5
5
 
6
- import { createSession, sysroot } from 'microbit-clang-wasm';
6
+ import { createSession, readDiagnostics, sysroot } from 'microbit-clang-wasm';
7
7
 
8
8
  import { SOURCE, plan } from './recipe.js';
9
9
  import { unpackTar } from './tar.js';
@@ -54,26 +54,29 @@ export function createCodal({ loadAsset } = {}) {
54
54
 
55
55
  const steps = [];
56
56
  let hex = null;
57
+ let failed = false;
57
58
  for (const command of recipe.steps) {
58
59
  // A whole build is one unbroken chain of microtasks, so an abort arriving as a message or a
59
60
  // timer is never delivered while it runs. This hands the event queue back between steps.
60
61
  if (signal) await new Promise((resolve) => setTimeout(resolve, 0));
61
62
  // Between steps only: a tool already running cannot be interrupted, so it finishes first.
62
63
  signal?.throwIfAborted();
64
+ // Every source is compiled, so each file's errors are reported; only the link needs them all.
65
+ if (failed && !command.source) break;
63
66
  const step = await invoke(session, command, manifest.layout.project);
64
67
  steps.push(step);
65
68
  onStep?.(step);
66
- if (step.exitCode !== 0) return failure(steps);
69
+ failed ||= step.exitCode !== 0;
67
70
  if (command.captureStdout) hex = step.stdout;
68
71
  }
72
+ if (failed) return failure(steps);
69
73
 
70
74
  const map = await session.readFile(recipe.map);
71
75
  return {
72
76
  ok: true,
73
77
  hex: new TextDecoder().decode(hex),
74
78
  map: map === null ? null : new TextDecoder().decode(map),
75
- output: steps.map((step) => step.stderr).join(''),
76
- steps,
79
+ ...report(steps),
77
80
  };
78
81
  };
79
82
 
@@ -115,8 +118,9 @@ async function open(loadAsset) {
115
118
  }
116
119
 
117
120
  // Only the capturing step keeps its stdout; the others would hold a copy of the hex for nothing.
118
- // Diagnostics name files as the caller did, so the virtual project prefix comes off them.
119
- async function invoke(session, { tool, args, captureStdout }, project) {
121
+ // Diagnostics name files as the caller did, so the virtual project prefix comes off them before
122
+ // they are read, one step at a time, since an include chain carries over only within one run.
123
+ async function invoke(session, { source = null, tool, args, captureStdout }, project) {
120
124
  const chunks = [];
121
125
  const decoder = new TextDecoder();
122
126
  let stderr = '';
@@ -126,18 +130,29 @@ async function invoke(session, { tool, args, captureStdout }, project) {
126
130
  stderr: (bytes) => bytes && (stderr += decoder.decode(bytes, { stream: true })),
127
131
  });
128
132
  stderr = stripProject(stderr + decoder.decode(), project);
129
- return { tool, args, exitCode, stderr, stdout: captureStdout ? join(chunks) : null };
133
+ return { source, tool, args, exitCode, stderr, stdout: captureStdout ? join(chunks) : null, diagnostics: readDiagnostics(stderr) };
130
134
  }
131
135
 
132
136
  // Only where a path starts is the prefix ours: a caller whose own file sits under `project/source/`
133
- // gets it twice in the virtual path, and removing both would name a file they do not have.
137
+ // gets it twice in the virtual path, and removing both would name a file they do not have. The
138
+ // linker's `>>>` lines also give it absolute, in parentheses: `(/project/source/main.cpp:7)`.
134
139
  function stripProject(text, project) {
135
140
  const escaped = project.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
136
- return text.replace(new RegExp(`(^|\\s)${escaped}/`, 'gm'), '$1');
141
+ return text
142
+ .replace(new RegExp(`(^|\\s)${escaped}/`, 'gm'), '$1')
143
+ .replace(new RegExp(`^(>>> .*?\\()/${escaped}/`, 'gm'), '$1');
144
+ }
145
+
146
+ function report(steps) {
147
+ return {
148
+ output: steps.map((step) => step.stderr).join(''),
149
+ diagnostics: steps.flatMap((step) => step.diagnostics.filter((record) => record.severity !== null)),
150
+ steps,
151
+ };
137
152
  }
138
153
 
139
154
  function failure(steps) {
140
- return { ok: false, hex: null, map: null, output: steps.map((step) => step.stderr).join(''), steps };
155
+ return { ok: false, hex: null, map: null, ...report(steps) };
141
156
  }
142
157
 
143
158
  function join(chunks) {
package/lib/index.d.ts CHANGED
@@ -4,15 +4,25 @@
4
4
  */
5
5
  export type Files = Record<string, string | Uint8Array>;
6
6
 
7
+ import type { Diagnostic, OtherOutput } from 'microbit-clang-wasm';
8
+
9
+ export type { Diagnostic, DiagnosticLocation, DiagnosticNote, OtherOutput } from 'microbit-clang-wasm';
10
+
7
11
  export type AssetLoader = (name: string) => Promise<Uint8Array> | Uint8Array;
8
12
 
9
13
  export type Step = {
14
+ /** The caller's file this step compiled, as they named it; null for the link and the hex. */
15
+ source: string | null;
10
16
  tool: string;
11
17
  args: string[];
12
18
  exitCode: number;
19
+ /** With the caller's own file names, as are the diagnostics read from it; CODAL's prebuilt
20
+ * libraries keep the path they were built at. */
13
21
  stderr: string;
14
22
  /** Only the step whose output is the hex keeps it; null everywhere else. */
15
23
  stdout: Uint8Array | null;
24
+ /** `stderr` read by the toolchain's `readDiagnostics`: joining every `text` gives it back. */
25
+ diagnostics: (Diagnostic | OtherOutput)[];
16
26
  };
17
27
 
18
28
  export type Result = {
@@ -22,11 +32,14 @@ export type Result = {
22
32
  map: string | null;
23
33
  /** Every step's stderr, in order. */
24
34
  output: string;
35
+ /** Every step's errors, warnings and remarks, in order. */
36
+ diagnostics: Diagnostic[];
25
37
  steps: Step[];
26
38
  };
27
39
 
28
40
  export type CompileOptions = {
29
- /** Called as each tool finishes; on a failure the last step reported is the one that failed. */
41
+ /** Called as each tool finishes. Every source is compiled even after one fails; the link and
42
+ * the hex run only when they all succeeded. */
30
43
  onStep?: (step: Step) => void;
31
44
  /** Aborting rejects with the signal's reason between steps; a tool already running finishes first. */
32
45
  signal?: AbortSignal;
package/lib/recipe.js CHANGED
@@ -25,6 +25,7 @@ export function plan(manifest, names, { sysroot }) {
25
25
  return {
26
26
  steps: [
27
27
  ...sources.map((name, index) => ({
28
+ source: name,
28
29
  tool: manifest.compile.tool,
29
30
  args: [...fill(manifest.compile.flags), ...includes, '-c', `${project}/${name}`, '-o', objects[index]],
30
31
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microbit-clang-wasm-codal",
3
- "version": "0.305.0-alpha.1",
3
+ "version": "0.305.0-alpha.2",
4
4
  "description": "Compile BBC micro:bit C++ programs to a flashable hex in a browser or Node, with prebuilt CODAL and no toolchain to install",
5
5
  "author": "Carlos Pereira Atencio",
6
6
  "license": "SEE LICENSE IN LICENSES",
@@ -38,7 +38,7 @@
38
38
  "./package.json": "./package.json"
39
39
  },
40
40
  "dependencies": {
41
- "microbit-clang-wasm": "21.11.0-alpha.1"
41
+ "microbit-clang-wasm": "21.11.0-alpha.2"
42
42
  },
43
43
  "scripts": {
44
44
  "configure": "node tools/configure-harness.mjs",