New issue
Advanced search Search tips

Issue 912784 link

Starred by 1 user

Issue metadata

Status: Untriaged
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug



Sign in to add a comment

Figure out how to make Cgo work from Tast tests

Project Member Reported by derat@chromium.org, Dec 7

Issue description

See https://groups.google.com/a/chromium.org/d/topic/tast-users/JfvxS1AJhjc/discussion for background.

https://github.com/jochenvg/go-udev uses cgo to access the libudev C library (provided by the sys-fs/udev Portage package).

Here's the top of device.go:

----

// +build linux,cgo

package udev

/*
  #cgo LDFLAGS: -ludev
  #include <libudev.h>
  #include <linux/types.h>
  #include <stdlib.h>
        #include <linux/kdev_t.h>
*/
import "C"

----

After installing this source via https://crrev.com/c/1366411 and making a Tast test depend on it, "tast run -build" fails with the following:

# github.com/jochenvg/go-udev                                                                                                                                                                                                                                                   
/usr/lib/gopath/src/github.com/jochenvg/go-udev/device.go:7:12: fatal error: 'libudev.h' file not found                                                                                                                                                                         
  #include <libudev.h>                                                                                                                                                                                                                                                          
           ^~~~~~~~~~~                                                                                                                                                                                                                                                          
1 error generated.

I'm not sure which include paths Cgo is searching by default. When I run "emerge-caroline tast-local-tests-cros", the test builds successfully, so presumably the environment is set up properly in that case.

As a hack, I tried adding CGO_CFLAGS=-I/build/caroline/usr/include to the environment used in cmd/tast/build/build.go, but that just yields a different error further down the line:

# runtime/cgo                                                                                                                                                                                                                                                                   
In file included from gcc_libinit.c:8:                                                                                                                                                                                                                                          
/build/caroline/usr/include/pthread.h:744:12: error: declaration of built-in function '__sigsetjmp' requires inclusion of the header <setjmp.h> [-Werror,-Wbuiltin-requires-header]

In order to use Cgo, I think that we need to do additional toolchain configuration in build.go.

But I think there's a bigger issue here: we'd need to make sure that we're also using C headers and libraries that are compatible with the target arch, and there's no guarantee that that board is even set up in the chroot. "go run -build" currently builds using the host source code under /usr/lib/gopath/src (rather than /build/<board>/usr/lib/gopath/src) so that developers won't need to maintain a bunch of different board sysroots. Unless I'm missing something, we'll lose that property if we need to use Cgo when building tests.

Please let me know if I'm missing an easy solution here.
 

Sign in to add a comment