Skip to content

Commit

Permalink
Merge branch 'ahnolds-clean_osx_go'
Browse files Browse the repository at this point in the history
* ahnolds-clean_osx_go:
  Go test-suite should now work on OSX
  Don't write empty swigargs structs
  Fail if nocgo version fails
  Handle weak linking on OSX

Conflicts:
	CHANGES.current
  • Loading branch information
wsfulton committed Jan 28, 2016
2 parents 15b75a7 + 3a9f260 commit 2817e02
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Expand Up @@ -162,9 +162,6 @@ matrix:
- compiler: gcc
os: linux
env: SWIGLANG=python SWIG_FEATURES=-O
- compiler: clang
os: osx
env: SWIGLANG=go
before_install:
- date -u
- uname -a
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.current
Expand Up @@ -8,6 +8,15 @@ Version 3.0.9 (in progress)
2016-01-27: steeve
[Go] Ensure structs are properly packed between gc and GCC/clang.

2016-01-23: ahnolds
[Go] Enable support for the Go test-suite on OSX:
* The linker on OSX requires that all symbols (even weak symbols)
are defined at link time. Because the function _cgo_topofstack is
only defined starting in Go version 1.4, we explicitly mark it as
undefined for older versions of Go on OSX.
* Avoid writing empty swigargs structs, since empty structs are not
allowed in extern "C" blocks.

2016-01-12: olly
[Javascript] Look for "nodejs" as well as "node", as it's packaged
as the former on Debian.
Expand Down
14 changes: 9 additions & 5 deletions Examples/test-suite/go/Makefile.in
Expand Up @@ -11,6 +11,8 @@ GO12 = @GO12@
GO13 = @GO13@
GO15 = @GO15@
GOC = @GOC@
GOVERSIONOPTION = @GOVERSIONOPTION@
host = @host@
SCRIPTSUFFIX = _runme.go

GOCOMPILEARG = `if $(GO15); then echo tool compile; elif $(GO1); then echo tool $(GOC:c=g); fi`
Expand All @@ -20,6 +22,8 @@ GOPACK = `if $(GO1) ; then echo go tool pack; else echo gopack; fi`

GOOBJEXT = `if $(GO15); then echo o; else echo $(GOC:c=); fi`

OSXOLDGOLINKFLAGS = `if [ -n "\`$(GO) $(GOVERSIONOPTION) | grep -E 'go1($|.0|.1|.2|.3)'\`" ] && [ -n "\`echo $(host) | grep darwin\`" ]; then echo "-Wl,-U,__cgo_topofstack"; fi`

SO = @SO@

srcdir = @srcdir@
Expand Down Expand Up @@ -50,7 +54,7 @@ INCLUDES = -I$(abs_top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \
TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \
$(LANGUAGE)$(VARIANT)_cpp_nocgo; \
$(LANGUAGE)$(VARIANT)_cpp_nocgo && \
$(run_testcase_cpp); \
fi

Expand All @@ -63,7 +67,7 @@ INCLUDES = -I$(abs_top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \
TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \
$(LANGUAGE)$(VARIANT)_nocgo; \
$(LANGUAGE)$(VARIANT)_nocgo && \
$(run_testcase); \
fi

Expand Down Expand Up @@ -121,7 +125,7 @@ run_testcase = \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
Expand All @@ -136,7 +140,7 @@ run_testcase_cpp = \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
Expand All @@ -152,7 +156,7 @@ run_multi_testcase = \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.a; done` -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/go.cxx
Expand Up @@ -2112,6 +2112,7 @@ class GO:public Language {
emit_attach_parmmaps(parms, f);
int parm_count = emit_num_arguments(parms);
int required_count = emit_num_required(parms);
bool needs_swigargs = false;

emit_return_variable(n, result, f);

Expand All @@ -2125,6 +2126,7 @@ class GO:public Language {
String *swigargs = NewString("\tstruct swigargs {\n");

if (parm_count > required_count) {
needs_swigargs = true;
Printv(swigargs, "\t\tintgo _swig_optargc;\n", NULL);
}

Expand All @@ -2136,6 +2138,7 @@ class GO:public Language {
SwigType *pt = Getattr(p, "type");
String *ct = gcCTypeForGoValue(p, pt, ln);
Printv(swigargs, "\t\t\t", ct, ";\n", NULL);
needs_swigargs = true;
Delete(ct);

String *gn = NewStringf("_swig_go_%d", i);
Expand All @@ -2152,6 +2155,7 @@ class GO:public Language {
String *ct = gcCTypeForGoValue(n, result, ln);
Delete(ln);
Printv(swigargs, "\t\t", ct, ";\n", NULL);
needs_swigargs = true;
Delete(ct);

ln = NewString("_swig_go_result");
Expand Down Expand Up @@ -2208,7 +2212,10 @@ class GO:public Language {

cleanupFunction(n, f, parms);

Printv(f->locals, swigargs, NULL);
if (needs_swigargs)
{
Printv(f->locals, swigargs, NULL);
}

Printv(f->code, "}\n", NULL);

Expand Down

0 comments on commit 2817e02

Please sign in to comment.