/// /** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . **/ import { Program } from '@fadroma/agent'; import * as OCI from '@fadroma/oci'; import { Config } from '@hackbg/conf'; import { Path, SyncFS } from '@hackbg/file'; import { spawn } from 'node:child_process'; export declare const Compiler: typeof Program.Compiler; export declare function getCompiler({ config, useContainer, ...options }?: ({ useContainer?: false; } & Partial) | ({ useContainer: true; } & Partial)): Program.Compiler; /** The parts of Cargo.toml which the compiler needs to be aware of. */ export type CargoTOML = { package: { name: string; }; dependencies: Record; }; /** @returns an codePath filename name in the format CRATE@REF.wasm */ export declare const codePathName: (crate: string, ref: string) => string; /** @returns a filename-friendly version of a Git ref */ export declare const sanitize: (ref: string) => string; /** @returns an array with duplicate elements removed */ export declare const distinct: (x: T[]) => T[]; /** A compiler that can take configuration values from the environment. */ export declare abstract class ConfiguredCompiler extends Compiler { config: Config; constructor(options?: Partial<{ config: Config; }>); } type SourcePath = string; type SourceRef = string; type CompileBatches = Record>; type CompileBatch = { sourcePath: string; sourceRef: string; tasks: Set; }; type CompileTask = CompileCrateTask | CompileWorkspaceTask; type CompileCrateTask = { buildIndex: number; cargoToml: string; cargoCrate: string; }; type CompileWorkspaceTask = { cargoWorkspace: string; cargoCrates: Array; }; type CompileWorkspaceCrateTask = { buildIndex: number; cargoCrate: string; }; /** Can compile Rust smart contracts. * Will only perform a build if a contract is not built yet or FADROMA_REBUILD=1 is set. */ export declare abstract class LocalRustCompiler extends ConfiguredCompiler { readonly id: string; /** Whether the build process should print more detail to the console. */ verbose: boolean; /** Whether the build log should be printed only on error, or always */ quiet: boolean; /** The build script. */ script?: string; /** Whether to skip any `git fetch` calls in the build script. */ noFetch: boolean; /** Name of directory where build artifacts are collected. */ outputDir: SyncFS.Directory; /** Version of Rust toolchain to use. */ toolchain: string | null; /** Default Git reference from which to build sources. */ revision: string; /** Owner uid that is set on build artifacts. */ buildUid?: number; /** Owner gid that is set on build artifacts. */ buildGid?: number; /** Whether to enable caching and reuse contracts from artifacts directory. */ caching: boolean; constructor(options?: Partial); /** @returns a fully populated RustSourceCode from the original. */ protected resolveSource(source: string | Partial): Partial; /** Compile a single contract. */ build(contract: string | Partial): Promise; /** This implementation groups the passed source by workspace and ref, * in order to launch one build container per workspace/ref combination * and have it build all the crates from that combination in sequence, * reusing the container's internal intermediate build cache. */ buildMany(contracts: (string | (Partial))[]): Promise; protected collectBatches(contracts: Array>): CompileBatches; /** Check if codePath exists in local artifacts cache directory. * If it does, don't rebuild it but return it from there. */ protected tryGetCached(outputDir: string, { sourceRef, cargoCrate }: Partial): Program.CompiledCode | null; protected populateBatchResults({ outputDir, sourceRef, tasks, }: { outputDir: string; sourceRef: string; tasks: Set; }): Promise>; protected abstract buildBatch(batch: CompileBatch): Promise>; protected logStart(sourcePath: string, sourceRef: string, tasks: Set): void; } /** Runs the build script in the current envionment. */ export declare class RawLocalRustCompiler extends LocalRustCompiler { /** Node.js runtime that runs the build subprocess. * Defaults to the same one that is running this script. */ runtime: string; protected buildBatch(batch: CompileBatch, options?: { outputDir?: string; buildScript?: string | Path; }): Promise>; /** Overridable for testing. */ protected spawn(...args: Parameters): import("child_process").ChildProcess; } /** Runs the build script in a container. */ export declare class ContainerizedLocalRustCompiler extends LocalRustCompiler { /** Used to launch build container. */ engine: OCI.Connection; /** Path to Docker API endpoint. */ engineSocket: string; /** Tag of the docker image for the build container. */ buildImage: OCI.Image; /** Docker image to use for dockerized builds. */ buildImageTag: string; /** Path to the dockerfile for the build container if missing. */ buildImageManifest: string; /** Owner uid that is set on build artifacts. */ outputUid: string | undefined; /** Owner gid that is set on build artifacts. */ outputGid: string | undefined; constructor(options?: Partial); get [Symbol.toStringTag](): string; protected buildBatch({ sourcePath, sourceRef, tasks }: CompileBatch, { outputDir, buildScript }?: { outputDir?: string; buildScript?: string | Path; }): Promise>; protected getLogStream(revision: string, cb: (data: string) => void): OCI.LineTransformStream; } export default function main(...args: any): void; export {}; //# sourceMappingURL=compile.d.ts.map