Commit f5ab890c authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/go: only check SWIG intsize once per build

Besides being more efficient in a large build, this avoids a possible
race when creating the input file.

Change-Id: Ifc2cb055925a76be9c90eac56d84ebd9e14f2bbc
Reviewed-on: https://go-review.googlesource.com/19392Reviewed-by: default avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
parent 622780b1
......@@ -3422,6 +3422,13 @@ func (b *builder) swigVersionCheck() error {
return swigCheck
}
// Find the value to pass for the -intgosize option to swig.
var (
swigIntSizeOnce sync.Once
swigIntSize string
swigIntSizeError error
)
// This code fails to build if sizeof(int) <= 32
const swigIntSizeCode = `
package main
......@@ -3429,8 +3436,8 @@ const i int = 1 << 32
`
// Determine the size of int on the target system for the -intgosize option
// of swig >= 2.0.9
func (b *builder) swigIntSize(obj string) (intsize string, err error) {
// of swig >= 2.0.9. Run only once.
func (b *builder) swigDoIntSize(obj string) (intsize string, err error) {
if buildN {
return "$INTBITS", nil
}
......@@ -3448,6 +3455,15 @@ func (b *builder) swigIntSize(obj string) (intsize string, err error) {
return "64", nil
}
// Determine the size of int on the target system for the -intgosize option
// of swig >= 2.0.9.
func (b *builder) swigIntSize(obj string) (intsize string, err error) {
swigIntSizeOnce.Do(func() {
swigIntSize, swigIntSizeError = b.swigDoIntSize(obj)
})
return swigIntSize, swigIntSizeError
}
// Run SWIG on one SWIG input file.
func (b *builder) swigOne(p *Package, file, obj string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _ := b.cflags(p, true)
......
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