Documentation
¶
Overview ¶
Package builders provides sandboxed compilation for multiple programming languages.
Each language is implemented as a separate subpackage that registers itself via Register during init(). To use a builder, import its package for side effects:
import _ "github.com/Highload-fun/builders/golang"
Then call GetVersions and Build with the builder's ID.
Index ¶
- Constants
- func Build(ctx context.Context, builderId, version string, flags []string, ...) error
- func Check(t *testing.T, builderId string, sources fs.FS)
- func CheckBuilding(t *testing.T, description, builderId, version string, flags []string, ...)
- func DownloadAndExtractArchive(ctx context.Context, archiveUrl, dstDir string) error
- func GetBuildersIds() []string
- func HttpGet(ctx context.Context, url string) (*http.Response, error)
- func Register(id string, builder Builder)
- type Builder
- type FakeCloser
- type Version
Constants ¶
const ( // CompilersHostDir is the host directory where downloaded compiler toolchains are cached. CompilersHostDir = "/tmp" // SourceDir is the path where user source code is mounted inside the sandbox. SourceDir = "/src" // OutDir is the path where the compiled binary is written inside the sandbox. OutDir = "/out" )
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build(ctx context.Context, builderId, version string, flags []string, srcDir, outDir string) error
Build compiles the source code in srcDir using the specified builder and version, writing the resulting binary to outDir. It creates an isolated sandbox with a 5 GB memory limit and network disabled. If version is empty, the builder's default is used.
func Check ¶
Check is a test helper that validates a builder's version listing and default-version build. It first asserts that GetVersions returns a non-empty list of valid versions, then delegates to CheckBuilding with an empty version to exercise the default.
func CheckBuilding ¶
func CheckBuilding(t *testing.T, description, builderId, version string, flags []string, sources fs.FS)
CheckBuilding is a test helper that compiles sources with the given builder and version, then verifies the resulting binary can execute inside a sandbox.
func DownloadAndExtractArchive ¶
DownloadAndExtractArchive fetches a tar archive from archiveUrl and extracts it into dstDir. Supported formats are .tar.gz, .tar.bz2, and .tar.xz.
func GetBuildersIds ¶
func GetBuildersIds() []string
GetBuildersIds returns the sorted IDs of all registered builders.
Types ¶
type Builder ¶
type Builder interface {
// GetVersions returns the available compiler versions for this language.
GetVersions(ctx context.Context) ([]Version, error)
// Build compiles source code inside the given sandbox, producing a "main" binary in [OutDir].
Build(ctx context.Context, sb *sandbox.Sandbox, version string, flags []string) error
}
Builder is the interface that each language compiler must implement.
type FakeCloser ¶
FakeCloser wraps an io.Reader with a no-op Close method to satisfy io.ReadCloser.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cpp provides a C++ builder that uses system-installed g++ and clang++ compilers.
|
Package cpp provides a C++ builder that uses system-installed g++ and clang++ compilers. |
|
Package csharp provides a C# builder that downloads .NET SDK toolchains from Microsoft.
|
Package csharp provides a C# builder that downloads .NET SDK toolchains from Microsoft. |
|
Package golang provides a Go builder that downloads toolchains from go.dev.
|
Package golang provides a Go builder that downloads toolchains from go.dev. |
|
test/md5
command
|
|
|
test/src
command
|
|
|
Package rust provides a Rust builder that downloads rustc toolchains from static.rust-lang.org.
|
Package rust provides a Rust builder that downloads rustc toolchains from static.rust-lang.org. |
|
Package zig provides a Zig builder that downloads toolchains from ziglang.org.
|
Package zig provides a Zig builder that downloads toolchains from ziglang.org. |