Skip to content

Add iOS build with bls #528

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

Merged
merged 30 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8cfa907
iOS changes
cmcewen Jun 17, 2019
5ce82b7
Merge branch 'master' into cmcewen/ios
cmcewen Aug 15, 2019
da88d4c
Compile on bls on ios
cmcewen Aug 15, 2019
5d0de52
Fix build
cmcewen Aug 15, 2019
738b8aa
Fix npm publishing
cmcewen Aug 16, 2019
f16308b
Fix podspec
cmcewen Aug 16, 2019
a36e3a0
Merge branch 'master' into cmcewen/ios
cmcewen Sep 2, 2019
2d1d8ca
Postinstall
cmcewen Sep 2, 2019
fa533cb
Fix cargo-lipo check
jeanregisser Oct 9, 2019
902f334
Patch gomobile to disable bitcode for now since the rust ouput is not…
jeanregisser Oct 9, 2019
22e0e43
Generate all archs for ios (armv7, arm64, i386, x86_64)
jeanregisser Oct 9, 2019
c8adc6a
Merge remote-tracking branch 'origin/master' into cmcewen/ios
jeanregisser Oct 9, 2019
4a466e0
Expose ipc path config
jeanregisser Oct 11, 2019
73653b2
Don't build bls for armv7s since it's not used in the final framework
jeanregisser Oct 11, 2019
084b2de
Restore original package version
jeanregisser Oct 11, 2019
2a69428
Zip iOS framework
jeanregisser Oct 11, 2019
33ecf24
Fix postinstall failing when geth framework has already been unzipped
jeanregisser Oct 11, 2019
bb1ed1f
Make iOS podspec compatible with use_frameworks!
jeanregisser Oct 14, 2019
42caff5
Remove empty line
jeanregisser Oct 14, 2019
4498015
Restore crate-type
jeanregisser Oct 14, 2019
2dba9f4
Ignore ndk_bundle dir
jeanregisser Oct 14, 2019
691d471
Merge remote-tracking branch 'origin/master' into cmcewen/ios
jeanregisser Oct 14, 2019
4227e14
Restore bls darwin linking flags
jeanregisser Oct 14, 2019
b804fd1
Remove space
jeanregisser Oct 16, 2019
eb12e5a
Remove more space
jeanregisser Oct 16, 2019
e81436d
Installing cargo-lipo for the user when necessary
jeanregisser Oct 16, 2019
d2127b7
Update package info
jeanregisser Oct 16, 2019
6ab3809
Merge remote-tracking branch 'origin/master' into cmcewen/ios
jeanregisser Oct 16, 2019
d52fd6b
Move podspec prepare command to package postinstall
jeanregisser Oct 18, 2019
f77b6d9
Merge remote-tracking branch 'origin/master' into cmcewen/ios
jeanregisser Oct 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target
/build/bin/*
!/build/bin/geth.aar
/geth*.zip
ndk_bundle

# travis
profile.tmp
Expand Down
16 changes: 16 additions & 0 deletions CeloBlockchain.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = 'CeloBlockchain'
s.version = package['version']
s.license = package['license']
s.homepage = package['homepage']
s.authors = { 'Connor McEwen' => '[email protected]' }
s.summary = package['description']
s.source = { :git => package['repository']['url'], :tag => s.version }
s.source_files = 'build/bin/Geth.framework/**/*.h', 'Empty.m'
s.vendored_libraries = 'libGeth.a', 'vendor/github.com/celo-org/bls-zexe/bls/target/universal/release/libbls_zexe.a'
s.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '-ObjC' }
end
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GO ?= latest

CARGO_exists := $(shell command -v cargo 2> /dev/null)
RUSTUP_exists := $(shell command -v rustup 2> /dev/null)
CARGO_LIPO_exists := $(shell command -v cargo-lipo 2> /dev/null)
LSB_exists := $(shell command -v lsb_release 2> /dev/null)

OS :=
Expand Down Expand Up @@ -86,6 +87,17 @@ else
cd vendor/github.com/celo-org/bls-zexe/bls && cargo build --release --target=x86_64-linux-android --lib
endif

