Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove files prefix #393

Merged
merged 9 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@


#include <string.h>
#include "cimcte_wrapper.h"
#include "cimcte_structs_accessor.h"
#include "wrapper.h"
#include "structs_accessor.h"

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include "cimcte_wrapper.h"
#include "wrapper.h"

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// DO NOT EDIT.


#include "cimcte_typedefs.h"
#include "typedefs.h"
#include "../cwrappers/cimCTE.h"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Code generated by cmd/codegen from https://github.com/AllenDang/cimgui-go.
// DO NOT EDIT.

#include "cimcte_wrapper.h"
#include "wrapper.h"
#include "../cwrappers/cimCTE.h"

void wrap_TextEditor_Redo(TextEditor* self) { TextEditor_Redo(self,1); }
Expand Down
File renamed without changes.
84 changes: 39 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,73 @@ define generate
cat templates/cflags.go |sed -e "s/^package.*/package $(2)/g" > $(2)/cflags.go
cd $(2); \
../codegen -preset ../cmd/codegen/cimgui-go-preset.json -p $(1) -pkg $(2) -i ../$(3) -d ../$(4) -e ../$(5) -t ../$(6) $(7)
go run mvdan.cc/gofumpt@latest -w $(2)/$(1)_enums.go
go run mvdan.cc/gofumpt@latest -w $(2)/$(1)_funcs.go
go run mvdan.cc/gofumpt@latest -w $(2)/$(1)_typedefs.go
go run mvdan.cc/gofumpt@latest -w $(2)/$(1)_callbacks.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/$(1)_funcs.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/$(1)_enums.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/$(1)_typedefs.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/$(1)_callbacks.go
go run mvdan.cc/gofumpt@latest -w $(2)/enums.go
go run mvdan.cc/gofumpt@latest -w $(2)/funcs.go
go run mvdan.cc/gofumpt@latest -w $(2)/typedefs.go
go run mvdan.cc/gofumpt@latest -w $(2)/callbacks.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/funcs.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/enums.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/typedefs.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/callbacks.go
endef

define cimgui
define imgui
$(call generate,cimgui,imgui,cwrappers/cimgui.h,cwrappers/cimgui_templates/definitions.json,cwrappers/cimgui_templates/structs_and_enums.json,cwrappers/cimgui_templates/typedefs_dict.json)
endef

## cimgui: generate cimgui binding
.PHONY: cimgui
cimgui: setup
$(call cimgui)
## cimgui: generate imgui binding
.PHONY: imgui
imgui: setup
$(call imgui)

