Skip to content

Proposal: Add -buildmode parameter support #1197

@cpunion

Description

@cpunion

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions