Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: failed to compile a package with C in comments #33937

Closed
hajimehoshi opened this issue Aug 29, 2019 · 7 comments
Closed

x/mobile: failed to compile a package with C in comments #33937

hajimehoshi opened this issue Aug 29, 2019 · 7 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hajimehoshi
Copy link
Member

hajimehoshi commented Aug 29, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.5 darwin/amd64
$ gomobile version
gomobile version +cafc553 Mon Aug 26 17:01:11 2019 +0000 (android,ios); androidSDK=/Users/hajimehoshi/Library/Android/sdk/platforms/android-28

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hajimehoshi/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/go-build345783314=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Build the below file with gomobile bind -target=ios

package main

// #cgo CFLAGS: -x objective-c                                                                                                                                                                                                                
// #cgo LDFLAGS: -framework Foundation -framework UIKit                                                                                                                                                                                       
//                                                                                                                                                                                                                                            
// #import <UIKit/UIKit.h>                                                                                                                                                                                                                    
import "C"

func main() {
}

What did you expect to see?

No error related to C compilation

What did you see instead?

$ gomobile bind -target=ios .
gomobile: /Users/hajimehoshi/go/bin/gobind -lang=go,objc -outdir=/var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/gomobile-work-318068638 -tags=ios . failed: exit status 1
2019/08/29 23:05:27 go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags ios -- .]: exit status 2: # example.com
./mobile.go:6:10: fatal error: 'UIKit/UIKit.h' file not found
 #import <UIKit/UIKit.h>
         ^~~~~~~~~~~~~~~
1 error generated.

At least 597adff16ade9d88626f8caea514bb189b8c74ee worked.

@gopherbot gopherbot added this to the Unreleased milestone Aug 29, 2019
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Aug 29, 2019
@hajimehoshi
Copy link
Member Author

Ah, this was duplicated with #33859

@hajimehoshi
Copy link
Member Author

hajimehoshi commented Aug 29, 2019

I found this was another case. The error message starts with # example.com (or an arbitrary package name) when C is written in a Go file.

@matloob , any thoughts?

@hajimehoshi hajimehoshi reopened this Aug 29, 2019
@hajimehoshi hajimehoshi changed the title x/mobile: failed to compile a package with Cgo for iOS x/mobile: failed to compile a package with C in comments Aug 29, 2019
@matloob
Copy link
Contributor

matloob commented Aug 29, 2019

Ugh, I think the best we can do is let through any errors that start with "# \n"

the compiler can spit out arbitrary error messages and trying to parse them is hopeless

@hajimehoshi
Copy link
Member Author

Thanks,

Ugh, I think the best we can do is let through any errors that start with "# \n"

This would highly likely include other messages than cgo, right?

@matloob
Copy link
Contributor

matloob commented Aug 29, 2019

Unfortunately yes, but I think this is the best we can do. Long term, we need to fix go list -e to not print these errors to stderr.

@gopherbot
Copy link

Change https://golang.org/cl/192330 mentions this issue: go/packages: ignore any go list errors that seem to come from cgo

@julieqiu julieqiu added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 29, 2019
hajimehoshi added a commit to hajimehoshi/ebiten that referenced this issue Sep 1, 2019
The latest version includes an issue: golang/go#33937
@gopherbot
Copy link

Change https://golang.org/cl/194497 mentions this issue: all: update go.mod

gopherbot pushed a commit to golang/mobile that referenced this issue Sep 10, 2019
The latest x/tools includes the fix
https://go-review.googlesource.com/c/tools/+/192330 for
golang/go#33937.

Updates golang/go#33937

Change-Id: I4af068315fb16aa3d526214f89e4005d792d0c49
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/194497
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@golang golang locked and limited conversation to collaborators Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants