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

cmd/go: packages that use cgo not cached when cross-compiling android .so file #29132

Open
bronze1man opened this issue Dec 7, 2018 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Milestone

Comments

@bronze1man
Copy link
Contributor

bronze1man commented Dec 7, 2018

Here is my build command (fast in go1.9.2), I used goroutines and waitgroup to make it build two android cpu arch in two processes to make it faster:

go build -buildmode=c-shared -i -pkgdir /xxx/pkg/android_386_shared -tags "android linux" -ldflags "-s -w" -gcflags=-trimpath=/xxx/ -o=bin/jniLibs/x86/libxxx.so xxx/xxx
go build -buildmode=c-shared -i -pkgdir /xxx/pkg/android_arm_shared -tags "android linux" -ldflags "-s -w" -gcflags=-trimpath=/xxx/ -o=bin/jniLibs/arm/libxxx.so xxx/xxx

My computer os is mac os 10.13.6
My program use cgo and it have a lot of c source code (sqlite3,"github.com/mutecomm/go-sqlcipher")
During all step I will not delete/modify the result .so files.
before first time run in go1.11.2, i will use rm -rf /Users/xxx/Library/Caches/go-build && rm -rf ./pkg && rm -rf ./bin to clean all build cache.
before first time run in go1.9.2, i will use rm -rf ./pkg && rm -rf ./bin to clean all build cache.
after first time run and before second time run, I will not change any code.
after second time run and before third time run, I will change one comment in the main package.

build time with go1.11.2

  • first 1m15.48132439s
  • second 44.123888335s
  • third 46.841824535s

build time with go1.9.2

  • first 1m15.187967573s
  • second 5.208278504s
  • third 3.91962979s

What I have already tried

Looks like I have already did what i can do to make the build faster in the command line without read the actually build source code to find some hidden faster flag.

  • I have tried go install -buildmode=c-shared xxx, it will not faster.
  • I have tried do not pass -pkgdir parameters, it will not faster.
  • I have tried do not pass -i parameters, it will not faster.
  • I have tried add -ldflags "-s -w", it save me about 20s in golang1.11.2, so I add in my program.

My build script to cross build .a file (-buildmode=c-archive) to ios(darwin arm64) have the same problem.
My build script to cross build elf file to (linux,amd64) become faster in go1.11.2 than go1.9.2.
I guess the build cache part of cross build android/ios or (-buildmode=c-archive) or (-buildmode=c-shared) have been delete.
Currently, I have to stop upgrade to newer golang version forever if I want develop my android/ios app faster.

So My problem is What command line should I use, if I want faster corss build to android with go1.11.2?

@ianlancetaylor
Copy link
Contributor

Show us the go build -x output.

@bronze1man
Copy link
Contributor Author

bronze1man commented Dec 7, 2018

2018-12-07_13-22-24.log.zip

Here's the log result of the second execution without code changes.

@ianlancetaylor
Copy link
Contributor

Thanks. Looks like the packages that use cgo have not been cached. I'm not sure why.

@ianlancetaylor ianlancetaylor changed the title android .so file cross build slow without code change after upgrade to go1.11.2 from go1.9.2 cmd/go: android .so file cross build slow without code change after upgrade to go1.11.2 from go1.9.2 Dec 7, 2018
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 7, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Dec 7, 2018
@bcmills bcmills modified the milestones: Go1.12, Go1.13 Jan 17, 2019
@bcmills bcmills changed the title cmd/go: android .so file cross build slow without code change after upgrade to go1.11.2 from go1.9.2 cmd/go: packages that use cgo not cached when cross-compiling android .so file Jan 17, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Projects
None yet
Development

No branches or pull requests

5 participants