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

Add initial gomobile support #1164

Merged
merged 71 commits into from
Feb 1, 2019
Merged

Add initial gomobile support #1164

merged 71 commits into from
Feb 1, 2019

Conversation

divan
Copy link
Contributor

@divan divan commented Aug 22, 2018

This PR adds initial "drop-in" gomobile support for status-go.
"Drop-in" means it's supposed to be used as a replacement to the current xgo-based lib package. I.e. generated .aar/.framework files should be absolutely the same and require no modification from status-react in order to work.

Important changes:

  • Add gomobile installation to the make setup
  • Replace statusgo-ios and statusgo-android to use gomobile instead of xgo
  • Remove Jenkinsfile-manual

Closes #680

@divan
Copy link
Contributor Author

divan commented Aug 22, 2018

Codeclimate doesn't like duplication in lib and mobile packages (but it's needed for transition). Travis seems to fail due to flack test TestPeerPoolSimulationSuite/TestMailServerPeersDiscovery.

Makefile Outdated
@@ -171,7 +164,11 @@ xgo:
docker pull $(XGOIMAGE)
go get github.com/karalabe/xgo

setup: dep-install lint-install mock-install ##@other Prepare project for first build
gomobile:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gomobile-install?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, thanks!

@@ -0,0 +1,64 @@
package status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can either move it to types.go or change it to jsonrpc_response.go.

It's an issue that we have so many response types but this one was introduced for bindings that are meant to replace JSON-RPC calls. In status-react, commands like eth_sendTransaction are intercepted and a binding is called instead. Thanks to this type of response, the response can be easily returned without further processing.

Copy link
Contributor

@dshulyak dshulyak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments are mostly irrelevant, but what is the thread situation in code generated by gomobile? as I remember we are using a thread pool in objective-c and java, and application seems to depend on it

return makeJSONResponse(err)
}

