Skip to content

Go generator: consolidate CGo import declarations to reduce build time #42

Description

@Randalphwa

Problem

The kwxgen Go generator currently emits import "C" in every generated *_gen.go file:

// Code generated by kwxgen. DO NOT EDIT.

package wx

// #include "kwx_classes.h"
import "C"

With 200+ generated files, this means the Go toolchain launches 200+ separate C compiler invocations, each re-parsing the full kwx_classes.h header tree. CGo does not share parsed header state across files in the same package. On a 32-core machine the build is still extremely slow because the C compilation bottleneck dominates.

Expected Behavior

The generator should consolidate all C function declarations into a single generated file (e.g., cgo_glue_gen.go) that contains all the // extern ... declarations and a single import "C". The remaining *_gen.go files would contain only pure Go wrapper functions — no import "C" — and would call helpers/type-casted C pointers from the consolidated glue file.

This is the standard pattern for large CGo packages and reduces C compiler invocations from O(N files) to O(1).

Impact

  • On a 32-core Windows machine, go build of the wx package takes several minutes
  • Nearly all of that time is redundant header parsing
  • After consolidation, incremental and clean builds should be dramatically faster (seconds instead of minutes)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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