Skip to content

Commit 3d241d8

Browse files
committed
Fix generated Makefile for pybindgen and capi
1 parent c5ba697 commit 3d241d8

2 files changed

Lines changed: 21 additions & 30 deletions

File tree

‎bind/gen.go‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,10 @@ def Init():
436436
437437
`
438438

439-
// 3 = gencmd, 4 = vm, 5 = libext 6 = extraGccArgs, 7 = CFLAGS, 8 = LDLFAGS,
440-
// 9 = windows special declspec hack, 10 = gopy version
439+
// 3 = gencmd, 4 = vm, 5 = libext, 6 = module file name,
440+
// 7 = windows special declspec hack, 8 = gopy version
441441
MakefileTemplate = `# Makefile for python interface for package %[1]s.
442-
# File is generated by gopy version %[10]s. Do not edit.
442+
# File is generated by gopy version %[8]s. Do not edit.
443443
# %[2]s
444444
445445
GOCMD=go
@@ -448,11 +448,6 @@ GOIMPORTS=goimports
448448
PYTHON=%[4]s
449449
LIBEXT=%[5]s
450450
451-
# get the CC and flags used to build python:
452-
GCC = $(shell $(GOCMD) env CC)
453-
CFLAGS = %[7]s
454-
LDFLAGS = %[8]s
455-
456451
all: gen build
457452
458453
gen:
@@ -464,20 +459,21 @@ build:
464459
- rm %[1]s.c
465460
# goimports is needed to ensure that the imports list is valid
466461
$(GOIMPORTS) -w %[1]s.go
467-
# generate %[1]s_go$(LIBEXT) from %[1]s.go -- the cgo wrappers to go functions
462+
# build %[1]s.go -- the cgo wrappers to go functions -- once, only for the
463+
# %[1]s_go.h header it writes, which %[1]s.c includes
468464
$(GOBUILD) -buildmode=c-shared -o %[1]s_go$(LIBEXT) %[1]s.go
469-
# use pybindgen to build the %[1]s.c file which are the CPython wrappers to cgo wrappers..
470-
# note: pip install pybindgen to get pybindgen if this fails
471-
$(PYTHON) build.py
472-
# build the _%[1]s$(LIBEXT) library that contains the cgo and CPython wrappers
473-
# generated %[1]s.py python wrapper imports this c-code package
474-
%[9]s
475-
$(GCC) %[1]s.c %[6]s %[1]s_go$(LIBEXT) -o _%[1]s$(LIBEXT) $(CFLAGS) $(LDFLAGS) -fPIC --shared -w
476-
465+
- rm %[1]s_go$(LIBEXT)
466+
# write %[1]s.c, the CPython wrappers to the cgo wrappers
467+
$(PYTHON) build.py%[7]s
468+
# build the module %[1]s.py imports: cgo compiles %[1]s.c into the same
469+
# shared library as the go code, so it depends on nothing but python
470+
$(GOBUILD) -buildmode=c-shared -o %[6]s .
471+
477472
`
478473

479-
// same argument positions as MakefileTemplate, though only 1-5 and 10 are used:
480-
// cffi needs none of the CPython CFLAGS/LDFLAGS that building %[1]s.c would.
474+
// 1 = package name, 2 = gopy command, 3 = gencmd, 4 = vm, 5 = libext,
475+
// 10 = gopy version (6-9 are unused): cffi needs no %[1]s.c, and none of
476+
// the CPython flags that building one would.
481477
MakefileTemplateCFFI = `# Makefile for python interface for package %[1]s, using cffi.
482478
# File is generated by gopy version %[10]s. Do not edit.
483479
# %[2]s
@@ -896,10 +892,12 @@ func (g *pyGen) genMakefile() {
896892
} else {
897893
winhack := ""
898894
if WindowsOS {
899-
winhack = fmt.Sprintf(`# windows-only sed hack here to fix pybindgen declaration of PyInit
900-
sed -i "s/ PyInit_/ __declspec(dllexport) PyInit_/g" %s.c`, g.cfg.Name)
895+
winhack = fmt.Sprintf(`
896+
# windows-only sed hack here to fix pybindgen declaration of PyInit
897+
sed -i "s/ PyInit_/ __declspec(dllexport) PyInit_/g" %s.c`, g.cfg.Name)
901898
}
902-
g.makefile.Printf(MakefileTemplate, g.cfg.Name, g.cfg.Cmd, gencmd, g.cfg.VM, g.libext, g.extraGccArgs, pycfg.CFlags, pycfg.LdFlags, winhack, g.cfg.Version)
899+
g.makefile.Printf(MakefileTemplate, g.cfg.Name, g.cfg.Cmd, gencmd, g.cfg.VM, g.libext,
900+
ExtModuleName(g.cfg.Name, g.libext, pycfg), winhack, g.cfg.Version)
903901
}
904902
}
905903

‎main_test.go‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,9 @@ func TestBindSimple(t *testing.T) {
467467
// TestMakefile builds _examples/simple with the Makefile gopy gen writes,
468468
// rather than with gopy build, under the backend GOPY_BACKEND selects.
469469
func TestMakefile(t *testing.T) {
470-
backend, err := bind.BackendFromEnv()
471-
if err != nil {
470+
if _, err := bind.BackendFromEnv(); err != nil {
472471
t.Fatal(err)
473472
}
474-
if backend == bind.BackendPyBindGen || backend == bind.BackendCAPI {
475-
// TODO: their (shared) Makefile links _simple against a separate
476-
// simple_go shared library with no rpath, so the result only imports
477-
// with that library's directory on the loader's search path.
478-
t.Skipf("the %s backend's Makefile output doesn't import as-is", backend)
479-
}
480473
if _, err := exec.LookPath("make"); err != nil {
481474
t.Skip("make not found")
482475
}

0 commit comments

Comments
 (0)