Commit 762daa2c authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Build SWIG and include it into Go build environment

Even if we don't use swig in our go projects, if hosting environment has
swig, but incorrectly installed, then Go build will fail as:

   --- FAIL: TestScript (0.03s)
       --- FAIL: TestScript/list_swigcxx (0.46s)
           script_test.go:252:
               # go list should not report SWIG-generated C++ files in CompiledGoFiles. (0.001s)
               # CompiledGoFiles should contain 4 files:
               #  a.go
               #  a.swigcxx.go
               #  _cgo_gotypes.go
               #  a.cgo1.go (0.421s)
               > go list -f '{{.CompiledGoFiles}}' -compiled=true example/swig
               [stdout]
               []
               [stderr]
               # example/swig
               :1: Error: Unable to find 'swig.swg'
               :3: Error: Unable to find 'go.swg'
               [exit status 2]
               FAIL: testdata/script/list_swigcxx.txt:12: unexpected command failure

Such broken environment, in particular, is present on our testnodes,
because there swig program is being included into slapos-node package,
slapos command includes it into $PATH for spawned programs

    https://lab.nexedi.com/nexedi/slapos/blob/99cf4bfd/component/slapos/buildout.cfg#L22-30
    https://lab.nexedi.com/nexedi/slapos/blob/99cf4bfd/component/slapos/buildout.cfg#L74-88

but the swig binary itself is configured to look into its supporting files in
the wrong place:

    slapuser91@vifibcloud-rapidspace-hosting-007:~/t/swig$ /opt/slapos/parts/swig/bin/swig -swiglib
    /usr/src/packages/BUILD/slapos/build/opt/slapos/parts/swig/share/swig/3.0.10

    slapuser91@vifibcloud-rapidspace-hosting-007:~/t/swig$ ll /usr/src/packages/BUILD/slapos/build/opt/slapos/parts/swig/share/swig/3.0.10
    ls: cannot access '/usr/src/packages/BUILD/slapos/build/opt/slapos/parts/swig/share/swig/3.0.10': No such file or directory

which leads to SWIG being broken:

    slapuser91@vifibcloud-rapidspace-hosting-007:~/t/swig$ /opt/slapos/parts/swig/bin/swig -v -go -intgosize 64 a.swigcxx
    Language subdirectory: go
    Search paths:
       ./
       ./swig_lib/go/
       /usr/src/packages/BUILD/slapos/build/opt/slapos/parts/swig/share/swig/3.0.10/go/
       ./swig_lib/
       /usr/src/packages/BUILD/slapos/build/opt/slapos/parts/swig/share/swig/3.0.10/
    Preprocessing...
    :1: Error: Unable to find 'swig.swg'
    :3: Error: Unable to find 'go.swg'

-> Fix it by building SWIG ourselves and using that built swig to build go and
in the Go environment provided to users.

See "Troubleshooting" in http://www.swig.org/Release/README for details.

/cc @luke, @jerome, @romain
parent 99cf4bfd
......@@ -5,6 +5,7 @@ extends =
../gcc/buildout.cfg
../git/buildout.cfg
../pkgconfig/buildout.cfg
../swig/buildout.cfg
./buildout.hash.cfg
parts = gowork go
......@@ -21,6 +22,7 @@ make-targets= cd src && unset GOBIN && ./all.bash && cp -alf .. ${:location}
# some testdata files have an issue with slapos.extension.strip.
post-install = ${findutils:location}/bin/find ${:location}/src -type d -name testdata -exec rm -rf {} \; || true
environment =
PATH=${swig:location}/bin:%(PATH)s
GOROOT_FINAL=${:location}
${:environment-extra}
......
......@@ -15,4 +15,4 @@
[gowork-env.sh]
filename = goenv.sh.in
md5sum = f6d0fc24e3f08f27bc2bd85003ca5ec2
md5sum = 67a211c786a2351867c3c38f675370f7
......@@ -14,7 +14,7 @@ done <<-EOF
EOF
# PATH so that go & friends work out of the box
export PATH=${gowork:golang}/bin:${git:location}/bin:${pkgconfig:location}/bin:${buildout:bin-directory}:${gcc:prefix}/bin:$PATH
export PATH=${gowork:golang}/bin:${git:location}/bin:${pkgconfig:location}/bin:${buildout:bin-directory}:${gcc:prefix}/bin:${swig:location}/bin:$PATH
X=${gowork:directory}
export PKG_CONFIG_PATH=$(echo -n "${gowork:cpkgpath}" |tr '\n' ':'):$PKG_CONFIG_PATH
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment