Background
The Go compiler supports multiple build modes via the -buildmode parameter. Currently, llgo only supports building standard executables. This proposal adds support for library generation modes needed for issue #1194.
Proposed Build Modes
Support only the essential modes:
exe - Standard executable (default, already supported)
c-archive - C archive file (.a + .h header)
c-shared - C shared library (.so/.dll/.dylib)
Implementation
1. Command Line Interface
llgo build [-buildmode mode] [-o output] [packages]
2. Code Changes
- Add
BuildMode flag to cmd/internal/flags/flags.go
- Extend
Config struct in internal/build/build.go
- Modify linker arguments based on build mode
- Generate C headers for
c-archive and c-shared modes
Use Case for Issue #1194
The c-archive mode will generate:
- Static library (.a file) containing Go code
- C header file (.h) with exported function declarations
This enables Go code to be compiled as libraries for target platforms rather than executables, which is required by issue #1194.
Background
The Go compiler supports multiple build modes via the
-buildmodeparameter. Currently, llgo only supports building standard executables. This proposal adds support for library generation modes needed for issue #1194.Proposed Build Modes
Support only the essential modes:
exe- Standard executable (default, already supported)c-archive- C archive file (.a + .h header)c-shared- C shared library (.so/.dll/.dylib)Implementation
1. Command Line Interface
2. Code Changes
BuildModeflag tocmd/internal/flags/flags.goConfigstruct ininternal/build/build.goc-archiveandc-sharedmodesUse Case for Issue #1194
The
c-archivemode will generate:This enables Go code to be compiled as libraries for target platforms rather than executables, which is required by issue #1194.