define cimplot
define implot
$(call generate,cimplot,implot,cwrappers/cimplot.h,cwrappers/cimplot_templates/definitions.json,cwrappers/cimplot_templates/structs_and_enums.json,cwrappers/cimplot_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef

## cimplot: generate implot binding
.PHONY: cimplot
cimplot: setup
$(call cimplot)
## implot: generate implot binding
.PHONY: implot
implot: setup
$(call implot)

define cimnodes
define imnodes
$(call generate,cimnodes,imnodes,cwrappers/cimnodes.h,cwrappers/cimnodes_templates/definitions.json,cwrappers/cimnodes_templates/structs_and_enums.json,cwrappers/cimnodes_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef

## cimnodes: generate imnodes binding
.PHONY: cimnodes
cimnodes: setup
$(call cimnodes)
## imnodes: generate imnodes binding
.PHONY: imnodes
imnodes: setup
$(call imnodes)

define cimmarkdown
define immarkdown
$(call generate,cimmarkdown,immarkdown,cwrappers/cimmarkdown.h,cwrappers/cimmarkdown_templates/definitions.json,cwrappers/cimmarkdown_templates/structs_and_enums.json,cwrappers/cimmarkdown_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef

## cimmarkdown: generate immarkdown binding
.PHONY: cimmarkdown
cimmarkdown: setup
$(call cimmarkdown)
## immarkdown: generate immarkdown binding
.PHONY: immarkdown
immarkdown: setup
$(call immarkdown)

define cimguizmo
define imguizmo
$(call generate,cimguizmo,imguizmo,cwrappers/cimguizmo.h,cwrappers/cimguizmo_templates/definitions.json,cwrappers/cimguizmo_templates/structs_and_enums.json,cwrappers/cimguizmo_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef

## cimgui: generate cimgui binding
.PHONY: cimguizmo
cimguizmo: setup
$(call cimguizmo)
## imguizmo: generate imguizmo binding
.PHONY: imguizmo
imguizmo: setup
$(call imguizmo)

define cimcte
define imcte
$(call generate,cimcte,ImGuiColorTextEdit,cwrappers/cimCTE.h,cwrappers/cimCTE_templates/definitions.json,cwrappers/cimCTE_templates/structs_and_enums.json,cwrappers/cimCTE_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef

## cimcte: generate cimgui binding
.PHONY: cimcte
cimcte: setup
$(call cimcte)

compile_cimgui_macos:
rm -rf ./lib/build
cd ./lib; cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DIMGUI_STATIC=On -DCMAKE_OSX_ARCHITECTURES=arm64
cd ./lib/build; make
cp -f ./lib/build/cimgui.a ./lib/macos/arm64/
## imcte: generate ImGuiColorTextEdit binding
.PHONY: imcte
imcte: setup
$(call imcte)

## generate: generates both bindings (equal to `all`)
.PHONY: generate
generate: cimgui cimplot cimnodes cimmarkdown cimguizmo cimcte
generate: imgui implot imnodes immarkdown imguizmo imcte

# update updates sub-repos (like cimplot or cimgui)
# $1 - subrepo directory
Expand Down
4 changes: 2 additions & 2 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package backend
// extern void keyCallback(void*, int, int, int, int);
// extern void sizeCallback(void*, int, int);
// #include "../imgui/extra_types.h"
// #include "../imgui/cimgui_wrapper.h"
// #include "../imgui/cimgui_typedefs.h"
// #include "../imgui/wrapper.h"
// #include "../imgui/typedefs.h"
import "C"

import (
Expand Down
2 changes: 1 addition & 1 deletion backend/glfwbackend/glfw_backend.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../../imgui/cimgui_wrapper.h"
#include "../../imgui/wrapper.h"
#include "../../thirdparty/glfw/include/GLFW/glfw3.h" // Will drag system OpenGL headers
#include "../../imgui/extra_types.h"

Expand Down
2 changes: 1 addition & 1 deletion backend/sdlbackend/sdl_backend.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../../imgui/cimgui_wrapper.h"
#include "../../imgui/wrapper.h"
#include "../../thirdparty/SDL/include/SDL.h" // Will drag system OpenGL headers
#include "../../imgui/extra_types.h"

Expand Down
26 changes: 13 additions & 13 deletions cmd/codegen/gencpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ extern "C" {

cppSb := &strings.Builder{}
cppSb.WriteString(cppFileHeader)
fmt.Fprintf(cppSb, `#include "%s_wrapper.h"
fmt.Fprintf(cppSb, `#include "wrapper.h"
#include "%s"

`, prefix, includePath)
`, includePath)

// Note for future generations: can't replace with range, because we edit funcDefs later
for i := 0; i < len(funcDefs); i++ {
Expand Down Expand Up @@ -385,7 +385,7 @@ extern "C" {
#endif
`)

headerPath := fmt.Sprintf("%s_wrapper.h", prefix)
headerPath := "wrapper.h"
headerFile, err := os.Create(headerPath)
if err != nil {
return nil, fmt.Errorf("failed to create header file %v: %v", headerPath, err)
Expand All @@ -398,7 +398,7 @@ extern "C" {
return nil, fmt.Errorf("failed to write header file %v: %v", headerPath, err)
}

cppPath := fmt.Sprintf("%s_wrapper.cpp", prefix)
cppPath := "wrapper.cpp"
cppFile, err := os.Create(cppPath)
if err != nil {
return nil, fmt.Errorf("failed to create cpp file %v: %v", cppPath, err)
Expand Down Expand Up @@ -430,22 +430,22 @@ func generateCppStructsAccessor(prefix string, validFuncs []FuncDef, structs []S
sbHeader.WriteString(cppFileHeader)
sbCpp.WriteString(cppFileHeader)

sbHeader.WriteString(fmt.Sprintf(`#pragma once
sbHeader.WriteString(`#pragma once

#include "%s_wrapper.h"
#include "wrapper.h"

#ifdef __cplusplus
extern "C" {
#endif

`, prefix))
`)

sbCpp.WriteString(fmt.Sprintf(`
sbCpp.WriteString(`
#include <string.h>
#include "%[1]s_wrapper.h"
#include "%[1]s_structs_accessor.h"
#include "wrapper.h"
#include "structs_accessor.h"

`, prefix))
`)

for _, s := range structs {
for _, m := range s.Members {
Expand Down Expand Up @@ -574,7 +574,7 @@ extern "C" {
#endif
`)

headerPath := fmt.Sprintf("%s_structs_accessor.h", prefix)
headerPath := "structs_accessor.h"
headerFile, err := os.Create(headerPath)
if err != nil {
return nil, fmt.Errorf("failed to create cpp file %v: %v", headerPath, err)
Expand All @@ -587,7 +587,7 @@ extern "C" {
return nil, fmt.Errorf("failed to write to file %v: %v", headerPath, err)
}

cppPath := fmt.Sprintf("%s_structs_accessor.cpp", prefix)
cppPath := "structs_accessor.cpp"
cppFile, err := os.Create(cppPath)
if err != nil {
return nil, fmt.Errorf("failed to create cpp file %v: %v", cppPath, err)
Expand Down
12 changes: 6 additions & 6 deletions cmd/codegen/gengo_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GenerateCallbacks(callbacks []CIdentifier, context *Context) (validTypes []
if err := result.writeCallback(typedefName, result.ctx.typedefs.data[typedefName]); err != nil {
if errors.Is(err, callbackNotGeneratedError) {
if context.flags.showNotGenerated {
glg.Warnf("Callback \"%s\" was not generated", typedefName)
glg.Warnf("Callback \"%s\" was not generated: %v", typedefName, err)
}

continue
Expand Down Expand Up @@ -458,9 +458,9 @@ func (g *callbacksGenerator) saveToDisk() error {
`// #include <stdlib.h>
// #include <memory.h>
// #include "../imgui/extra_types.h"
// #include "%[1]s_wrapper.h"
// #include "%[1]s_typedefs.h"
`, g.ctx.prefix)
// #include "wrapper.h"
// #include "typedefs.h"
`)

fmt.Fprintf(result, g.cgoSb.String())

Expand All @@ -470,8 +470,8 @@ import "unsafe"

fmt.Fprintf(result, g.goSb.String())

if err := os.WriteFile(fmt.Sprintf("%s_callbacks.go", g.ctx.prefix), []byte(result.String()), 0644); err != nil {
return fmt.Errorf("cannot write %s_typedefs.go: %w", g.ctx.prefix, err)
if err := os.WriteFile("callbacks.go", []byte(result.String()), 0644); err != nil {
return fmt.Errorf("cannot write typedefs.go: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/codegen/gengo_enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func generateGoEnums(prefix string, enums []EnumDef, ctx *Context) ([]CIdentifie
sb.WriteString(")\n\n")
}

enumFile, err := os.Create(fmt.Sprintf("%s_enums.go", prefix))
enumFile, err := os.Create("enums.go")
if err != nil {
return nil, err
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/codegen/gengo_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func GenerateGoFuncs(
context *Context,
) error {
generator := &goFuncsGenerator{
prefix: context.prefix,
prefix: context.prefix,
typedefsNames: context.typedefsNames,
enumNames: context.enumNames,
refTypedefs: context.refTypedefs,
context: context,
enumNames: context.enumNames,
refTypedefs: context.refTypedefs,
context: context,
}

generator.writeFuncsFileHeader()
Expand Down Expand Up @@ -83,7 +83,7 @@ func GenerateGoFuncs(
100*float32(generator.convertedFuncCount)/float32(len(validFuncs)),
)

goFile, err := os.Create(fmt.Sprintf("%s_funcs.go", context.prefix))
goFile, err := os.Create("funcs.go")
if err != nil {
panic(err.Error())
}
Expand All @@ -100,10 +100,10 @@ func GenerateGoFuncs(

// goFuncsGenerator is an internal state of GO funcs' generator
type goFuncsGenerator struct {
prefix string
prefix string
typedefsNames map[CIdentifier]bool
enumNames map[CIdentifier]bool
refTypedefs map[CIdentifier]bool
enumNames map[CIdentifier]bool
refTypedefs map[CIdentifier]bool

sb strings.Builder
convertedFuncCount int
Expand All @@ -116,14 +116,14 @@ type goFuncsGenerator struct {
func (g *goFuncsGenerator) writeFuncsFileHeader() {
g.sb.WriteString(getGoPackageHeader(g.context))

g.sb.WriteString(fmt.Sprintf(
g.sb.WriteString(
`// #include "../imgui/extra_types.h"
// #include "%[1]s_structs_accessor.h"
// #include "%[1]s_wrapper.h"
// #include "structs_accessor.h"
// #include "wrapper.h"
import "C"
import "unsafe"

`, g.prefix))
`)
}

func (g *goFuncsGenerator) GenerateFunction(f FuncDef, args []GoIdentifier, argWrappers []ArgumentWrapperData) (noErrors bool) {
Expand Down
Loading
Loading