Skip to content

Commit

Permalink
Allow compiling with CGO_ENABLED=1 and no measurement-kit (#344)
Browse files Browse the repository at this point in the history
I want to build an `.aar` file that only includes experiments written in Go such that I can link such `.aar` file into the OONI app along with measurement-kit/android-libs. To this end, I need to be able to compile this repository with CGO enabled, to cross compile for Android, but without linking with MK.

This work is part of #339.
  • Loading branch information
bassosimone committed Feb 18, 2020
1 parent 60d2060 commit 1b63702
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v2
- run: go test -v -coverprofile=probe-engine.cov -coverpkg=./... ./...
- run: go test -tags nomk -v -coverprofile=probe-engine.cov -coverpkg=./... ./...
env:
CGO_ENABLED: 0
- name: Send coverage
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ and requires Go v1.13+. We also depend on [Measurement Kit](
https://github.com/measurement-kit/measurement-kit), a C++14 library
implementing many OONI tests.

Note that `export CGO_ENABLED=0` will disable C/C++ extensions and
therefore will prevent Measurement Kit tests from being linked into
the resulting Go binaries. You may want that in some cases, e.g. when
you only want to use OONI tests written in Go.
Note that passing the `-tags nomk` flag to Go will disable linking
Measurement Kit into the resulting Go binaries. You may want that in
cases where you only want to use experiments written in Go.

We plan on gradually rewriting all OONI tests in Go, therefore the
dependency on Measurement Kit will eventually be removed.
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions measurementkit/task_cgo.go → measurementkit/mkcgo/mkcgo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package measurementkit
// +build cgo

// Package mkcgo contains CGO bindings to Measurement Kit.
package mkcgo

import (
// #include <measurement_kit/ffi.h>
Expand Down Expand Up @@ -75,7 +78,8 @@ func taskstart(settings []byte) *C.mk_task_t {
return C.mk_task_start(settingsp)
}

func start(settings []byte) (<-chan []byte, error) {
// Start starts a Measurement Kit task.
func Start(settings []byte) (<-chan []byte, error) {
taskp := taskstart(settings)
if taskp == nil {
return nil, errors.New("C.mk_task_start failed")
Expand All @@ -84,7 +88,3 @@ func start(settings []byte) (<-chan []byte, error) {
go taskloop(taskp, out)
return out, nil
}

func available() bool {
return true
}
15 changes: 15 additions & 0 deletions measurementkit/task_mk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build !nomk

package measurementkit

import (
"github.com/ooni/probe-engine/measurementkit/mkcgo"
)

func start(settings []byte) (<-chan []byte, error) {
return mkcgo.Start(settings)
}

func available() bool {
return true
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !cgo
// +build nomk

package measurementkit

Expand Down

0 comments on commit 1b63702

Please sign in to comment.