@typecad/cuttlefish 1.0.0-alpha.13 → 1.0.0-alpha.15
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 -79
- package/assets/editor-extensions/typecad-debug/README.md +141 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js +347 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js.map +1 -0
- package/assets/editor-extensions/typecad-debug/package.json +76 -0
- package/assets/editor-extensions/typecad-ui/LICENSE +27 -0
- package/assets/editor-extensions/typecad-ui/README.md +52 -0
- package/assets/editor-extensions/typecad-ui/file-icon-dark.png +0 -0
- package/assets/editor-extensions/typecad-ui/file-icon-light.png +0 -0
- package/assets/editor-extensions/typecad-ui/icon.png +0 -0
- package/assets/editor-extensions/typecad-ui/language-configuration.json +43 -0
- package/assets/editor-extensions/typecad-ui/package.json +54 -0
- package/assets/editor-extensions/typecad-ui/snippets/typecad-ui.json +80 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/markdown-ui.json +45 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/typecad-ui.tmLanguage.json +1269 -0
- package/dist/api/config.d.ts +30 -27
- package/dist/api/schema/types.d.ts +20 -3
- package/dist/api/shared/async-runtime-static.d.ts +1 -1
- package/dist/api/shared/async-runtime-static.js +5 -5
- package/dist/api/shared/async-types.d.ts +3 -2
- package/dist/api/shared/board-catalog.d.ts +2 -0
- package/dist/api/shared/board-catalog.js +6 -0
- package/dist/api/shared/board-resolver.d.ts +4 -7
- package/dist/api/shared/board-resolver.js +2 -1
- package/dist/api/shared/coop-scheduler.d.ts +1 -1
- package/dist/api/shared/coop-scheduler.js +1 -1
- package/dist/api/shared/cpp-type-ir.d.ts +1 -1
- package/dist/api/shared/cpp-type-ir.js +1 -1
- package/dist/api/shared/display-profile.d.ts +1 -1
- package/dist/api/shared/display-profile.js +3 -5
- package/dist/api/shared/framework-manifest-registry.d.ts +1 -1
- package/dist/api/shared/framework-manifest-registry.js +0 -1
- package/dist/api/shared/framework-manifest.d.ts +65 -507
- package/dist/api/shared/framework-manifest.js +6 -11
- package/dist/api/shared/hal-op-ir.d.ts +294 -685
- package/dist/api/shared/hal-op-ir.js +31 -65
- package/dist/api/shared/index.d.ts +0 -4
- package/dist/api/shared/index.js +1 -7
- package/dist/api/shared/ir-core.d.ts +6 -0
- package/dist/api/shared/ir-declarations.d.ts +4 -0
- package/dist/api/shared/ir.d.ts +1 -3
- package/dist/api/shared/platform-strategy.d.ts +14 -37
- package/dist/api/shared/polyfill-helper-registry.js +0 -5
- package/dist/api/shared/polyfill-types.js +0 -27
- package/dist/api/shared/promise-runtime.js +3 -3
- package/dist/api/shared/spdx-licenses.d.ts +12 -10
- package/dist/api/shared/spdx-licenses.js +1 -1
- package/dist/api/shared/toolchain-types.d.ts +1 -1
- package/dist/api/shared/toolchain-types.js +3 -3
- package/dist/api/shared/types.d.ts +0 -3
- package/dist/api/shared/validate-framework-manifest.js +13 -33
- package/dist/board-catalog/dts-reader.d.ts +220 -0
- package/dist/board-catalog/dts-reader.js +1052 -0
- package/dist/board-catalog/index.d.ts +11 -0
- package/dist/board-catalog/index.js +12 -0
- package/dist/board-catalog/pinconfig.d.ts +48 -0
- package/dist/board-catalog/pinconfig.js +263 -0
- package/dist/board-catalog/sdk.d.ts +82 -0
- package/dist/board-catalog/sdk.js +180 -0
- package/dist/board-catalog/store.d.ts +196 -0
- package/dist/board-catalog/store.js +363 -0
- package/dist/board-catalog/types.d.ts +233 -0
- package/dist/board-catalog/types.js +7 -0
- package/dist/board-catalog/walker.d.ts +112 -0
- package/dist/board-catalog/walker.js +1101 -0
- package/dist/cli-utils.d.ts +2 -2
- package/dist/cli-utils.js +5 -5
- package/dist/cli.js +227 -244
- package/dist/config-loader.d.ts +14 -19
- package/dist/config-loader.js +242 -78
- package/dist/config-schema.d.ts +19 -227
- package/dist/config-schema.js +9 -8
- package/dist/contract/board-generator.d.ts +4 -4
- package/dist/contract/board-generator.js +16 -5
- package/dist/contract/contract-parser.d.ts +36 -127
- package/dist/contract/contract-parser.js +76 -0
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +70 -21
- package/dist/create/active-board-catalog.d.ts +9 -0
- package/dist/create/active-board-catalog.js +94 -0
- package/dist/create/board-catalog.generated.d.ts +96 -0
- package/dist/create/board-catalog.generated.js +128737 -0
- package/dist/create/board-search.d.ts +23 -0
- package/dist/create/board-search.js +88 -0
- package/dist/create/editor-integration.d.ts +32 -0
- package/dist/create/editor-integration.js +257 -0
- package/dist/create/eslint-rules-template.d.ts +2 -2
- package/dist/create/framework-catalog.d.ts +48 -8
- package/dist/create/framework-catalog.js +58 -44
- package/dist/create/index.d.ts +8 -13
- package/dist/create/index.js +5 -9
- package/dist/create/mcu-target.d.ts +39 -0
- package/dist/create/mcu-target.js +80 -0
- package/dist/create/pack-targets.d.ts +19 -0
- package/dist/create/pack-targets.js +56 -0
- package/dist/create/{init-scaffold.d.ts → scaffold.d.ts} +8 -11
- package/dist/create/{init-scaffold.js → scaffold.js} +28 -87
- package/dist/create/templates.d.ts +51 -0
- package/dist/create/{init-templates.js → templates.js} +135 -116
- package/dist/create/wizard.d.ts +19 -0
- package/dist/create/wizard.js +314 -0
- package/dist/debug/preprocessor.d.ts +5 -0
- package/dist/debug/preprocessor.js +31 -7
- package/dist/diagnostics/diagnostics-report.d.ts +1 -1
- package/dist/diagnostics/diagnostics-report.js +3 -11
- package/dist/diagnostics/json-schema.d.ts +1 -1
- package/dist/diagnostics/md-writer.js +2 -2
- package/dist/diagnostics/mermaid-builder.d.ts +1 -1
- package/dist/diagnostics/mermaid-builder.js +1 -1
- package/dist/emit/cpp-emitter.js +4 -1
- package/dist/emit/emitters/class-emitter.js +32 -4
- package/dist/emit/emitters/emitter-context.d.ts +11 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +1 -1
- package/dist/emit/emitters/function-emitter-impl.js +33 -17
- package/dist/emit/emitters/output-finalizer.d.ts +7 -0
- package/dist/emit/emitters/output-finalizer.js +31 -23
- package/dist/emit/emitters/setup.js +147 -63
- package/dist/emit/emitters/top-level-prep.js +1 -1
- package/dist/emit/emitters/type-decl-emitter.js +13 -8
- package/dist/emit/emitters/ui-emitter.js +1 -1
- package/dist/emit/expression-renderer.d.ts +3 -3
- package/dist/emit/expression-renderer.js +17 -7
- package/dist/emit/route-hal-op.js +17 -48
- package/dist/emit/snprintf-helpers.d.ts +1 -3
- package/dist/emit/snprintf-helpers.js +1 -39
- package/dist/emit/statement-renderer.d.ts +0 -4
- package/dist/emit/statement-renderer.js +54 -45
- package/dist/emit/utils/async-state-machine.d.ts +16 -9
- package/dist/emit/utils/async-state-machine.js +56 -54
- package/dist/emit/utils/comment-helpers.d.ts +0 -8
- package/dist/emit/utils/comment-helpers.js +1 -1
- package/dist/emit/utils/cpp-helpers.d.ts +2 -2
- package/dist/emit/utils/cpp-helpers.js +2 -2
- package/dist/emit/utils/hal-op-cpp-type.js +4 -6
- package/dist/emit/utils/index.d.ts +3 -3
- package/dist/emit/utils/index.js +3 -3
- package/dist/emit/utils/type-inference.d.ts +1 -29
- package/dist/emit/utils/type-inference.js +0 -75
- package/dist/framework-package.d.ts +3 -0
- package/dist/framework-package.js +23 -6
- package/dist/framework-registry.d.ts +5 -5
- package/dist/frameworks/native/graphics/terminal-preview.d.ts +5 -0
- package/dist/frameworks/native/graphics/terminal-preview.js +33 -0
- package/dist/frameworks/native/index.d.ts +3 -0
- package/dist/frameworks/native/index.js +15 -0
- package/dist/frameworks/native/native-compile.d.ts +17 -0
- package/dist/frameworks/native/native-compile.js +170 -0
- package/dist/frameworks/native/native-config.d.ts +41 -0
- package/dist/frameworks/native/native-config.js +7 -0
- package/dist/frameworks/native/strategy.d.ts +97 -0
- package/dist/frameworks/native/strategy.js +664 -0
- package/dist/ir/board-resolver.d.ts +18 -23
- package/dist/ir/board-resolver.js +43 -401
- package/dist/ir/build-ir-state.d.ts +3 -0
- package/dist/ir/build-ir-state.js +42 -0
- package/dist/ir/build-ir.d.ts +1 -1
- package/dist/ir/build-ir.js +64 -45
- package/dist/ir/declaration-builders.js +1 -0
- package/dist/ir/expression-to-ir.js +17 -10
- package/dist/ir/hal/hal-emitter.d.ts +0 -2
- package/dist/ir/hal/hal-emitter.js +92 -41
- package/dist/ir/hal/hal-parser.d.ts +5 -5
- package/dist/ir/hal/hal-parser.js +128 -36
- package/dist/ir/hal/hal-plugins.d.ts +0 -1
- package/dist/ir/hal/hal-plugins.js +425 -716
- package/dist/ir/heap-analysis.js +2 -41
- package/dist/ir/identifier-collector.js +32 -20
- package/dist/ir/network-validation.js +7 -11
- package/dist/ir/ownership-analysis.js +75 -13
- package/dist/ir/peripheral-usage.d.ts +8 -2
- package/dist/ir/peripheral-usage.js +78 -149
- package/dist/ir/peripheral-validation.js +23 -3
- package/dist/ir/pin-capability-validation.d.ts +12 -0
- package/dist/ir/pin-capability-validation.js +61 -97
- package/dist/ir/pin-mode-validation.js +5 -5
- package/dist/ir/program-analysis.d.ts +8 -15
- package/dist/ir/program-analysis.js +140 -323
- package/dist/ir/pulldown-validation.js +11 -4
- package/dist/ir/resource-analysis.js +15 -3
- package/dist/ir/statement-to-ir.js +0 -6
- package/dist/ir/timing-validation.js +1 -1
- package/dist/ir/transformers/array-methods.js +11 -5
- package/dist/ir/transformers/call-statement.js +20 -87
- package/dist/ir/transformers/callback-context-registry.d.ts +1 -1
- package/dist/ir/transformers/callback-context-registry.js +8 -16
- package/dist/ir/transformers/control-flow.js +0 -13
- package/dist/ir/transformers/expressions.js +10 -9
- package/dist/ir/transformers/hal-call-resolver.d.ts +2 -2
- package/dist/ir/transformers/hal-call-resolver.js +24 -10
- package/dist/ir/transformers/hal-emit-helpers.d.ts +2 -2
- package/dist/ir/transformers/hal-emit-helpers.js +2 -2
- package/dist/ir/transformers/namespace-methods.js +1 -1
- package/dist/ir/transformers/ui-callback-lowering.d.ts +0 -2
- package/dist/ir/transformers/ui-callback-lowering.js +0 -24
- package/dist/ir/transformers/variables.js +338 -42
- package/dist/ir/try-catch-validation.js +4 -3
- package/dist/ir/type-resolution.js +15 -4
- package/dist/ir/validation-orchestrator.js +0 -9
- package/dist/libdef/cpp-to-decl.d.ts +0 -9
- package/dist/libdef/cpp-to-decl.js +0 -72
- package/dist/libdef/registry.d.ts +0 -1
- package/dist/libdef/registry.js +1 -24
- package/dist/library/catalog.d.ts +35 -0
- package/dist/library/catalog.js +67 -0
- package/dist/library/cli.d.ts +2 -0
- package/dist/library/cli.js +168 -0
- package/dist/library/init.d.ts +25 -0
- package/dist/library/init.js +397 -0
- package/dist/library/install.d.ts +9 -0
- package/dist/library/install.js +80 -0
- package/dist/library/registry-search.d.ts +34 -0
- package/dist/library/registry-search.js +50 -0
- package/dist/library/validate.d.ts +17 -0
- package/dist/library/validate.js +175 -0
- package/dist/library-packages.d.ts +95 -0
- package/dist/library-packages.js +275 -0
- package/dist/mapping/peripheral-names.js +9 -4
- package/dist/mapping/source-map.d.ts +3 -4
- package/dist/mapping/source-map.js +12 -18
- package/dist/orchestrator/graph-builder.d.ts +3 -3
- package/dist/orchestrator/graph-builder.js +29 -12
- package/dist/orchestrator/type-checker.d.ts +3 -3
- package/dist/orchestrator/type-checker.js +3 -3
- package/dist/platform/async-runtime.js +1 -1
- package/dist/platform/coop-scheduler-runtime.js +2 -2
- package/dist/platform/generic-debug-codegen.d.ts +36 -0
- package/dist/platform/generic-debug-codegen.js +185 -0
- package/dist/platform/generic-strategy.d.ts +3 -4
- package/dist/platform/generic-strategy.js +5 -80
- package/dist/platform/index.js +1 -1
- package/dist/platform/registry.d.ts +2 -2
- package/dist/platform/registry.js +2 -2
- package/dist/preview/client.js +17 -3
- package/dist/safety/asil-decorators.d.ts +32 -0
- package/dist/safety/asil-decorators.js +32 -0
- package/dist/safety/authoring.d.ts +85 -0
- package/dist/safety/authoring.js +61 -0
- package/dist/safety/engine.d.ts +3 -0
- package/dist/safety/engine.js +83 -0
- package/dist/safety/hal/ops.d.ts +48 -0
- package/dist/safety/hal/ops.js +46 -0
- package/dist/safety/iso26262/analyze.d.ts +13 -0
- package/dist/safety/iso26262/analyze.js +29 -0
- package/dist/safety/iso26262/asil.d.ts +10 -0
- package/dist/safety/iso26262/asil.js +22 -0
- package/dist/safety/iso26262/collect.d.ts +14 -0
- package/dist/safety/iso26262/collect.js +137 -0
- package/dist/safety/iso26262/goto-checker.d.ts +10 -0
- package/dist/safety/iso26262/goto-checker.js +72 -0
- package/dist/safety/iso26262/heap-checker.d.ts +7 -0
- package/dist/safety/iso26262/heap-checker.js +57 -0
- package/dist/safety/iso26262/init-checker.d.ts +13 -0
- package/dist/safety/iso26262/init-checker.js +127 -0
- package/dist/safety/iso26262/loop-checker.d.ts +7 -0
- package/dist/safety/iso26262/loop-checker.js +86 -0
- package/dist/safety/iso26262/recursion-checker.d.ts +9 -0
- package/dist/safety/iso26262/recursion-checker.js +134 -0
- package/dist/safety/iso26262/sidecar-writer.d.ts +25 -0
- package/dist/safety/iso26262/sidecar-writer.js +13 -0
- package/dist/safety/passes/pinMode-intercept.d.ts +3 -0
- package/dist/safety/passes/pinMode-intercept.js +60 -0
- package/dist/safety/runtime/mode-table.d.ts +5 -0
- package/dist/safety/runtime/mode-table.js +55 -0
- package/dist/safety/runtime/polyfills.d.ts +6 -0
- package/dist/safety/runtime/polyfills.js +12 -0
- package/dist/safety/runtime/result-struct.d.ts +11 -0
- package/dist/safety/runtime/result-struct.js +98 -0
- package/dist/safety/runtime/safe-int.d.ts +33 -0
- package/dist/safety/runtime/safe-int.js +170 -0
- package/dist/safety/runtime/safe-traits.d.ts +4 -0
- package/dist/safety/runtime/safe-traits.js +95 -0
- package/dist/safety/runtime/safe-variable.d.ts +39 -0
- package/dist/safety/runtime/safe-variable.js +226 -0
- package/dist/safety/runtime/vote.d.ts +8 -0
- package/dist/safety/runtime/vote.js +92 -0
- package/dist/safety/runtime/write-verify.d.ts +8 -0
- package/dist/safety/runtime/write-verify.js +71 -0
- package/dist/safety/safe-int-types.d.ts +45 -0
- package/dist/safety/safe-int-types.js +25 -0
- package/dist/safety/safe-variable-types.d.ts +29 -0
- package/dist/safety/safe-variable-types.js +19 -0
- package/dist/safety/safety-bridge.d.ts +5 -6
- package/dist/safety/safety-bridge.js +15 -28
- package/dist/safety/sidecar-bridge.d.ts +1 -3
- package/dist/safety/sidecar-bridge.js +3 -20
- package/dist/safety/specifiers.d.ts +6 -0
- package/dist/safety/specifiers.js +14 -0
- package/dist/safety-hook.d.ts +8 -7
- package/dist/safety-hook.js +12 -13
- package/dist/testing.d.ts +5 -6
- package/dist/testing.js +5 -5
- package/dist/transpile/resolution.d.ts +1 -1
- package/dist/transpile/resolution.js +18 -9
- package/dist/transpile/test-pins.d.ts +18 -0
- package/dist/transpile/test-pins.js +142 -0
- package/dist/transpile.d.ts +1 -2
- package/dist/transpile.js +90 -29
- package/dist/types.d.ts +45 -26
- package/dist/ui-hook.d.ts +1 -1
- package/dist/utils/cli.d.ts +2 -2
- package/dist/utils/cli.js +160 -157
- package/dist/utils/fs.d.ts +3 -4
- package/dist/utils/fs.js +4 -5
- package/dist/utils/strings.d.ts +0 -1
- package/dist/utils/strings.js +0 -8
- package/dist/utils/ui.d.ts +5 -2
- package/dist/utils/ui.js +13 -3
- package/package.json +158 -149
- package/dist/add-preset.d.ts +0 -4
- package/dist/add-preset.js +0 -74
- package/dist/api/shared/async-symbol-detector.d.ts +0 -11
- package/dist/api/shared/async-symbol-detector.js +0 -140
- package/dist/api/shared/native-display-op-resolver.d.ts +0 -10
- package/dist/api/shared/native-display-op-resolver.js +0 -64
- package/dist/create/board-checklist.d.ts +0 -2
- package/dist/create/board-checklist.js +0 -52
- package/dist/create/board-codegen.d.ts +0 -9
- package/dist/create/board-codegen.js +0 -238
- package/dist/create/board-generators.d.ts +0 -12
- package/dist/create/board-generators.js +0 -651
- package/dist/create/board-spec.d.ts +0 -637
- package/dist/create/board-spec.js +0 -214
- package/dist/create/init-templates.d.ts +0 -28
- package/dist/create/init-wizard.d.ts +0 -8
- package/dist/create/init-wizard.js +0 -182
- package/dist/install/framework-catalog.d.ts +0 -53
- package/dist/install/framework-catalog.js +0 -107
- package/dist/install/handle-install.d.ts +0 -35
- package/dist/install/handle-install.js +0 -177
- package/dist/install/index.d.ts +0 -4
- package/dist/install/index.js +0 -3
- package/dist/ir/pin-state-tracking.d.ts +0 -58
- package/dist/ir/pin-state-tracking.js +0 -182
- package/dist/ir/pwm-timer-sharing.d.ts +0 -4
- package/dist/ir/pwm-timer-sharing.js +0 -94
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +0 -4
- package/dist/ir/timer0-pwm-timing-conflict.js +0 -72
- package/dist/libdef/component-decls.d.ts +0 -2
- package/dist/libdef/component-decls.js +0 -6
- package/dist/libdef/component-discovery.d.ts +0 -43
- package/dist/libdef/component-discovery.js +0 -83
- package/dist/theme-tokens.d.ts +0 -22
- package/dist/theme-tokens.js +0 -172
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Native C++ compilation toolchain
|
|
3
|
+
//
|
|
4
|
+
// Compiles generated C++ into a native executable using g++ or clang++.
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { parseCompileErrors, collectCppFiles } from '../../api/shared/index.js';
|
|
10
|
+
function findCppSource(outputDir, sourcePath) {
|
|
11
|
+
if (sourcePath.endsWith(".cpp") && fs.existsSync(sourcePath)) {
|
|
12
|
+
return sourcePath;
|
|
13
|
+
}
|
|
14
|
+
if (fs.existsSync(outputDir)) {
|
|
15
|
+
const entries = fs.readdirSync(outputDir);
|
|
16
|
+
const cppFile = entries.find((e) => e.endsWith(".cpp"));
|
|
17
|
+
if (cppFile)
|
|
18
|
+
return path.join(outputDir, cppFile);
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`No .cpp source file found in ${outputDir}`);
|
|
21
|
+
}
|
|
22
|
+
function detectCompiler() {
|
|
23
|
+
// On Windows, also try MSYS2/MinGW paths that may not be in PATH
|
|
24
|
+
const candidates = ["g++", "clang++"];
|
|
25
|
+
if (process.platform === "win32") {
|
|
26
|
+
candidates.unshift("C:\\msys64\\ucrt64\\bin\\g++.exe", "C:\\msys64\\mingw64\\bin\\g++.exe");
|
|
27
|
+
}
|
|
28
|
+
for (const cmd of candidates) {
|
|
29
|
+
try {
|
|
30
|
+
const r = spawnSync(cmd, ["--version"], {
|
|
31
|
+
encoding: "utf8",
|
|
32
|
+
timeout: 5000,
|
|
33
|
+
});
|
|
34
|
+
if (r.status === 0) {
|
|
35
|
+
// On Windows, ensure the compiler's bin dir is first in PATH
|
|
36
|
+
// so g++ can find its internal tools (as, ld, cc1plus, etc.)
|
|
37
|
+
let env;
|
|
38
|
+
if (process.platform === "win32" && cmd.includes("\\")) {
|
|
39
|
+
const binDir = path.dirname(cmd);
|
|
40
|
+
const pathSep = ";";
|
|
41
|
+
const existing = process.env.PATH ?? "";
|
|
42
|
+
env = { ...process.env, PATH: `${binDir}${pathSep}${existing}` };
|
|
43
|
+
}
|
|
44
|
+
return { cmd, env };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch { /* not found */ }
|
|
48
|
+
}
|
|
49
|
+
throw new Error("No C++ compiler found. Install g++ or clang++ and ensure it is in your PATH." +
|
|
50
|
+
(process.platform === "win32"
|
|
51
|
+
? " On Windows, install MSYS2 (https://www.msys2.org/) and add C:\\msys64\\ucrt64\\bin to your PATH."
|
|
52
|
+
: ""));
|
|
53
|
+
}
|
|
54
|
+
function warningFlags(level) {
|
|
55
|
+
switch (level) {
|
|
56
|
+
case "none": return ["-w"];
|
|
57
|
+
case "all": return ["-Wall"];
|
|
58
|
+
case "extra": return ["-Wall", "-Wextra"];
|
|
59
|
+
case "error": return ["-Wall", "-Wextra", "-Werror"];
|
|
60
|
+
default: return ["-Wall"];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the -l link libraries for a native build.
|
|
65
|
+
*
|
|
66
|
+
* The SDL display driver (#include <SDL2/SDL.h>) requires core SDL2 at link
|
|
67
|
+
* time on every platform; Windows/MSYS2 additionally needs -lmingw32 and
|
|
68
|
+
* -lSDL2main for the Win32 GUI entry-point glue (the SDL_MAIN_HANDLED define
|
|
69
|
+
* + SDL_SetMainReady() in display_init). Because the cuttlefish config loader
|
|
70
|
+
* is AST-only (it cannot evaluate process.platform conditionals), these libs
|
|
71
|
+
* are auto-provided here when the `sdl` display driver is active, so a single
|
|
72
|
+
* config links on both Windows and Linux without a platform-specific
|
|
73
|
+
* `native.libraries` array. User-supplied libraries are appended (deduped).
|
|
74
|
+
*/
|
|
75
|
+
export function resolveLinkLibraries(display, userLibs) {
|
|
76
|
+
const libs = [];
|
|
77
|
+
if (display?.driver === "sdl") {
|
|
78
|
+
if (process.platform === "win32") {
|
|
79
|
+
// mingw32 (WinMain CRT glue) → SDL2main (SDL_main) → SDL2 (core).
|
|
80
|
+
libs.push("mingw32", "SDL2main", "SDL2");
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
libs.push("SDL2");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const lib of userLibs) {
|
|
87
|
+
if (!libs.includes(lib))
|
|
88
|
+
libs.push(lib);
|
|
89
|
+
}
|
|
90
|
+
return libs;
|
|
91
|
+
}
|
|
92
|
+
export const NativeToolchain = {
|
|
93
|
+
compile(options) {
|
|
94
|
+
const nativeConfig = (options.frameworkConfig ?? {});
|
|
95
|
+
let cppFiles = collectCppFiles(options.outputDir);
|
|
96
|
+
if (cppFiles.length === 0) {
|
|
97
|
+
const fallback = findCppSource(options.outputDir, options.sourcePath);
|
|
98
|
+
cppFiles.push(fallback);
|
|
99
|
+
}
|
|
100
|
+
const exeExt = process.platform === "win32" ? ".exe" : ".out";
|
|
101
|
+
const exeFile = cppFiles[0].replace(/\.cpp$/, exeExt);
|
|
102
|
+
// Use configured compiler or auto-detect
|
|
103
|
+
const detected = detectCompiler();
|
|
104
|
+
const compiler = nativeConfig.compiler ?? detected.cmd;
|
|
105
|
+
const env = detected.env;
|
|
106
|
+
const flags = [];
|
|
107
|
+
// C++ standard
|
|
108
|
+
flags.push(`-std=${nativeConfig.cxxStandard ?? "c++17"}`);
|
|
109
|
+
// Optimization: always -O2. The old `output.optimize` config knob was
|
|
110
|
+
// removed from cuttlefish ("framework territory" — see config-loader's
|
|
111
|
+
// deprecation note); nothing can populate a ToolchainOptions.optimize, so
|
|
112
|
+
// these branches were dead code that never type-checked.
|
|
113
|
+
flags.push("-O2");
|
|
114
|
+
// Warning level
|
|
115
|
+
flags.push(...warningFlags(nativeConfig.warnings));
|
|
116
|
+
// Static linking (default: true on Windows, false elsewhere)
|
|
117
|
+
const staticLink = nativeConfig.staticLink ?? (process.platform === "win32");
|
|
118
|
+
if (staticLink)
|
|
119
|
+
flags.push("-static");
|
|
120
|
+
// Windows GUI subsystem: link as a windowed app, not a console app. Without
|
|
121
|
+
// -mwindows, MinGW produces a console-subsystem executable that spawns a
|
|
122
|
+
// cmd.exe window behind the SDL window on launch. This is the standard flag
|
|
123
|
+
// for any SDL/Win32 GUI program built with g++ on MSYS2/MinGW. No-op on
|
|
124
|
+
// Linux/macOS (no console-subsystem concept there).
|
|
125
|
+
if (process.platform === "win32")
|
|
126
|
+
flags.push("-mwindows");
|
|
127
|
+
// Include paths
|
|
128
|
+
if (nativeConfig.includePaths) {
|
|
129
|
+
for (const p of nativeConfig.includePaths)
|
|
130
|
+
flags.push(`-I${p}`);
|
|
131
|
+
}
|
|
132
|
+
// Library paths
|
|
133
|
+
if (nativeConfig.libraryPaths) {
|
|
134
|
+
for (const p of nativeConfig.libraryPaths)
|
|
135
|
+
flags.push(`-L${p}`);
|
|
136
|
+
}
|
|
137
|
+
// Generic extra flags and defines
|
|
138
|
+
if (options.extraFlags)
|
|
139
|
+
flags.push(...options.extraFlags);
|
|
140
|
+
if (options.defines) {
|
|
141
|
+
for (const [k, v] of Object.entries(options.defines)) {
|
|
142
|
+
flags.push(`-D${k}=${v}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Build args: flags + source + output, then -l flags last (GCC ordering).
|
|
146
|
+
// SDL2 link libs are auto-provided when the `sdl` display driver is active
|
|
147
|
+
// (see resolveLinkLibraries) — the AST config loader can't evaluate
|
|
148
|
+
// platform conditionals, so this keeps a single config portable across
|
|
149
|
+
// Windows/Linux/macOS. User-supplied native.libraries are merged in.
|
|
150
|
+
const linkLibs = resolveLinkLibraries(options.display, nativeConfig.libraries ?? []).map((lib) => `-l${lib}`);
|
|
151
|
+
const args = [...flags, ...cppFiles, "-o", exeFile, ...linkLibs];
|
|
152
|
+
const result = spawnSync(compiler, args, {
|
|
153
|
+
encoding: "utf8",
|
|
154
|
+
timeout: 120000,
|
|
155
|
+
env: env ?? process.env,
|
|
156
|
+
});
|
|
157
|
+
let output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`.trim();
|
|
158
|
+
if (result.status === 0) {
|
|
159
|
+
output = `${compiler} -> ${exeFile}`;
|
|
160
|
+
}
|
|
161
|
+
else if (result.error) {
|
|
162
|
+
output = `Compiler error: ${result.error.message}\n${output}`.trim();
|
|
163
|
+
}
|
|
164
|
+
else if (!output) {
|
|
165
|
+
output = `Compiler exited with code ${result.status} (no output). Command: ${compiler} ${args.join(" ")}`;
|
|
166
|
+
}
|
|
167
|
+
const errors = parseCompileErrors(output, options.outputDir);
|
|
168
|
+
return { success: result.status === 0, output, errors };
|
|
169
|
+
},
|
|
170
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native C++ compilation configuration.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* // TypeCAD.config.ts
|
|
7
|
+
* const config: TypeCADConfig = {
|
|
8
|
+
* framework: '@typecad/framework-native',
|
|
9
|
+
* native: {
|
|
10
|
+
* compiler: 'clang++',
|
|
11
|
+
* cxxStandard: 'c++20',
|
|
12
|
+
* warnings: 'extra',
|
|
13
|
+
* includePaths: ['./vendor/include'],
|
|
14
|
+
* libraries: ['curl'],
|
|
15
|
+
* },
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface NativeCompileConfig {
|
|
20
|
+
/** Override auto-detected compiler (e.g. 'clang++', 'g++-12'). */
|
|
21
|
+
compiler?: string;
|
|
22
|
+
/** C++ standard (e.g. 'c++17', 'c++20'). Default: 'c++17'. */
|
|
23
|
+
cxxStandard?: string;
|
|
24
|
+
/** Additional include directories (-I flags). */
|
|
25
|
+
includePaths?: string[];
|
|
26
|
+
/** Library search directories (-L flags). */
|
|
27
|
+
libraryPaths?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Libraries to link (-l flags, without the 'lib' prefix).
|
|
30
|
+
*
|
|
31
|
+
* Note: when the `sdl` display driver is active, SDL2 link libraries are
|
|
32
|
+
* auto-provided per platform by NativeToolchain (-lmingw32 -lSDL2main -lSDL2
|
|
33
|
+
* on Windows, -lSDL2 elsewhere); this field is for additional user libraries
|
|
34
|
+
* and is appended (deduped) after the auto-provided set.
|
|
35
|
+
*/
|
|
36
|
+
libraries?: string[];
|
|
37
|
+
/** Warning level: 'none', 'basic', 'all', 'extra', 'error'. Default: 'basic'. */
|
|
38
|
+
warnings?: string;
|
|
39
|
+
/** Static linking toggle. Default: true on Windows, false elsewhere. */
|
|
40
|
+
staticLink?: boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Native C++ compilation configuration
|
|
3
|
+
//
|
|
4
|
+
// Place under the `native` key in TypeCAD.config.ts to customize
|
|
5
|
+
// how g++/clang++ compiles your generated C++ code.
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { PlatformStrategy, ProgramIR, Diagnostic, PlatformContext, RuntimePolyfillIR, StdLibSupport, AsyncRuntimeConfig, GraphicsCapacity, DisplayHALOp } from '../../api/shared/index.js';
|
|
2
|
+
export declare class NativeStrategy implements PlatformStrategy {
|
|
3
|
+
readonly id = "native";
|
|
4
|
+
forcedIncludes(program: ProgramIR, ctx?: PlatformContext): string[];
|
|
5
|
+
symbolAliases(): Record<string, string>;
|
|
6
|
+
shimLines(program: ProgramIR, ctx?: PlatformContext): string[];
|
|
7
|
+
profileDiagnostics(): Diagnostic[];
|
|
8
|
+
sourceExtension(): string;
|
|
9
|
+
entrypointFunctionName(): string;
|
|
10
|
+
requiresLoopFunction(): boolean;
|
|
11
|
+
overrideBaseName(originalBaseName: string): string;
|
|
12
|
+
effectiveEmitMode(requestedMode: string): string;
|
|
13
|
+
normalizeCppType(typeName: string): string;
|
|
14
|
+
defaultNumericType(compliance?: {
|
|
15
|
+
isBanned(ruleId: string): boolean;
|
|
16
|
+
}): string;
|
|
17
|
+
mapReturnType(functionName: string, returnType: string): string;
|
|
18
|
+
isStringLikeType(cppType: string): boolean;
|
|
19
|
+
isPointerType(cppType: string): boolean;
|
|
20
|
+
mapFunctionName(originalName: string): string;
|
|
21
|
+
normalizeRawExpression(value: string): string;
|
|
22
|
+
nullValue(): string;
|
|
23
|
+
wrapStringConcat(): string | undefined;
|
|
24
|
+
wrapStringObject(value: string): string;
|
|
25
|
+
useSnprintfForStrings(): boolean;
|
|
26
|
+
promoteDivisionToDouble(): boolean;
|
|
27
|
+
renameEnumMember(_enumName: string, memberName: string): string;
|
|
28
|
+
private _largeEnumNames;
|
|
29
|
+
setLargeEnumNames(names: ReadonlySet<string>): void;
|
|
30
|
+
enumCastType(enumName: string): string | undefined;
|
|
31
|
+
renderBoardDefinitionAccess(): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Native lowers array literals to std::vector (not __tc_StaticArray), so the
|
|
34
|
+
* structural array-method lowering must use the std::vector/__tc_* helper form
|
|
35
|
+
* (.push_back, __tc_pop) rather than the StaticArray wrapper's .push/.pop.
|
|
36
|
+
* Embedded/generic targets promote literals to StaticArray and default to true.
|
|
37
|
+
*/
|
|
38
|
+
promotesArrayLiteralsToStaticArray(): boolean;
|
|
39
|
+
renderThrow(valueExpr: string): string;
|
|
40
|
+
objectFieldInitializer(): string | undefined;
|
|
41
|
+
overrideClassFieldType(_fieldName: string, normalizedType: string): string;
|
|
42
|
+
reservedNames(): ReadonlySet<string>;
|
|
43
|
+
passthroughMacroNames(): ReadonlySet<string>;
|
|
44
|
+
apiReservedEnumNames(): ReadonlySet<string>;
|
|
45
|
+
apiReservedEnumGuard(): string;
|
|
46
|
+
ambientTypeDeclarations(): string[];
|
|
47
|
+
needsIostream(): boolean;
|
|
48
|
+
needsStdString(): boolean;
|
|
49
|
+
needsStdVector(): boolean;
|
|
50
|
+
needsStdExcept(): boolean;
|
|
51
|
+
needsStdFunction(): boolean;
|
|
52
|
+
mathHeader(): string;
|
|
53
|
+
cstringHeader(): string;
|
|
54
|
+
needsLargeEnumUnderlying(): boolean;
|
|
55
|
+
renameStructField(fieldName: string): string;
|
|
56
|
+
structFieldInitializer(): string | undefined;
|
|
57
|
+
getAsyncRuntimeConfig(): AsyncRuntimeConfig;
|
|
58
|
+
asyncLoopInjection(taskVarNames: string[], config: AsyncRuntimeConfig): string[];
|
|
59
|
+
asyncLoopInjection(taskVarNames: string[], hasPromiseRuntime: boolean, hasTimers: boolean): string[];
|
|
60
|
+
asyncDriverFunctionName(): string;
|
|
61
|
+
shouldSkipTypeAlias(): boolean;
|
|
62
|
+
emitDiagnostics(): Diagnostic[];
|
|
63
|
+
currentTimeMillis(): string;
|
|
64
|
+
asyncQueueCapacity(): number;
|
|
65
|
+
outputSubdirectory(_baseName: string): string;
|
|
66
|
+
generateHeaderFile(): boolean;
|
|
67
|
+
enumApiGuard(_enumName: string): {
|
|
68
|
+
open: string;
|
|
69
|
+
close: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
getStdLibSupport(_architecture?: string): StdLibSupport;
|
|
72
|
+
nativePolyfills(): Set<string>;
|
|
73
|
+
generateNativePolyfills(program?: ProgramIR): RuntimePolyfillIR[];
|
|
74
|
+
resolveDisplayOp(op: DisplayHALOp): {
|
|
75
|
+
code?: string;
|
|
76
|
+
expression?: string;
|
|
77
|
+
} | undefined;
|
|
78
|
+
hostEventLoop(): {
|
|
79
|
+
flagName: string;
|
|
80
|
+
continueCondition: string;
|
|
81
|
+
preIteration: string;
|
|
82
|
+
postIteration: string;
|
|
83
|
+
};
|
|
84
|
+
supportedDisplayDrivers(): ReadonlySet<string>;
|
|
85
|
+
modelsGpio(): boolean;
|
|
86
|
+
readDigitalPin(_pin: string): string;
|
|
87
|
+
readAnalogPin(_pin: string): string;
|
|
88
|
+
writeDigitalPin(_pin: string, _val: string): string;
|
|
89
|
+
setPinMode(_pin: string, _mode: string): string;
|
|
90
|
+
delayMs(_ms: string): string;
|
|
91
|
+
delayMicroseconds(_us: string): string;
|
|
92
|
+
halCallNames(): ReadonlySet<string>;
|
|
93
|
+
isHalCall(_name: string): boolean;
|
|
94
|
+
analogReadCallNames(): ReadonlySet<string>;
|
|
95
|
+
colorFormat(): "rgb565" | "rgb666" | "rgb888" | "mono";
|
|
96
|
+
graphicsCapacity(): GraphicsCapacity;
|
|
97
|
+
}
|