bls-zexe-ios:
ifeq ("$(RUSTUP_exists)","")
$(error "No rustup in PATH, consult https://github.com/celo-org/celo-monorepo/blob/master/SETUP.md")
else
ifeq ("$(CARGO_LIPO_exists)","")
cargo install cargo-lipo
endif
rustup target add aarch64-apple-ios armv7-apple-ios x86_64-apple-ios i386-apple-ios
cd vendor/github.com/celo-org/bls-zexe/bls && cargo lipo --release --targets=aarch64-apple-ios,armv7-apple-ios,x86_64-apple-ios,i386-apple-ios
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there an endif missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question 👍 this syntax works but someone mentions it's failing with GNU Make 3.80:
https://stackoverflow.com/a/12297193/158525

My machine has GNU Make 3.81 which was first released in 2006.
I think we're safe, but let me know if you still wanna change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I just changed the structure anyway so no questions about this anymore :D


vendor/github.com/celo-org/bls-zexe/bls/target/release/libbls_zexe.a:
ifeq ("$(CARGO_exists)","")
$(error "No cargo in PATH, consult https://github.com/celo-org/celo-monorepo/blob/master/SETUP.md")
Expand All @@ -106,8 +118,9 @@ android: bls-zexe-android
@echo "Done building."
@echo "Import \"$(GOBIN)/geth.aar\" to use the library."

ios:
ios: bls-zexe-ios
build/env.sh go run build/ci.go xcode --local
pushd "$(GOBIN)"; rm -rf Geth.framework.zip; zip -r9y Geth.framework.zip Geth.framework; popd
@echo "Done building."
@echo "Import \"$(GOBIN)/Geth.framework\" to use the library."

Expand Down
2 changes: 2 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@ func doXCodeFramework(cmdline []string) {

// Build the iOS XCode framework
build.MustRun(goTool("get", "golang.org/x/mobile/cmd/gomobile", "golang.org/x/mobile/cmd/gobind"))
// Patch gomobile to disable bitcode for now (rust generated bls lib output is not compatible)
build.MustRunCommand("sed", "-i", "", `/^[[:space:]]*cflags += \" -fembed-bitcode\"$/s/^/\/\//`, filepath.Join(build.GOPATH(), "src/golang.org/x/mobile/cmd/gomobile/env.go"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Too bad it doesn't work :(
Can you try with Rust 1.37? I'm upgrading the build toolchain to that anyway. Seems like people succeeded with recent nightlies, so it might work there: rust-lang/rust#35968 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried with Rust 1.38 stable and 1.40.0-nightly (2748a9fd9 2019-10-08).
Both failed to link with gomobile when bitcode was enabled (Xcode 10.3). Though the generated rust lib do contain bitcode markers.

bind := gomobileTool("bind", "-ldflags", "-s -w", "--target", "ios", "--tags", "ios", "-v", "github.com/ethereum/go-ethereum/mobile")

if *local {
Expand Down
8 changes: 7 additions & 1 deletion mobile/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ type NodeConfig struct {
// scrypt KDF at the expense of security.
// See https://geth.ethereum.org/doc/Mobile_Account-management for reference
UseLightweightKDF bool

// IPCPath is the requested location to place the IPC endpoint. If the path is
// a simple file name, it is placed inside the data directory (or on the root
// pipe path on Windows), whereas if it's a resolvable path name (absolute or
// relative), then that specific path is enforced. An empty path disables IPC.
IPCPath string
}

// defaultNodeConfig contains the default node configuration values to use if all
Expand Down Expand Up @@ -145,7 +151,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
DataDir: datadir,
KeyStoreDir: filepath.Join(datadir, "keystore"), // Mobile should never use internal keystores!
UseLightweightKDF: config.UseLightweightKDF,
IPCPath: "geth.ipc",
IPCPath: config.IPCPath,
P2P: p2p.Config{
NoDiscovery: true,
DiscoveryV5: false,
Expand Down
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
"name": "@celo/client",
"version": "0.0.1",
"description": "Celo client for mobile",
"homepage": "https://celo.org",
"repository": {
"type": "git",
"url": "https://github.com/celo-org/celo-blockchain.git"
},
"license": "LGPL-3.0",
"files": [
"build/bin/geth.aar"
]
"build/bin/geth.aar",
"build/bin/Geth.framework.zip",
"CeloBlockchain.podspec",
"vendor/github.com/celo-org/bls-zexe/bls/target/universal/release/libbls_zexe.a"
],
"scripts": {
"postinstall": "rm -rf build/bin/Geth.framework && unzip build/bin/Geth.framework.zip -d build/bin && touch Empty.m && ln -sf build/bin/Geth.framework/Versions/A/Geth libGeth.a"
}
}
8 changes: 8 additions & 0 deletions vendor/github.com/celo-org/bls-zexe/go/bls_ios.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.