api.RunAsync(func() error { return statusBackend.StartNode(config) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really related to this PR. but it seems that RunAsync is totally unnecessary, every call is executed in its own thread. so, for example, StartNode can return an actual error, instead of using signals to report that error. and that means - part of the signals are not useful at all. and the other part of signals can be a simple a subscription over RPC.

mobile/status.go Outdated
var statusBackend = api.NewStatusBackend()

// All general log messages in this package should be routed through this logger.
var logger = log.New("package", "status-go/lib")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to keep the name of logger (lib part)?

)
errString := ""

defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this defer usage is so confusing. it definitely should be a simple function that accepts error and returns string

@divan
Copy link
Contributor Author

divan commented Sep 3, 2018

@dshulyak answering your comments here in bulk: this PR is "drop-in" replacement, I want to change as little as possible in the original implementation. So I guess the followup PR will be a rethinking the interface between status-go and react with gomobile in mind, and most of your comments will be for sure resolved there.

I'm not quite sure I understood the thread pool issue. Can you elaborate on it?

@dshulyak
Copy link
Contributor

dshulyak commented Sep 4, 2018

@divan so both versions of the app are running on a thread pool. but recently there were performance issues on android. after investigation it turned out that pool size was too small. i think it was set to the number of cpu cores (or a double of that). raising number of threads helped. i don't know details of those performance problems, but in current implementation there must be a peer pool in andoid/ios bindings. otherwise app won't work. cc @pombeirp in case he wants to provide more details

@pedropombeiro
Copy link
Contributor

pedropombeiro commented Sep 21, 2018

From a quick test, it seems that there are some open questions:

  • make statusgo-ios needs XCode to run, so we'd need to adapt the Makefiles to run each build on the appropriate host;
  • make statusgo-android needs some environment variables, so it can find things like the NDK. We need to think what the best way is to go around that. Right now the documentation doesn't reflect that (btw the documentation has moved to docs.status.im in develop).

xgo is not removed yet, because it's probably still needed for status-desktop (to confirm)

If we collectively decide that it is not absolutely required to be able to cross-compile iOS/MacOS libraries, then I'd definitely get rid of xgo, as otherwise I don't see much advantage in bringing gomobile to the equation.

@ghost
Copy link

ghost commented Sep 21, 2018

Pull Request Checklist

  • Have you updated the documentation, if impacted (e.g. docs.status.im)?

@divan
Copy link
Contributor Author

divan commented Sep 21, 2018

Thanks for feedback @pombeirp. So let's breakdown the problems we have:

  • Unclear if it's possible to make an iOS gomobile build on Linux machine (Jenkins/CI)
  • Lack of documentation of what to do when Android NDK is not installed

Is that correct?

Regarding the Android NDK: I had an assumption that gomobile init does all the needed checks and validations, so no further env variables needed to be specified, but I have to test this assumption.

@pedropombeiro
Copy link
Contributor

Yeah, that's correct. Although I'm quite sure that XCode doesn't run on anything but a Mac. When you mentioned the PR was ready for testing on the react side (pending being able to build status-react), I thought you had already tested the two types of builds to confirm that the libraries were generated correctly, but if I understand correctly, that still remains to be done, right?

@pedropombeiro
Copy link
Contributor

pedropombeiro commented Sep 25, 2018

As future context: I'm currently working on another PR which is meant to provide status-go static library artifacts to Status Desktop builds. I'm running into issues consuming the cross-compiled OSX library, so I'm starting to think that with the move to gomobile, we'll already be tied to OSX hosts anyway, so might as well stop relying on xgo altogether and ensure that we build OSX artifacts on OSX hosts. cc @jakubgs

@dmitryn
Copy link
Contributor

dmitryn commented Nov 6, 2018

I'm trying to make manual build with gomobile branch to integrate it into status-react, but CI fails with:
https://ci.status.im/job/status-go/job/status-go-manual/544/console

[status-go] Running shell script
+ make ci
lint
level=warning msg="[runner/megacheck] Can't run megacheck because of compilation errors in packages [github.com/status-im/status-go/mobile]: mobile/status.go:67: LoadNodeConfig not declared by package params and 6 more errors: run `golangci-lint run --no-config --disable-all -E typecheck` to see all errors"
mobile/status.go:67:19: LoadNodeConfig not declared by package params (typecheck)
	_, err := params.LoadNodeConfig(configJSON)
	                 ^
mobile/status.go:43:24: LoadNodeConfig not declared by package params (typecheck)
	config, err := params.LoadNodeConfig(configJSON)
	                      ^
mobile/status.go:28:47: cannot convert "" (untyped string constant) to uint64 (typecheck)
	config, err := params.NewNodeConfig(datadir, "", params.FleetBeta, uint64(networkID))
	                                             ^
Makefile:260: recipe for target 'lint' failed
make: *** [lint] Error 1
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE

@divan is there any instructions on how to build it?

@adambabik
Copy link
Contributor

This branch is just outdated as some packages in status-go changed.

@divan
Copy link
Contributor Author

divan commented Nov 6, 2018

I pushed the commit with rebase, please try now.

@dmitryn
Copy link
Contributor

dmitryn commented Nov 7, 2018

Failing:

[status-go-manual] Running shell script
+ go get github.com/status-im/xgo
[Pipeline] parallel
[Pipeline] [statusgo-android] { (Branch: statusgo-android)
[Pipeline] [statusgo-ios-simulator] { (Branch: statusgo-ios-simulator)
[Pipeline] [statusgo-android] dir
[statusgo-android] Running in /home/jenkins/workspace/status-go/status-go-manual/src/github.com/status-im/status-go
[Pipeline] [statusgo-android] {
[Pipeline] [statusgo-ios-simulator] dir
[statusgo-ios-simulator] Running in /home/jenkins/workspace/status-go/status-go-manual/src/github.com/status-im/status-go
[Pipeline] [statusgo-ios-simulator] {
[Pipeline] [statusgo-android] sh
[statusgo-android] [status-go] Running shell script
[statusgo-android] + make statusgo-android
[Pipeline] [statusgo-ios-simulator] sh
[statusgo-android] Installing gomobile...
[statusgo-ios-simulator] [status-go] Running shell script
[statusgo-ios-simulator] + make statusgo-ios-simulator
[statusgo-ios-simulator] make: *** No rule to make target 'statusgo-ios-simulator'.  Stop.
[Pipeline] [statusgo-ios-simulator] }
[Pipeline] [statusgo-ios-simulator] // dir
[Pipeline] [statusgo-ios-simulator] }
[statusgo-ios-simulator] Failed in branch statusgo-ios-simulator
[statusgo-android] Building status-go for Android...
[statusgo-android] gomobile: no Android NDK path is set. Please run gomobile init with the ndk-bundle installed through the Android SDK manager or with the -ndk flag set.
[statusgo-android] Makefile:118: recipe for target 'statusgo-android' failed
[statusgo-android] make: *** [statusgo-android] Error 1
[Pipeline] [statusgo-android] }
[Pipeline] [statusgo-android] // dir
[Pipeline] [statusgo-android] }
[statusgo-android] Failed in branch statusgo-android
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE

https://ci.status.im/job/status-go/job/status-go-manual/545/console

@divan
Copy link
Contributor Author

divan commented Nov 8, 2018

@dmitryn hmm, so Makefile should have gomobile init command to prepare CI environment. Can you manually put this command to pipeline before Makefile is executing?

@dmitryn
Copy link
Contributor

dmitryn commented Nov 9, 2018

@divan I've added gomobile init before make statusgo-android and make statusgo-ios-simulator, but it didn't help

+ go get github.com/status-im/xgo
[Pipeline] parallel
[Pipeline] [statusgo-android] { (Branch: statusgo-android)
[Pipeline] [statusgo-ios-simulator] { (Branch: statusgo-ios-simulator)
[Pipeline] [statusgo-android] dir
[statusgo-android] Running in /home/jenkins/workspace/status-go/status-go-manual/src/github.com/status-im/status-go
[Pipeline] [statusgo-android] {
[Pipeline] [statusgo-ios-simulator] dir
[statusgo-ios-simulator] Running in /home/jenkins/workspace/status-go/status-go-manual/src/github.com/status-im/status-go
[Pipeline] [statusgo-ios-simulator] {
[Pipeline] [statusgo-android] sh
[statusgo-android] [status-go] Running shell script
[statusgo-android] + gomobile init
[Pipeline] [statusgo-ios-simulator] sh
[statusgo-ios-simulator] [status-go] Running shell script
[statusgo-ios-simulator] + sh gomobile init
[statusgo-ios-simulator] sh: 0: Can't open gomobile init
[Pipeline] [statusgo-ios-simulator] }
[Pipeline] [statusgo-ios-simulator] // dir
[Pipeline] [statusgo-ios-simulator] }
[statusgo-ios-simulator] Failed in branch statusgo-ios-simulator
[Pipeline] [statusgo-android] sh
[statusgo-android] [status-go] Running shell script
[statusgo-android] + make statusgo-android
[statusgo-android] Installing gomobile...
[statusgo-android] Building status-go for Android...
[statusgo-android] gomobile: no Android NDK path is set. Please run gomobile init with the ndk-bundle installed through the Android SDK manager or with the -ndk flag set.
[statusgo-android] Makefile:118: recipe for target 'statusgo-android' failed
[statusgo-android] make: *** [statusgo-android] Error 1
[Pipeline] [statusgo-android] }
[Pipeline] [statusgo-android] // dir
[Pipeline] [statusgo-android] }
[statusgo-android] Failed in branch statusgo-android
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

@divan
Copy link
Contributor Author

divan commented Nov 9, 2018

@dmitryn that's because sh gomobile init failed – sh seems to expect sh script as an input, not the command itself.

@ghost
Copy link

ghost commented Nov 23, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@ghost ghost added the stale label Nov 23, 2018
@jakubgs jakubgs force-pushed the gomobile branch 4 times, most recently from d7b5267 to 49b3335 Compare February 1, 2019 09:42
Signed-off-by: Jakub Sokołowski <jakub@status.im>
@mandrigin
Copy link
Contributor

android: works

@mandrigin
Copy link
Contributor

iOS: works.

@mandrigin mandrigin merged commit 4f3f5ee into develop Feb 1, 2019
@delete-merged-branch delete-merged-branch bot deleted the gomobile branch February 1, 2019 17:02
@mandrigin
Copy link
Contributor

thanks @divan for starting it!
@adambabik for wrapping it up!
@jakubgs for fighting dear god scary nightmares of Jenkins!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants