@tsplc/tmp-compiler 0.0.0-stage → 0.6.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.
Files changed (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/dist/cli.js +2325 -0
  4. package/dist/cli.js.map +26 -0
  5. package/dist/clock.js +11 -0
  6. package/dist/clock.js.map +11 -0
  7. package/dist/codesys.js +6558 -0
  8. package/dist/codesys.js.map +51 -0
  9. package/dist/collections.js +399 -0
  10. package/dist/collections.js.map +10 -0
  11. package/dist/index.js +16076 -0
  12. package/dist/index.js.map +61 -0
  13. package/dist/ir.js +3948 -0
  14. package/dist/ir.js.map +35 -0
  15. package/dist/retain.js +10 -0
  16. package/dist/retain.js.map +10 -0
  17. package/dist/signals.js +115 -0
  18. package/dist/signals.js.map +10 -0
  19. package/dist/telemetry.js +121 -0
  20. package/dist/telemetry.js.map +12 -0
  21. package/package.json +122 -4
  22. package/src/codesys/config.ts +50 -0
  23. package/src/codesys/debug.ts +655 -0
  24. package/src/codesys/emit.ts +185 -0
  25. package/src/codesys/endpoints.ts +111 -0
  26. package/src/codesys/engineering.ts +96 -0
  27. package/src/codesys/explain/expressions.ts +445 -0
  28. package/src/codesys/explain/flags.ts +134 -0
  29. package/src/codesys/explain/parameters.ts +53 -0
  30. package/src/codesys/explain/rows.ts +182 -0
  31. package/src/codesys/explain/tables.ts +79 -0
  32. package/src/codesys/explain/tasks.ts +68 -0
  33. package/src/codesys/explain/writes.ts +497 -0
  34. package/src/codesys/explain.ts +149 -0
  35. package/src/codesys/expressions.ts +100 -0
  36. package/src/codesys/global-lists.ts +284 -0
  37. package/src/codesys/global-names.ts +66 -0
  38. package/src/codesys/http.ts +1078 -0
  39. package/src/codesys/index.ts +13 -0
  40. package/src/codesys/instrumentation.ts +574 -0
  41. package/src/codesys/io-paths.ts +149 -0
  42. package/src/codesys/loops.ts +101 -0
  43. package/src/codesys/manifest.ts +684 -0
  44. package/src/codesys/names.ts +58 -0
  45. package/src/codesys/numeric.ts +516 -0
  46. package/src/codesys/plan.ts +688 -0
  47. package/src/codesys/programs.ts +138 -0
  48. package/src/codesys/publication.ts +99 -0
  49. package/src/codesys/required.ts +8 -0
  50. package/src/codesys/routines.ts +247 -0
  51. package/src/codesys/scan-clock.ts +103 -0
  52. package/src/codesys/scheduling.ts +96 -0
  53. package/src/codesys/service-channels.ts +24 -0
  54. package/src/codesys/sources.ts +118 -0
  55. package/src/codesys/st-files.ts +219 -0
  56. package/src/codesys/statements.ts +409 -0
  57. package/src/codesys/storage.ts +150 -0
  58. package/src/codesys/symbols.ts +240 -0
  59. package/src/codesys/task-access.ts +186 -0
  60. package/src/codesys/telemetry-settings.ts +19 -0
  61. package/src/codesys/telemetry.ts +852 -0
  62. package/src/codesys/types.ts +310 -0
  63. package/src/codesys/vendor.ts +113 -0
  64. package/src/frontend/analyzer.ts +779 -0
  65. package/src/frontend/async.ts +530 -0
  66. package/src/frontend/blocks.ts +578 -0
  67. package/src/frontend/configuration.ts +83 -0
  68. package/src/frontend/const-functions.ts +204 -0
  69. package/src/frontend/control-flow.ts +787 -0
  70. package/src/frontend/cooperative.ts +114 -0
  71. package/src/frontend/coroutines.ts +1336 -0
  72. package/src/frontend/dialect-names.ts +104 -0
  73. package/src/frontend/elaborate/array-searches.ts +224 -0
  74. package/src/frontend/elaborate/assignments.ts +343 -0
  75. package/src/frontend/elaborate/calls.ts +1342 -0
  76. package/src/frontend/elaborate/capture-protocol.ts +237 -0
  77. package/src/frontend/elaborate/capture.ts +388 -0
  78. package/src/frontend/elaborate/declarations.ts +124 -0
  79. package/src/frontend/elaborate/dialect.ts +473 -0
  80. package/src/frontend/elaborate/expressions.ts +2171 -0
  81. package/src/frontend/elaborate/filtered-arrays.ts +643 -0
  82. package/src/frontend/elaborate/frame.ts +145 -0
  83. package/src/frontend/elaborate/generics.ts +123 -0
  84. package/src/frontend/elaborate/graph.ts +141 -0
  85. package/src/frontend/elaborate/imports.ts +105 -0
  86. package/src/frontend/elaborate/index.ts +851 -0
  87. package/src/frontend/elaborate/initializers.ts +235 -0
  88. package/src/frontend/elaborate/iterators.ts +1541 -0
  89. package/src/frontend/elaborate/layouts.ts +1025 -0
  90. package/src/frontend/elaborate/model.ts +478 -0
  91. package/src/frontend/elaborate/names.ts +134 -0
  92. package/src/frontend/elaborate/reduce.ts +900 -0
  93. package/src/frontend/elaborate/references.ts +727 -0
  94. package/src/frontend/elaborate/retention.ts +284 -0
  95. package/src/frontend/elaborate/specialize.ts +1137 -0
  96. package/src/frontend/elaborate/statements.ts +1220 -0
  97. package/src/frontend/elaborate/storage.ts +836 -0
  98. package/src/frontend/elaborate/time-constructors.ts +34 -0
  99. package/src/frontend/elaborate/values.ts +200 -0
  100. package/src/frontend/elaborate/writes.ts +415 -0
  101. package/src/frontend/expressions.ts +1382 -0
  102. package/src/frontend/generated-names.ts +95 -0
  103. package/src/frontend/intrinsics.ts +382 -0
  104. package/src/frontend/lowering-key.ts +23 -0
  105. package/src/frontend/module-graph.ts +156 -0
  106. package/src/frontend/positions.ts +359 -0
  107. package/src/frontend/promise-chains.ts +872 -0
  108. package/src/frontend/promises.ts +419 -0
  109. package/src/frontend/routines.ts +239 -0
  110. package/src/frontend/sdk.ts +187 -0
  111. package/src/frontend/services.ts +609 -0
  112. package/src/frontend/statements.ts +871 -0
  113. package/src/frontend/tasks.ts +526 -0
  114. package/src/frontend/telemetry.ts +174 -0
  115. package/src/frontend/types.ts +1073 -0
  116. package/src/frontend/typescript.ts +651 -0
  117. package/src/index.ts +9 -0
  118. package/src/ir/aggregates.ts +291 -0
  119. package/src/ir/allocation.ts +96 -0
  120. package/src/ir/conditions.ts +855 -0
  121. package/src/ir/core-model.ts +289 -0
  122. package/src/ir/declarations.ts +281 -0
  123. package/src/ir/diagnostics.ts +68 -0
  124. package/src/ir/domains.ts +151 -0
  125. package/src/ir/fold.ts +279 -0
  126. package/src/ir/identity.ts +19 -0
  127. package/src/ir/index.ts +137 -0
  128. package/src/ir/job-errors.ts +69 -0
  129. package/src/ir/layouts.ts +211 -0
  130. package/src/ir/link.ts +302 -0
  131. package/src/ir/model.ts +394 -0
  132. package/src/ir/normalization-error.ts +10 -0
  133. package/src/ir/normalize.ts +52 -0
  134. package/src/ir/numeric.ts +163 -0
  135. package/src/ir/operands.ts +160 -0
  136. package/src/ir/ranges.ts +420 -0
  137. package/src/ir/routine.ts +1116 -0
  138. package/src/ir/scalars.ts +453 -0
  139. package/src/ir/share.ts +790 -0
  140. package/src/ir/short-circuit.ts +140 -0
  141. package/src/ir/tables.ts +111 -0
  142. package/src/ir/temporaries.ts +138 -0
  143. package/src/ir/types.ts +151 -0
  144. package/src/project/artifacts.ts +424 -0
  145. package/src/project/cli.ts +211 -0
  146. package/src/project/debugger.ts +111 -0
  147. package/src/project/deployments.ts +387 -0
  148. package/src/project/flags.ts +14 -0
  149. package/src/project/git.ts +35 -0
  150. package/src/project/plant.ts +629 -0
  151. package/src/project/project-commands.ts +507 -0
  152. package/src/project/project.ts +559 -0
  153. package/src/project/release.ts +152 -0
  154. package/src/project/server-check.ts +54 -0
  155. package/src/project/server.ts +165 -0
  156. package/src/project/terminal.ts +45 -0
  157. package/src/runtime/async.ts +207 -0
  158. package/src/runtime/launch.ts +59 -0
  159. package/src/runtime/main.ts +59 -0
  160. package/src/runtime/missing-file.ts +3 -0
  161. package/src/runtime/process.ts +177 -0
  162. package/src/runtime/program.ts +109 -0
  163. package/src/runtime/retain.ts +108 -0
  164. package/src/runtime/runtime.ts +324 -0
  165. package/src/runtime/settings.ts +27 -0
  166. package/src/runtime/storage.ts +456 -0
  167. package/src/runtime/symbols.ts +97 -0
  168. package/src/runtime/telemetry.ts +154 -0
  169. package/src/runtime/transport.ts +168 -0
  170. package/stdlib/clock.ts +8 -0
  171. package/stdlib/collections.ts +534 -0
  172. package/stdlib/plc-time.ts +2 -0
  173. package/stdlib/retain.ts +4 -0
  174. package/stdlib/signals.ts +142 -0
  175. package/stdlib/telemetry.ts +89 -0
  176. package/types/async.d.ts +87 -0
  177. package/types/clock.d.ts +8 -0
  178. package/types/config.d.ts +2 -0
  179. package/types/data-types.d.ts +31 -0
  180. package/types/dialect.d.ts +49 -0
  181. package/types/globals.d.ts +10 -0
  182. package/types/index.d.ts +212 -0
  183. package/types/retain.d.ts +12 -0
  184. package/types/telemetry.d.ts +47 -0
@@ -0,0 +1,185 @@
1
+ import { createHash } from "node:crypto";
2
+ import type {
3
+ EmitResult,
4
+ GeneratedObject,
5
+ SourceSpan,
6
+ } from "@tsplc/compiler/ir";
7
+ import { isBlockRoutine } from "@tsplc/compiler/ir";
8
+ import type { Publication } from "@tsplc/config";
9
+ import type { DebugManifest } from "@tsplc/debug/manifest";
10
+ import type { ServiceChannel } from "@tsplc/server/wire";
11
+ import { explainedWriters, explanations } from "./explain";
12
+ import { emitGlobalLists, emitIoList, type IoMapping } from "./global-lists";
13
+ import { emitServiceBlock, httpNetwork, serviceBlock } from "./http";
14
+ import {
15
+ emitDebugGlobal,
16
+ emitTelemetry,
17
+ planInstrumentation,
18
+ } from "./instrumentation";
19
+ import { debugManifest } from "./manifest";
20
+ import { type CodesysPlan, isPlanned } from "./plan";
21
+ import { emitScanProgram, emitTaskWrappers } from "./programs";
22
+ import { publishedSymbols } from "./publication";
23
+ import { emitRoutine } from "./routines";
24
+ import { emitScanClock } from "./scan-clock";
25
+ import { serviceChannelsFile } from "./service-channels";
26
+ import { Sources } from "./sources";
27
+ import { type ObjectMapping, type PlacedObject, stFiles } from "./st-files";
28
+ import {
29
+ allocateBlockMembers,
30
+ allocateFunctionNames,
31
+ allocateRoutineScope,
32
+ type CodesysSymbols,
33
+ type EmissionContext,
34
+ globalSymbols,
35
+ } from "./symbols";
36
+
37
+ export interface SourceMapping {
38
+ path: string;
39
+ line: number;
40
+ span: SourceSpan;
41
+ }
42
+
43
+ export type CodesysBundle = Omit<EmitResult, "objects"> & {
44
+ objects: PlacedObject[];
45
+ /** Variables a generated device tree maps to their bit or byte channels. */
46
+ ioMappings: readonly IoMapping[];
47
+ mappings: readonly SourceMapping[];
48
+ ioSymbols: Readonly<Record<string, string>>;
49
+ publication: Publication;
50
+ /** The debugger's view of this build; its id is also published as `build.target`. */
51
+ debug: DebugManifest;
52
+ /** `explain.json`'s text, whose digest `debug` records. */
53
+ explain: string;
54
+ };
55
+
56
+ /** The routines emitted as objects: every function, and every block CODESYS does not provide. */
57
+ const emittedRoutines = ({ core }: CodesysPlan) => [
58
+ ...core.functions,
59
+ ...core.blocks.filter((block) => !block.standard),
60
+ ];
61
+
62
+ /**
63
+ * Allocates every target name the emitters read, in the order that fixes them, with the objects
64
+ * emitted on the way: types, storage lists, the network, numeric helpers and telemetry. Each
65
+ * routine's scope reserves those objects' names, as an ST local must never shadow a helper,
66
+ * function, FB, or DUT that the implementation calls.
67
+ */
68
+ function emissionContext(plan: CodesysPlan) {
69
+ const { core } = plan;
70
+ const global = globalSymbols(plan);
71
+ const planned = planInstrumentation(plan, global);
72
+ const globalLists = emitGlobalLists(plan, global);
73
+ const ioList = emitIoList(plan, global, globalLists.references);
74
+ const network = httpNetwork(plan, global);
75
+ const objects: GeneratedObject[] = [
76
+ ...global.targetTypes.objects,
77
+ ...globalLists.objects,
78
+ ...ioList.objects,
79
+ ...(global.scanClock ? [emitScanClock(global.scanClock)] : []),
80
+ ...(network ? [network] : []),
81
+ ];
82
+
83
+ const routineNames = allocateFunctionNames(plan, global);
84
+ for (const routine of [...core.functions, ...core.blocks]) {
85
+ global.numeric.prepareStatements(routine.body);
86
+ }
87
+ objects.push(...global.numeric.objects);
88
+ const members = allocateBlockMembers(
89
+ plan,
90
+ { ...global, functionNames: routineNames },
91
+ planned,
92
+ objects,
93
+ );
94
+ const functionNames = new Map([...routineNames, ...members.methods]);
95
+ const instrumentation = { ...planned, fields: members.instrumented };
96
+
97
+ const telemetry = emitTelemetry(plan, global, instrumentation, network?.name);
98
+ objects.push(...telemetry.objects);
99
+ const scopes = new Map(
100
+ emittedRoutines(plan).map((fn) => [
101
+ fn.id,
102
+ allocateRoutineScope(
103
+ { ...global, functionNames, blockFields: members.fields },
104
+ objects,
105
+ instrumentation.global,
106
+ fn,
107
+ ),
108
+ ]),
109
+ );
110
+ const symbols: CodesysSymbols = {
111
+ ...global,
112
+ references: new Map([...globalLists.references, ...ioList.references]),
113
+ functionNames,
114
+ blockFields: members.fields,
115
+ mailboxLocks: members.mailboxLocks,
116
+ programResults: new Map(
117
+ [...scopes].flatMap(([id, { result }]) => (result ? [[id, result]] : [])),
118
+ ),
119
+ routineScopes: new Map([...scopes].map(([id, { scope }]) => [id, scope])),
120
+ };
121
+ const context: EmissionContext = { plan, symbols, instrumentation };
122
+ return {
123
+ context,
124
+ objects,
125
+ mappings: [...globalLists.mappings, ...ioList.mappings],
126
+ ioList,
127
+ network,
128
+ rpcChannels: telemetry.rpcChannels,
129
+ };
130
+ }
131
+
132
+ export function emitCodesys(plan: CodesysPlan): CodesysBundle {
133
+ if (!isPlanned(plan)) {
134
+ throw new Error("Emission requires a validated CODESYS plan.");
135
+ }
136
+ const { context, objects, mappings, ioList, network, rpcChannels } =
137
+ emissionContext(plan);
138
+ const channels: ServiceChannel[] = [...rpcChannels];
139
+ const lines: ObjectMapping[] = [...mappings];
140
+ for (const fn of emittedRoutines(plan)) {
141
+ if (isBlockRoutine(fn) && serviceBlock(fn)) {
142
+ const service = emitServiceBlock(context, network?.name, fn);
143
+ objects.push(...service.objects);
144
+ channels.push(...service.rpcChannels);
145
+ continue;
146
+ }
147
+ const routine = emitRoutine(context, fn);
148
+ objects.push(...routine.objects);
149
+ lines.push(...routine.mappings);
150
+ }
151
+ for (const program of plan.core.programs) {
152
+ objects.push(emitScanProgram(context, ioList.channels, program));
153
+ }
154
+ objects.push(...emitTaskWrappers(context, objects));
155
+ // Explanations index the manifest's sources and functions, and its digest of them feeds the build id.
156
+ const sources = new Sources(plan.project.root);
157
+ const { manifest, functionIds } = debugManifest(context, sources);
158
+ const explained = explanations(context, manifest, sources, functionIds);
159
+ const explain = JSON.stringify(explained.file);
160
+ const debug = emitDebugGlobal(plan, context.instrumentation, objects, {
161
+ ...manifest,
162
+ writers: explainedWriters(
163
+ manifest,
164
+ explained,
165
+ context.instrumentation.analysis.writers,
166
+ ),
167
+ explain: { sha256: createHash("sha256").update(explain).digest("hex") },
168
+ });
169
+ const placed = stFiles(context, objects, lines);
170
+
171
+ return {
172
+ artifacts: [...placed.artifacts, serviceChannelsFile(channels)],
173
+ objects: placed.objects,
174
+ mappings: placed.mappings,
175
+ ioSymbols: Object.fromEntries([
176
+ ...ioList.channels.map((channel) => [channel.key, channel.target]),
177
+ ...ioList.ioMappings.map((mapping) => [mapping.key, mapping.variable]),
178
+ ]),
179
+ ioMappings: ioList.ioMappings,
180
+ publication: publishedSymbols(context, channels),
181
+ debug,
182
+ explain,
183
+ diagnostics: [],
184
+ };
185
+ }
@@ -0,0 +1,111 @@
1
+ import { type Environment, type HttpOptions, secretValue } from "@tsplc/config";
2
+
3
+ /** Where a client sends its requests: a server over HTTP(S), or a route of the app server's OPC UA gateway. */
4
+ export type HttpEndpoint =
5
+ | {
6
+ transport: "http";
7
+ host: string;
8
+ port: number;
9
+ authority: string;
10
+ path: string;
11
+ token: string;
12
+ timeoutMs: number;
13
+ tls: boolean;
14
+ }
15
+ | { transport: "opcua"; path: string; timeoutMs: number };
16
+
17
+ export type NativeEndpoint = Extract<HttpEndpoint, { transport: "http" }>;
18
+
19
+ const invalidUrl = { error: "Invalid URL" };
20
+
21
+ /** Each configured credential's bearer token, by the exact origin it is sent to. */
22
+ export const resolveHttpCredentials = (
23
+ credentials: HttpOptions["credentials"],
24
+ environment: Environment,
25
+ ): { tokens: ReadonlyMap<string, string> } | { error: string } => {
26
+ const tokens = new Map<string, string>();
27
+ for (const credential of credentials) {
28
+ const configured = environment[credential.originEnv];
29
+ const secret = environment[credential.bearerTokenEnv];
30
+ if (!configured || !secret) {
31
+ return {
32
+ error: `HTTP credentials require ${credential.originEnv} and ${credential.bearerTokenEnv}.`,
33
+ };
34
+ }
35
+ const origin = URL.parse(configured);
36
+ if (!origin) {
37
+ return invalidUrl;
38
+ }
39
+ if (
40
+ !["http:", "https:"].includes(origin.protocol) ||
41
+ origin.username ||
42
+ origin.password ||
43
+ origin.pathname !== "/" ||
44
+ origin.search ||
45
+ origin.hash
46
+ ) {
47
+ return {
48
+ error: `HTTP credential origin ${credential.originEnv} must contain only a scheme, host and port.`,
49
+ };
50
+ }
51
+ if (tokens.has(origin.origin)) {
52
+ return { error: "HTTP credential origins must be unique." };
53
+ }
54
+ if (!secretValue.safeParse(secret).success) {
55
+ return { error: `Invalid bearer token in ${credential.bearerTokenEnv}.` };
56
+ }
57
+ tokens.set(origin.origin, secret);
58
+ }
59
+ return { tokens };
60
+ };
61
+
62
+ export const resolveHttpEndpoint = (
63
+ value: string,
64
+ input: HttpOptions,
65
+ environment: Environment,
66
+ ): NativeEndpoint | { error: string } => {
67
+ const url = URL.parse(value);
68
+ if (!url) {
69
+ return invalidUrl;
70
+ }
71
+ if (
72
+ !["http:", "https:"].includes(url.protocol) ||
73
+ url.username ||
74
+ url.password ||
75
+ url.hash ||
76
+ url.hostname.includes(":")
77
+ ) {
78
+ return {
79
+ error:
80
+ "fetch requires an HTTP(S) URL with an IPv4 address or DNS hostname, without credentials or fragment.",
81
+ };
82
+ }
83
+ const port = Number(url.port || (url.protocol === "https:" ? 443 : 80));
84
+ if (
85
+ (url.pathname + url.search).length > 2048 ||
86
+ url.hostname.length > 253 ||
87
+ port === 0
88
+ ) {
89
+ return {
90
+ error:
91
+ "HTTP URL exceeds the native host/path limits or has an invalid port.",
92
+ };
93
+ }
94
+ const credentials = resolveHttpCredentials(input.credentials, environment);
95
+ if ("error" in credentials) {
96
+ return credentials;
97
+ }
98
+ return {
99
+ transport: "http",
100
+ host: url.hostname,
101
+ port,
102
+ authority: url.host,
103
+ path: url.pathname + url.search,
104
+ token: credentials.tokens.get(url.origin) ?? "",
105
+ timeoutMs: input.timeoutMs,
106
+ tls: url.protocol === "https:",
107
+ };
108
+ };
109
+
110
+ /** A server base URL as routes such as the telemetry path are appended to it, by the PLC and the Bun runtime alike. */
111
+ export const routeBase = (baseUrl: string) => baseUrl.replace(/\/+$/, "");
@@ -0,0 +1,96 @@
1
+ import { resolve } from "node:path";
2
+ import {
3
+ compileStructuredText,
4
+ type InstalledLibrary,
5
+ type ProgressOptions,
6
+ } from "@tsplc/build";
7
+ import type { Controller, DeviceTree } from "@tsplc/config";
8
+ import { engineeringBuildSchema, resolveConfig } from "@tsplc/config/build";
9
+ import { z } from "zod";
10
+ import type { CodesysBundle } from "./emit";
11
+ import { httpLibraryReferences } from "./http";
12
+ import type { CodesysPlan } from "./plan";
13
+ import { taskPrograms } from "./programs";
14
+ import { required } from "./required";
15
+
16
+ export const engineeringSchema = z.strictObject({
17
+ kind: z.literal("v3.5"),
18
+ build: engineeringBuildSchema.optional(),
19
+ });
20
+ export type CodesysEngineeringBuild = z.input<typeof engineeringBuildSchema>;
21
+
22
+ export function codesysBuildConfig(
23
+ plan: CodesysPlan,
24
+ bundle: Pick<CodesysBundle, "objects">,
25
+ paths: {
26
+ configFile: string;
27
+ sourceDir: string;
28
+ outDir: string;
29
+ libraries?: InstalledLibrary[];
30
+ deviceTree?: DeviceTree;
31
+ controller?: Controller;
32
+ },
33
+ ) {
34
+ const settings = plan.options.engineering.build;
35
+ if (!settings) {
36
+ throw new Error(
37
+ 'Compiling with CODESYS needs a build section in the config, for example build: { outDir: "build/codesys" }. Add one, or emit the Structured Text only with build --emit-only.',
38
+ );
39
+ }
40
+ const [first] = plan.core.programs;
41
+ if (!first) {
42
+ throw new Error("CODESYS build requires a generated PROGRAM entry.");
43
+ }
44
+ const programs = new Map(
45
+ bundle.objects
46
+ .filter((object) => object.kind === "program")
47
+ .map((object) => [object.id, object]),
48
+ );
49
+ const programIds = new Map(
50
+ plan.core.programs.map((program) => [program.name, program.id]),
51
+ );
52
+ const programObject = (id: string) => required(programs.get(id));
53
+ const tasks = plan.deployment.tasks.map((task) => {
54
+ const { configured, wrapper } = taskPrograms(plan, task);
55
+ return {
56
+ ...task,
57
+ programs: [
58
+ ...configured.map(
59
+ (name) => programObject(required(programIds.get(name))).name,
60
+ ),
61
+ programObject(wrapper.id).name,
62
+ ],
63
+ };
64
+ });
65
+ const entry = programObject(first.id);
66
+ const sourceDir = resolve(paths.sourceDir);
67
+ return resolveConfig(
68
+ {
69
+ ...settings,
70
+ libraryReferences: [
71
+ ...settings.libraryReferences,
72
+ ...httpLibraryReferences(plan),
73
+ ],
74
+ ...(paths.libraries ? { libraries: paths.libraries } : {}),
75
+ ...(paths.deviceTree ? { deviceTree: paths.deviceTree } : {}),
76
+ ...(paths.controller ? { controller: paths.controller } : {}),
77
+ sourceDir,
78
+ entry: resolve(sourceDir, entry.sourcePath),
79
+ outDir: resolve(paths.outDir),
80
+ tasks,
81
+ },
82
+ paths.configFile,
83
+ );
84
+ }
85
+
86
+ export async function buildCodesys(
87
+ plan: CodesysPlan,
88
+ bundle: Pick<CodesysBundle, "objects">,
89
+ paths: Parameters<typeof codesysBuildConfig>[2],
90
+ options: ProgressOptions = {},
91
+ ) {
92
+ return compileStructuredText(
93
+ codesysBuildConfig(plan, bundle, paths),
94
+ options,
95
+ );
96
+ }