Proposal: Platform-Specific Project Layout and Output
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by reading the llcppg.cfg Dir rules and tracing how the CLI selects its source and destination directories. Then check how GOOS and GOARCH are obtained and where generated output is placed. Done means platform-prefixed inputs resolve to the expected platform directory, output is written under the matching destination subdirectory, and non-platform projects retain current behavior; the proposal leaves several design questions open.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
llcppg currently assumes that a C/C++ library looks the same on every platform: one include directory, one generated Go package. That assumption breaks down for libraries whose headers differ per operating system and architecture, with libc being the most important example. This proposal introduces a minimal platform-awareness framework for llcppg.cfg. libc is used throughout as the motivating example, but nothing in the design is specific to it.
The core ideas are:
- Each platform is fully independent and lives in its own
$GOOS-$GOARCHdirectory (for exampledarwin-arm64), following Go's own naming exactly. Dirinllcppg.cfggains a mandatory$GOOS-$GOARCH/prefix when the project is platform-specific.- When converting, llcppg automatically places output under
<dest-dir>/$GOOS-$GOARCH. Users never create the platform subdirectory themselves.
Motivation
libc is not one library. Each platform has a different maintainer and a different set of headers:
| Platform | libc provider |
|---|---|
| darwin | macOS SDK (libSystem) |
| linux | glibc, musl, or others |
| windows | UCRT / MSVCRT |
Their types, constants, and function sets differ (struct stat, errno values, O_* flags, sigaction, and so on). A single binding cannot describe all of them, and trying to merge them by hand defeats the purpose of automatic generation.
The sensible model is the one Go itself uses: treat each GOOS/GOARCH pair as its own world, generate a binding for each, and let tooling pick the right one later. This proposal only covers the first part: generating and organizing the per-platform bindings.
Project Layout
A platform-specific llcppg project looks like this:
<a-llcppg-project>/
go.mod
go.sum
llcppg.cfg
darwin-arm64/
include/
<headers of the library for darwin/arm64>
linux-amd64/
include/
<headers of the library for linux/amd64>
...
Taking libc as an example: darwin-arm64/include would hold the relevant files from the macOS SDK, while linux-amd64/include would hold the headers of the Linux libc being targeted (glibc or musl, for instance).
Rules:
- The directory name is exactly
$GOOS-$GOARCHas defined by Go (darwin-arm64,linux-amd64,linux-arm64,windows-amd64, and so on). No aliases, no custom spellings. - Each platform directory is self-contained. It carries its own headers, and nothing is shared between platforms.
go.mod,go.sum, andllcppg.cfgstay at the project root and are common to all platforms.
Configuration
The Dir field
For an ordinary, platform-independent project, Dir is typically one of:
"Dir": "./include"
"Dir": "./include/..."
For a platform-specific project, Dir must instead start with the $GOOS-$GOARCH/ prefix:
"Dir": "$GOOS-$GOARCH/include"
"Dir": "$GOOS-$GOARCH/include/..."
The prefix is what tells llcppg that the project is platform-specific. The rest of the path keeps its existing meaning: a plain directory, or a directory followed by /... to include subdirectories recursively.
A complete example
{
"name": "libc",
"Dir": "$GOOS-$GOARCH/include/...",
"Files": [
"stdio.h",
"stdlib.h",
"string.h"
]
}
With this configuration and the layout above, llcppg run for darwin/arm64 reads headers from darwin-arm64/include/..., and run for linux/amd64 reads them from linux-amd64/include/.... Everything else in llcppg.cfg (prefixes, type aliases, and so on) behaves as it does today and applies to whichever platform is being converted.
Validation
llcppg should reject configurations that would silently produce confusing results:
- A
Dirthat mentions$GOOSor$GOARCHanywhere other than as the leading$GOOS-$GOARCH/segment is an error. - A project whose headers live under platform directories but whose
Dirlacks the prefix is not detected specially; it is simply treated as a normal project. Detection is driven by theDirprefix only. - If the resolved platform directory does not exist, llcppg fails with a message that names the expected path (for example
darwin-arm64/include).
Output Layout
When converting, the user passes <dest-dir> exactly as before:
llcppg <dest-dir> [<src-dir>]
For a platform-specific project, llcppg does not write the generated package directly into <dest-dir>. It appends the platform directory automatically:
<dest-dir>/
darwin-arm64/
<generated Go package for darwin/arm64>
and for another platform:
<dest-dir>/
linux-amd64/
<generated Go package for linux/amd64>
Key points:
- The user never creates
darwin-arm64(or any other platform directory) by hand. It is created by llcppg. - The same
<dest-dir>can therefore accumulate bindings for several platforms, one subdirectory each, without any collision. - For ordinary platform-independent projects nothing changes: output still goes straight into
<dest-dir>.
Selecting the Target Platform
llcppg needs to know which platform it is converting for, so it can expand $GOOS-$GOARCH. The proposal follows Go's conventions:
- The
GOOSandGOARCHenvironment variables select the target platform. - If they are unset, llcppg uses the host platform (
runtime.GOOS/runtime.GOARCH).
Because platforms are independent, producing bindings for several platforms is simply a matter of running llcppg once per platform:
GOOS=darwin GOARCH=arm64 llcppg <dest-dir> [<src-dir>]
GOOS=linux GOARCH=amd64 llcppg <dest-dir> [<src-dir>]
Both runs write into their own subdirectory of <dest-dir>.
Compatibility
- Existing projects are unaffected. A
Dirwithout the$GOOS-$GOARCH/prefix keeps the current behavior in full, including the output location. - No change is required to the cfg schema other than the new meaning of the
Dirprefix.
Non-Goals
This proposal deliberately stops at "generate and organize per-platform bindings". The following are left for follow-up proposals:
- A unified import path that automatically selects the right platform package at build time (for example via build constraints or a facade package).
- Sharing or deduplicating declarations across platforms.
- Fetching or vendoring SDK headers for a platform; the headers are provided in the platform directory by the project author.
Open Questions
- Concrete prefixes in
Dir. ShouldDiralso be allowed to name a concrete platform (for exampledarwin-arm64/include) to pin a project to one platform, or must it always use the$GOOS-$GOARCHplaceholder form? - Go package path. The generated package lands in
<dest-dir>/darwin-arm64, so its import path ends with the platform directory. A follow-up proposal should decide how consumers import a platform-neutral name on top of this. - Cross-conversion. Running llcppg on a Linux host for
darwin/arm64requires the Darwin headers to be parsed with the right target triple. The framework allows it throughGOOS/GOARCH, but the clang invocation details (target triple, sysroot) need to be specified. - Architecture-independent platforms. Some systems may want a single directory per OS (
linux) rather than per OS/arch pair. This proposal sticks to Go's$GOOS-$GOARCHform; a coarser grouping can be considered later if real cases appear.
- Lingua principale
- Go
- Stelle
- 40
- Fork
- 13
- Merge medio
- 2h 4m
- PR unite (30g)
- 143
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di goplus/llcppg
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 6/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
goplus/llcppg#1136 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di goplus/llcppg
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
riverqueue/river#1576 ·
I maintainer di solito rispondono entro 1 giorno
-
NFS StorageProvider renders a missing nfsSubDir as "<no value>"Forse già presa @ldming l’ha presa oggi. Apertakind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apecloud/kubeblocks#11067 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
emersion/go-msgauth#87 ·
-
CLI: `describe <ns>.<table>` reports "namespace does not exist" when only the table is missingForse già presa @Shruthirdy l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
apache/iceberg-go#2423 ·
I maintainer di solito rispondono entro 2 giorni
-
good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
mafzalkalwardev/mailforge#21 ·