Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 71 lines 2.28 KB
Raw
1 #!/usr/bin/env bun
2
3 /**
4 * Cross-compile a CLI binary for a specific Bun target.
5 *
6 * Usage: `bun scripts/build-binary-cross.ts --target <target>`
7 *
8 * Valid targets are the `bunTarget` values of `RELEASE_TARGETS`.
9 *
10 * Output: `dist/binaries/<artifact-name>` (`.exe` on Windows)
11 */
12
13 import process from 'node:process';
14 import { Config, ConfigProvider, Console, Effect, Logger, Layer, References } from 'effect';
15 import * as BunServices from '@effect/platform-bun/BunServices';
16 import * as BunRuntime from '@effect/platform-bun/BunRuntime';
17 import { buildCompanionModules, compileBinary, teardown } from './_shared';
18 import { RELEASE_TARGETS, type ReleaseTarget } from './_release-artifacts';
19
20 function parseTarget(): ReleaseTarget {
21 const targetIdx = process.argv.indexOf('--target');
22 const requested = targetIdx === -1 ? undefined : process.argv[targetIdx + 1];
23 const target = RELEASE_TARGETS.find(({ bunTarget }) => bunTarget === requested);
24 if (!target) {
25 process.stderr.write(
26 requested
27 ? `Invalid target: ${requested}\n`
28 : `Usage: bun scripts/build-binary-cross.ts --target <target>\n`
29 );
30 process.stderr.write(
31 `Valid targets: ${RELEASE_TARGETS.map(({ bunTarget }) => bunTarget).join(', ')}\n`
32 );
33 process.exit(1);
34 }
35 return target;
36 }
37
38 export function buildBinaryCross() {
39 const target = parseTarget();
40
41 return Effect.gen(function* () {
42 yield* Effect.logDebug(
43 `Cross-compiling binary in ${process.cwd()} for target ${target.bunTarget}`
44 );
45
46 const outfile = yield* compileBinary(target);
47
48 yield* buildCompanionModules('./dist/binaries/companions');
49
50 yield* Console.log(`Binary cross-compiled: ${outfile}`);
51 });
52 }
53
54 const ConfigLive = Effect.gen(function* () {
55 const logLevel = yield* Config.LogLevel('COMPOSIO_LOG_LEVEL').pipe(Config.withDefault('Info'));
56
57 return Layer.succeed(References.MinimumLogLevel, logLevel);
58 }).pipe(Layer.unwrap, Layer.merge(ConfigProvider.layer(ConfigProvider.fromEnv())));
59
60 if (require.main === module) {
61 buildBinaryCross().pipe(
62 Effect.provide(ConfigLive),
63 Effect.provide(Logger.layer([Logger.consolePretty()])),
64 Effect.provide(BunServices.layer),
65 Effect.scoped,
66 Effect.map(() => ({ message: 'Process completed successfully.' })),
67 BunRuntime.runMain({
68 teardown,
69 })
70 );
71 }