How lmittmann/go-solc works
Project type and purpose
• This is a Go library/CLI‐style tool (“go-solc”) that provides Go bindings around the Solidity compiler.
• Purpose: fetch a specified Solidity compiler version from the official binaries site, cache it locally, and invoke it with configured arguments via a Go API.
File structure
• Top level:
• compiler.go / console.go / download.go / options.go / params.go / types.go — public API surfaces and orchestrators
• params_*.go + params_gen.go — OS/arch–specific compiler parameter definitions
• internal/console — arguments templating and process spawning
• internal/mod — module/root selection (resolving solc root directory)
• internal/version — version management logic
• examples/ — sample usage and tests
• testdata/ — integration‐style test inputs
• Configuration & metadata: go.mod, CI (/.github/workflows/go.yml), tests alongside each module.
README for additional insights
• Describes automatic download of solc binary from https://binaries.soliditylang.org
• Caching location: .solc/bin/solc_vX.Y.Z
• API usage: solc.New(...).Compile(...) with optional optimizer settings
• Emphasis on pre-1.0, API may change
Main components
a. API Layer
• Public API (compiler.go, console.go, options.go, types.go)
• Exposes New(), Compile(), WithOptimizer(), etc.
b. Version Manager (internal/version)
• Determines requested version, validates, formats version tag
c. Download Manager (download.go)
• Contacts external Solidity binaries endpoint
• Downloads the .tar.gz or binary, unpacks it into cache
d. Local Cache
• Filesystem directory (.solc/bin/)
• Stores versioned solc executables
e. Module Resolver (internal/mod)
• Determines which cache root or external fallback to use
f. Parameter Provider (params_*.go + params_gen.go)
• Supplies OS-arch specific compiler parameters (paths, exec names)
g. Console/Process Runner (internal/console)
• Renders argument templates (args.go.tmpl)
• Spawns child process, captures stdout/stderr
h. External Service
• Solidity compiler binary repository (binaries.soliditylang.org)
Relationships and data flows
• User Code → calls Public API →
• API invokes Version Manager → resolves version
• API calls Module Resolver → locates cache path
• If binary not present, API invokes Download Manager → External Service → caches to Local Cache
• Parameter Provider → supplies exec path & flags
• API triggers Console/Process Runner → launches solc → compiler output → returned to caller
Architectural patterns & design principles
• Modular layering: each responsibility in its own package (single responsibility)
• Dependency inversion: public API depends on interfaces implemented by internal modules
• Caching layer: avoids redundant downloads
• Template‐driven argument construction for flexibility
• OS/arch abstraction via generated params files
Putting it all together
• “Parameter Provider” feeds flags to “Console/Process Runner”
• “Console/Process Runner” executes binary from cache → returns output to API → back to User Code