diff --git a/Dockerfile b/Dockerfile index 77f7dd4..e5e3b8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,43 @@ FROM ubuntu:18.04 -# CUSTOM VARIABLES -ENV GOLANG=go1.13.5.linux-amd64.tar.gz - # ENV VARIABLES +ENV GOLANG=go1.13.5.linux-amd64.tar.gz ENV GOROOT=/usr/local/go ENV GOPATH=/native/altbn128 ENV GOBIN=$GOPATH/bin -ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 ENV CGO_CFLAGS="-I$JAVA_HOME/include -I$JAVA_HOME/include/linux" +ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH + +# DEPENDENCIES -RUN apt-get update && \ - apt-get -y install git && \ - apt-get -y install tree && \ - apt-get install -y -o APT::Install-Suggests="false" git curl openjdk-8-jdk build-essential=12.4ubuntu1 && \ - apt-get install -y -o APT::Install-Suggests="true" autoconf && \ - curl "https://dl.google.com/go/"$GOLANG -o $GOLANG -# && \ - echo "512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569 go1.13.5.linux-amd64.tar.gz" > goChecksum.txt && \ +# common +RUN apt-get update +RUN apt-get install -y build-essential +RUN apt-get install -y -o APT::Install-Suggests="false" git tree curl openjdk-8-jdk + +# secp25k1 dependencies +RUN apt-get install -y autoconf libtool + +# altbn128 dependencies +RUN curl "https://dl.google.com/go/"$GOLANG -o $GOLANG -# && \ + echo "512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569 $GOLANG" > goChecksum.txt && \ cat goChecksum.txt && \ sha256sum -c goChecksum.txt && \ - tar -xvf $GOLANG && mkdir -p $GOCUSTOM && mv go $GOCUSTOM -RUN curl "https://sh.rustup.rs" -sSf | bash -s -- -y + tar -xvf $GOLANG && \ + mkdir -p /usr/local && \ + mv go /usr/local - -#Cloning native's repo -#RUN git clone https://github.com/rsksmart/native.git +# bls12-381 dependencies +RUN curl "https://sh.rustup.rs" -sSf | bash -s -- -y +RUN apt-get install -y clang gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev wget cmake libxml2-dev libssl-dev gcc-mingw-w64-x86-64 +RUN git clone https://github.com/tpoechtrager/osxcross && \ + cd osxcross && \ + wget -nc https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz&& \ + mv MacOSX10.10.sdk.tar.xz tarballs/ && \ + UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh + +# Cloning native's repo COPY . /native WORKDIR /native @@ -36,4 +48,3 @@ RUN cp -r jniheaders/include $JAVA_HOME WORKDIR /native ENTRYPOINT ["./gradlew"] CMD ["buildProject"] - diff --git a/README.md b/README.md index 7ba7386..7f46f80 100644 --- a/README.md +++ b/README.md @@ -6,25 +6,24 @@ In this project you'll find all the native libraries used in rskj. - altbn128 - [secp256k1](secp256k1/README.md) +- [bls12-381](bls12_381/README.md) -## Build - -Currently productive build will only compile for linux systems (but every build command is mac compatilble). -Mac support for productive env will be added in future releases. -### Productive +### Compatibility -```bash -> docker build -t native-libs . -> docker run --rm -v $(pwd)/build:/native/build native-libs -``` +| Library | Linux | Mac OS | Windows (x64) | +| ------------- |:-------------:| :--------:| :-------:| +| altbn128 | x | | | +| secp256k1 | x | | | +| bls12-381 | x | x | x | -### Dev +## Build -Build every library and wrap them into native.jar +Builds each library, runs all the tests (only for linux) and bundles `native-x.y.z.jar` ```bash -> ./gradlew buildProject +> docker build -t native-libs . +> docker run --rm -v $(pwd)/build:/native/build native-libs ``` ## Build a Specific Library @@ -40,26 +39,29 @@ To build an specific library > ./gradlew buildSecp256k1 -# bls12-381 (req: cargo) +# bls12-381 (req: rust) > ./gradlew buildBls12_381 ``` ## Checksums -``` -libbn128.so: 669543be939058001ffb5ca3b816d3961f39db82dad60dfd0ffc89540956dc6f +```bash +# altbn128 +libbn128.so: ee41baa43b5a3927e99c2d0f826666e5baf2885ec0d689ea3c591db35ad9ae47 + +# secp256k1 libsecp256k1.so: 0b99909b0c86b3f4bcad90f70eef81d7b5fd77f7d29997195b3291526e5cd7f0 -libeth_pairings.so: 2a1d00f77ce59c4cede20a354cf523dd81a1bfc80a68ad0ea70322b420a88908 -native-1.2.1.jar: b1357a0619596d496d01b095ceb45819337b0ee457b9df9cef4144ed560ea715 + +# bls12-381 +libeth_pairings.so: da214a3c3d66b057a6d3636161da977fdd8dee638a82919e86c18a6137ca0d04 +eth_pairings.dll: bb78b4dbfbf12bdb4daff1acbd682c3df9da2d7c755bc776808d634889e5d6f0 + +native-1.3.0.jar: 58e707310e43f16e3e238469c26a777bc8ad4e3b3d0f7baf9a89ec881e53a1c5 go1.13.5.linux-amd64.tar.gz: 512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569 $ java -version -openjdk version "1.8.0_265" -OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~18.04-b01) -OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode) +openjdk version "1.8.0_275" +OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~18.04-b01) +OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode) ``` - -## Disclaimer - -Experimental/dev features should only be used under your own risk. diff --git a/bls12_381/.cargo/config b/bls12_381/.cargo/config new file mode 100644 index 0000000..4727075 --- /dev/null +++ b/bls12_381/.cargo/config @@ -0,0 +1,3 @@ +[target.x86_64-apple-darwin] +linker = "x86_64-apple-darwin14-clang" +ar = "x86_64-apple-darwin14-ar" \ No newline at end of file diff --git a/bls12_381/build.sh b/bls12_381/build.sh index 1c5fc42..62d5412 100755 --- a/bls12_381/build.sh +++ b/bls12_381/build.sh @@ -1,15 +1,33 @@ #!/bin/bash +JAVA_BLS_RESOURCES="/native/src/main/resources/co/rsk/bls12_381" +PATH="/osxcross/target/bin:$PATH" PATH="$HOME/.cargo/bin:$PATH" # delete old build dir, if exists rm -rf "target/" && \ -rm -rf "/native/src/main/resources/co/rsk/bls12_381" || true && \ -mkdir -p "/native/src/main/resources/co/rsk/bls12_381" && \ +rm -rf $JAVA_BLS_RESOURCES && \ +mkdir -p $JAVA_BLS_RESOURCES && \ +mkdir $JAVA_BLS_RESOURCES/macos && \ +mkdir $JAVA_BLS_RESOURCES/linux && \ +mkdir $JAVA_BLS_RESOURCES/win && \ -# clean & build bls12-381 +# clean & build bls12-381 (linux) +rustup target add x86_64-unknown-linux-gnu && \ +rustup toolchain install stable-x86_64-unknown-linux-gnu && \ cargo clean && \ -cargo build --lib --features eip_2357_c_api --release && \ +cargo build --lib --features eip_2357_c_api --release --target x86_64-unknown-linux-gnu && \ +cp target/x86_64-unknown-linux-gnu/release/libeth_pairings.so $JAVA_BLS_RESOURCES/linux &&\ -# move to resources -cp target/release/libeth_pairings.so "/native/src/main/resources/co/rsk/bls12_381" +# clean & build bls12-381 (windows 64 bits) +rustup target add x86_64-pc-windows-gnu && \ +rustup toolchain install stable-x86_64-pc-windows-gnu && \ +cargo clean && \ +cargo build --lib --features eip_2357_c_api --release --target x86_64-pc-windows-gnu && \ +cp target/x86_64-pc-windows-gnu/release/eth_pairings.dll $JAVA_BLS_RESOURCES/win + +# clean & build bls12-381 (mac) - toolchain: osxcross +rustup target add x86_64-apple-darwin && \ +cargo clean && \ +cargo build --lib --features eip_2357_c_api --release --target x86_64-apple-darwin && \ +cp target/x86_64-apple-darwin/release/libeth_pairings.dylib $JAVA_BLS_RESOURCES/macos \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6b25b99..e07625a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ import java.util.jar.JarFile import java.util.jar.JarOutputStream group 'co.rsk' -version '1.2.0' +version '1.3.0' buildscript { repositories {