mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
feat(extgen): automatically add "runtime/cgo" to the imports if necessary
This commit is contained in:
committed by
Kévin Dunglas
parent
861b345b05
commit
f7298557aa
@@ -47,7 +47,7 @@ func (gg *GoFileGenerator) buildContent() (string, error) {
|
||||
|
||||
filteredImports := make([]string, 0, len(imports))
|
||||
for _, imp := range imports {
|
||||
if imp != `"C"` && imp != `"unsafe"` && imp != `"github.com/dunglas/frankenphp"` {
|
||||
if imp != `"C"` && imp != `"unsafe"` && imp != `"github.com/dunglas/frankenphp"` && imp != `"runtime/cgo"` {
|
||||
filteredImports = append(filteredImports, imp)
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,19 @@ func (gg *GoFileGenerator) buildContent() (string, error) {
|
||||
classes := make([]phpClass, len(gg.generator.Classes))
|
||||
copy(classes, gg.generator.Classes)
|
||||
|
||||
if len(classes) > 0 {
|
||||
hasCgo := false
|
||||
for _, imp := range imports {
|
||||
if imp == `"runtime/cgo"` {
|
||||
hasCgo = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasCgo {
|
||||
filteredImports = append(filteredImports, `"runtime/cgo"`)
|
||||
}
|
||||
}
|
||||
|
||||
templateContent, err := gg.getTemplateContent(goTemplateData{
|
||||
PackageName: SanitizePackageName(gg.generator.BaseName),
|
||||
BaseName: gg.generator.BaseName,
|
||||
|
||||
Reference in New Issue
Block a user