# A tiny Go code fails only on Travis CI for Linux

**URL:** <https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846>\
**Category:** Linux\
**Created:** [March 27, 2020, 11:10am UTC](https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846 "2020-03-27T11:10:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![herumi](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/herumi/32/4178_2.png) [@herumi](https://travis-ci.community/u/herumi)\
**Post date:** [March 27, 2020, 11:10am UTC](https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846/1 "2020-03-27T11:10:41Z")

</div>

I have a strange behavior of Travis CI for Linux.  
[https://github.com/herumi/test-travis-release](https://github.com/herumi/test-travis-release) is a sample of it.  
`make test` runs well in my local environments such as Ubuntu 18.04.4 LTS + go1.13.4(14.1) and macOS 10.14.  
But it fails only on Travis CI for Linux (It runs well on Travis CI for macOS).  
[https://travis-ci.org/github/herumi/test-travis-release/builds/667614744](https://travis-ci.org/github/herumi/test-travis-release/builds/667614744)

```auto
bls/bls.go:15:105: cannot use (*[8]_Ctype_char)(unsafe.Pointer(&buf[0])) (type *[8]_Ctype_char) as type unsafe.Pointer in argument to func literal

```

I think that it would cause an error in every environment if it is a syntax error.  
Could you give me some advice?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [March 27, 2020, 12:54pm UTC](https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846/2 "2020-03-27T12:54:19Z")

</div>

At the very least

- you are using `language: cpp` rather than `language: go` for some reason and Xenial rather than Bionic
- preinstalled Go version is [1.11.1](https://travis-ci.org/github/herumi/test-travis-release/jobs/667614745#L127), not 1.13.4
- it likely uses GCC in Linux and CLang in OSX

---

<div class="post-metadata">

**Author:** ![herumi](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/herumi/32/4178_2.png) [@herumi](https://travis-ci.community/u/herumi)\
**Post date:** [March 27, 2020, 7:15pm UTC](https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846/3 "2020-03-27T19:15:10Z")

</div>

Thank you for the advice.  
I tried many combinations but the results were the same.

> <https://github.com/herumi/test-travis-release/blob/master/.travis.yml>

  
[https://travis-ci.org/github/herumi/test-travis-release/builds/667846719](https://travis-ci.org/github/herumi/test-travis-release/builds/667846719)

The strangest thing for me is that it works well locally but not on travis, even if using the same version of Go.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [March 27, 2020, 10:39pm UTC](https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846/4 "2020-03-27T22:39:36Z")

</div>

If something works locally but not in Travis, there are differences between your local environment and Travis.

Find out what this error message means and dig from there – only that can tell what the cause is and point to the discrepancy.

---

<div class="post-metadata">

**Author:** ![herumi](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/herumi/32/4178_2.png) [@herumi](https://travis-ci.community/u/herumi)\
**Post date:** [March 27, 2020, 11:08pm UTC](https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846/5 "2020-03-27T23:08:04Z")

</div>

The code I pointed out is minimized from my large projects.  
It is [https://github.com/herumi/test-travis-release/blob/master/bls/bls.go](https://github.com/herumi/test-travis-release/blob/master/bls/bls.go)

```auto
package bls

/*
#cgo LDFLAGS:-lbls
#cgo linux,amd64 LDFLAGS:-L${SRCDIR}/lib/linux/amd64
#cgo darwin,amd64 LDFLAGS:-L${SRCDIR}/lib/darwin/amd64
void blsFunc(const char buf[][8]);
*/
import "C"
import (
	"unsafe"
)

func BlsFunc(buf []byte) {
	C.blsFunc((*[8]C.char)(unsafe.Pointer(&buf[0])))
}

travis says:
bls/bls.go:15:105: cannot use (*[8]_Ctype_char)(unsafe.Pointer(&buf[0])) (type *[8]_Ctype_char) as type unsafe.Pointer in argument to func literal

```

But my all environments (Ubuntu/CentOS/Windows mingw/macOS + Go 1.12.10, 1.13.4, 1.14.1 and travis with macOS) say nothing.

---

<div class="post-metadata">

**Author:** ![herumi](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/herumi/32/4178_2.png) [@herumi](https://travis-ci.community/u/herumi)\
**Post date:** [March 30, 2020, 1:56am UTC](https://travis-ci.community/t/a-tiny-go-code-fails-only-on-travis-ci-for-linux/7846/6 "2020-03-30T01:56:46Z")

</div>

I asked this problem at [go forum](https://forum.golangbridge.org/t/how-to-cast-byte-to-const-char-buf-8/18106/2) and got the answer that this Go code has no problem.  
By checking of the result of `go tool bls.go`, I found that there are difference between Travis-mac-go and Travis-linux-go.

I think that this causes an error, but I don’t know why Travis-go puts it.

```auto
bls/bls.go:13:118: cannot use _cgo0 (type *[8]_Ctype_char) as type unsafe.Pointer in argument to _Cfunc_blsFunc

```

travis-linux-go

```auto
//go:cgo_unsafe_args

func _Cfunc_blsFunc(p0 unsafe.Pointer) (r1 _Ctype_void) {
    _cgo_runtime_cgocall(_cgo_e2f56382bf64_Cfunc_blsFunc, uintptr(unsafe.Pointer(&p0)))
    if _Cgo_always_false {
        _Cgo_use(p0)
    }
    return
}

```

travis-mac-go and all my local environments (linux/mac/mingw)

```auto
//go:cgo_unsafe_args

func _Cfunc_blsFunc(p0 *[8]_Ctype_char) (r1 _Ctype_void) {
    _cgo_runtime_cgocall(_cgo_e2f56382bf64_Cfunc_blsFunc, uintptr(unsafe.Pointer(&p0)))
    if _Cgo_always_false {
        _Cgo_use(p0)
    }
    return
}

```
