Skip to content

Commit ee42d04

Browse files
authored
Add Linux ARM64 native support (#61)
arm64 linux support Signed-off-by: garyschulte <garyschulte@gmail.com>
1 parent c9ce066 commit ee42d04

File tree

11 files changed

+163
-60
lines changed

11 files changed

+163
-60
lines changed

.circleci/config.yml

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ executors:
1616
environment:
1717
GRADLE_OPTS: -Xmx2048m -Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=2
1818
HOMEBREW_NO_AUTO_UPDATE: true
19+
besu_executor_med_linux_arm64: # 2cpu, 8G ram
20+
machine:
21+
image: ubuntu-2004:current
22+
resource_class: arm.medium
23+
working_directory: ~/project
24+
environment:
25+
architecture: "arm64"
26+
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=2
27+
1928
# besu_executor_med_windows: # 2cpu, 4G ram
2029
# machine:
2130
# image: "windows-server-2019-vs2019:stable"
@@ -78,36 +87,75 @@ jobs:
7887
- persist_to_workspace:
7988
root: .
8089
paths:
81-
- altbn128/build/lib/*.so*
82-
- bls12-381/build/lib/*.so*
83-
- secp256k1/build/lib/*.so*
84-
- ipa-multipoint/build/lib/*.so
85-
- secp256r1/besu-native-ec/release/*.so
90+
- altbn128/build/linux-gnu-x86_64/lib/*.so*
91+
- bls12-381/build/linux-gnu-x86_64/lib/*.so*
92+
- secp256k1/build/linux-gnu-x86_64/lib/*.so*
93+
- ipa-multipoint/build/linux-gnu-x86_64/lib/*.so
94+
- secp256r1/besu-native-ec/release/linux-gnu-x86_64/*.so
8695
- store_artifacts:
8796
name: Linux altbn128 native build artifacts
88-
path: altbn128/build/lib
97+
path: altbn128/build/linux-gnu-x86_64/lib
8998
destination: altbn128_linux_x86_64_native_artifacts
9099
when: always
91100
- store_artifacts:
92101
name: Linux bls12-381 native build artifacts
93-
path: bls12-381/build/lib
102+
path: bls12-381/build/linux-gnu-x86_64/lib
94103
destination: bls12_381_linux_x86_64_native_artifacts
95104
when: always
96105
- store_artifacts:
97106
name: Linux secp256k1 native build artifacts
98-
path: secp256k1/build/lib
107+
path: secp256k1/build/linux-gnu-x86_64/lib
99108
destination: secp256k1_linux_x86_64_native_artifacts
100109
when: always
101110
- store_artifacts:
102111
name: Linux secp256r1 native build artifacts
103-
path: secp256r1/besu-native-ec/release
112+
path: secp256r1/besu-native-ec/release/linux-gnu-x86_64
104113
destination: secp256r1_linux_x86_64_native_artifacts
105114
when: always
106115
- store_artifacts:
107116
name: Linux ipa-multipoint native build artifacts
108-
path: ipa-multipoint/build/lib
117+
path: ipa-multipoint/build/linux-gnu-x86_64/lib
109118
destination: ipa_multipoint_linux_x86_64_native_artifacts
110119
when: always
120+
121+
native-build-linux-aarch64:
122+
executor: besu_executor_med_linux_arm64
123+
environment:
124+
SKIP_GRADLE: true
125+
steps:
126+
- checkout_code
127+
- prepare_linux
128+
- run:
129+
name: build
130+
command: |
131+
./build.sh
132+
- persist_to_workspace:
133+
root: .
134+
paths:
135+
- altbn128/build/linux-gnu-aarch64/lib/*.so*
136+
- secp256k1/build/linux-gnu-aarch64/lib/*.so*
137+
- ipa-multipoint/build/linux-gnu-aarch64/lib/*.so
138+
- secp256r1/besu-native-ec/release/linux-gnu-aarch64/*.so
139+
- store_artifacts:
140+
name: Linux altbn128 native build artifacts
141+
path: altbn128/build/linux-gnu-aarch64/lib
142+
destination: altbn128_linux_aarch64_native_artifacts
143+
when: always
144+
- store_artifacts:
145+
name: Linux secp256k1 native build artifacts
146+
path: secp256k1/build/linux-gnu-aarch64/lib
147+
destination: secp256k1_linux_aarch64_native_artifacts
148+
when: always
149+
- store_artifacts:
150+
name: Linux secp256r1 native build artifacts
151+
path: secp256r1/besu-native-ec/release/linux-gnu-aarch64
152+
destination: secp256r1_linux_aarch64_native_artifacts
153+
when: always
154+
- store_artifacts:
155+
name: Linux ipa-multipoint native build artifacts
156+
path: ipa-multipoint/build/linux-gnu-aarch64/lib
157+
destination: ipa_multipoint_linux_aarch64_native_artifacts
158+
when: always
111159
native-build-macos:
112160
executor: besu_executor_med_macos
113161
environment:
@@ -122,34 +170,34 @@ jobs:
122170
- persist_to_workspace:
123171
root: .
124172
paths:
125-
- altbn128/build/lib/*.*dylib*
126-
- bls12-381/build/lib/*.*dylib*
127-
- secp256k1/build/lib/*.*dylib*
128-
- ipa-multipoint/build/lib/*.dylib
129-
- secp256r1/besu-native-ec/release/*.dylib
173+
- altbn128/build/darwin/lib/*.*dylib*
174+
- bls12-381/build/darwin/lib/*.*dylib*
175+
- secp256k1/build/darwin/lib/*.*dylib*
176+
- ipa-multipoint/build/darwin/lib/*.dylib
177+
- secp256r1/besu-native-ec/release/darwin/*.dylib
130178
- store_artifacts:
131179
name: macOS altbn128 native build artifacts
132-
path: altbn128/build/lib
180+
path: altbn128/build/darwin/lib
133181
destination: altbn128_macOS_native_artifacts
134182
when: always
135183
- store_artifacts:
136184
name: macOS bls12-381 native build artifacts
137-
path: bls12-381/build/lib
185+
path: bls12-381/build/darwin/lib
138186
destination: bls12_381_macOS_native_artifacts
139187
when: always
140188
- store_artifacts:
141189
name: macOS secp256k1 native build artifacts
142-
path: secp256k1/build/lib
190+
path: secp256k1/build/darwin/lib
143191
destination: secp256k1_macOS_native_artifacts
144192
when: always
145193
- store_artifacts:
146194
name: macOS secp256r1 native build artifacts
147-
path: secp256r1/besu-native-ec/release
195+
path: secp256r1/besu-native-ec/release/darwin
148196
destination: secp256r1_macOS_native_artifacts
149197
when: always
150198
- store_artifacts:
151199
name: macOS ipa-multipoint native build artifacts
152-
path: ipa-multipoint/build/lib
200+
path: ipa-multipoint/build/darwin/lib
153201
destination: ipa_multipoint_macOS_native_artifacts
154202
when: always
155203
final-assembly:
@@ -210,10 +258,12 @@ workflows:
210258
default:
211259
jobs:
212260
- native-build-linux-x86-64
261+
- native-build-linux-aarch64
213262
- native-build-macos
214263
- final-assembly:
215264
requires:
216265
- native-build-linux-x86-64
266+
- native-build-linux-aarch64
217267
- native-build-macos
218268
- publish:
219269
filters:

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
# 0.4.4 (not released yet)
3+
# 0.5.0 (not released yet)
44

5+
* Add linux-arm64 native support [#61](https://github.com/hyperledger/besu-native/pull/61)
56
* Add ipa-multipoint library support [#56](https://github.com/hyperledger/besu-native/pull/56)
67

78

altbn128/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,26 @@ dependencies {
2424
}
2525

2626
task macLibCopy(type: Copy) {
27-
from 'build/lib/libeth_altbn128.dylib'
27+
from 'build/darwin/lib/libeth_altbn128.dylib'
2828
into 'build/resources/main/darwin'
2929
}
3030
jar.dependsOn macLibCopy
3131

3232
task linuxLibCopy(type: Copy) {
33-
from 'build/lib/libeth_altbn128.so'
33+
from 'build/linux-gnu-x86_64/lib/libeth_altbn128.so'
3434
into 'build/resources/main/linux-x86-64'
3535
}
3636
jar.dependsOn linuxLibCopy
3737

38+
task linuxArm64LibCopy(type: Copy) {
39+
from 'build/linux-gnu-aarch64/lib/libeth_altbn128.so'
40+
into 'build/resources/main/linux-aarch64'
41+
}
42+
jar.dependsOn linuxArm64LibCopy
43+
3844
jar {
3945
archiveBaseName = 'besu-native-altbn128'
46+
includeEmptyDirs = false
4047
manifest {
4148
attributes(
4249
'Specification-Title': archiveBaseName,

altbn128/sputnikvm_altbn128/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ edition = "2018"
1010
[dependencies]
1111
ethereum-bigint = { version = "0.2", default-features = false }
1212
bn-plus = { version = "0.4.4" }
13+
libc = "0.2"
1314

1415
[lib]
1516
name = "eth_altbn128"

altbn128/sputnikvm_altbn128/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ pub extern "C" fn altbn128_add_precompiled(
1717
o: *mut ::std::os::raw::c_char,
1818
o_len: *mut u32,
1919
) -> u32 {
20-
let input_i8: &[i8] = unsafe { std::slice::from_raw_parts(i, i_len as usize) };
20+
let input_i8: &[libc::c_char] = unsafe { std::slice::from_raw_parts(i, i_len as usize) };
2121
let input: &[u8] = unsafe { std::mem::transmute(input_i8) };
2222

23-
let raw_out_i8: &mut [i8] = unsafe { std::slice::from_raw_parts_mut(o, o_len as usize) };
23+
let raw_out_i8: &mut [libc::c_char] = unsafe { std::slice::from_raw_parts_mut(o, o_len as usize) };
2424
let mut raw_out: &mut [u8] = unsafe { std::mem::transmute(raw_out_i8) };
2525

2626
return match altbn128_add_precompiled_impl(input) {
@@ -88,10 +88,10 @@ pub extern "C" fn altbn128_mul_precompiled(
8888
o: *mut ::std::os::raw::c_char,
8989
o_len: *mut u32,
9090
) -> u32 {
91-
let input_i8: &[i8] = unsafe { std::slice::from_raw_parts(i, i_len as usize) };
91+
let input_i8: &[libc::c_char] = unsafe { std::slice::from_raw_parts(i, i_len as usize) };
9292
let input: &[u8] = unsafe { std::mem::transmute(input_i8) };
9393

94-
let raw_out_i8: &mut [i8] = unsafe { std::slice::from_raw_parts_mut(o, o_len as usize) };
94+
let raw_out_i8: &mut [libc::c_char] = unsafe { std::slice::from_raw_parts_mut(o, o_len as usize) };
9595
let mut raw_out: &mut [u8] = unsafe { std::mem::transmute(raw_out_i8) };
9696

9797
return match altbn128_mul_precompiled_impl(input) {
@@ -151,10 +151,10 @@ pub extern "C" fn altbn128_pairing_precompiled(
151151
o: *mut ::std::os::raw::c_char,
152152
o_len: *mut u32,
153153
) -> u32 {
154-
let input_i8: &[i8] = unsafe { std::slice::from_raw_parts(i, i_len as usize) };
154+
let input_i8: &[libc::c_char] = unsafe { std::slice::from_raw_parts(i, i_len as usize) };
155155
let input: &[u8] = unsafe { std::mem::transmute(input_i8) };
156156

157-
let raw_out_i8: &mut [i8] = unsafe { std::slice::from_raw_parts_mut(o, o_len as usize) };
157+
let raw_out_i8: &mut [libc::c_char] = unsafe { std::slice::from_raw_parts_mut(o, o_len as usize) };
158158
let mut raw_out: &mut [u8] = unsafe { std::mem::transmute(raw_out_i8) };
159159

160160
return match altbn128_pairing_precompiled_impl(input) {

bls12-381/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ dependencies {
2828
}
2929

3030
task macLibCopy(type: Copy) {
31-
from 'build/lib/libeth_pairings.dylib'
31+
from 'build/darwin/lib/libeth_pairings.dylib'
3232
into 'build/resources/main/darwin'
3333
}
3434
jar.dependsOn macLibCopy
3535

3636
task linuxLibCopy(type: Copy) {
37-
from 'build/lib/libeth_pairings.so'
37+
from 'build/linux-gnu-x86_64/lib/libeth_pairings.so'
3838
into 'build/resources/main/linux-x86-64'
3939
}
4040
jar.dependsOn linuxLibCopy
4141

4242
jar {
4343
archiveBaseName = 'besu-native-bls12-381'
44+
includeEmptyDirs = false
4445
manifest {
4546
attributes(
4647
'Specification-Title': archiveBaseName,

build.sh

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
3434
done
3535
SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
3636

37-
3837
# Determine core count for parallel make
3938
if [[ "$OSTYPE" == "linux-gnu" ]]; then
4039
CORE_COUNT=$(nproc)
40+
OSARCH=${OSTYPE%%[0-9.]*}-`arch`
4141
fi
4242

4343
if [[ "$OSTYPE" == "darwin"* ]]; then
4444
export CFLAGS="-arch x86_64 -arch arm64"
4545
CORE_COUNT=$(sysctl -n hw.ncpu)
46+
OSARCH="darwin"
4647
fi
4748

4849
# add to path cargo
@@ -67,7 +68,7 @@ EOF
6768
fi
6869

6970
./autogen.sh && \
70-
./configure --prefix="$SCRIPTDIR/secp256k1/build" $SECP256K1_BUILD_OPTS && \
71+
./configure --prefix="$SCRIPTDIR/secp256k1/build/${OSARCH}" $SECP256K1_BUILD_OPTS && \
7172
make -j $CORE_COUNT && \
7273
make -j $CORE_COUNT install
7374
}
@@ -93,7 +94,8 @@ EOF
9394
cargo build --lib --release
9495
fi
9596

96-
cp target/release/libeth_altbn128.* "$SCRIPTDIR/altbn128/build/lib"
97+
mkdir -p "$SCRIPTDIR/altbn128/build/${OSARCH}/lib"
98+
cp target/release/libeth_altbn128.* "$SCRIPTDIR/altbn128/build/${OSARCH}/lib"
9799
}
98100

99101
build_ipa_multipoint() {
@@ -107,7 +109,7 @@ EOF
107109

108110
# delete old build dir, if exists
109111
rm -rf "$SCRIPTDIR/ipa-multipoint/build" || true
110-
mkdir -p "$SCRIPTDIR/ipa-multipoint/build/lib"
112+
mkdir -p "$SCRIPTDIR/ipa-multipoint/build/${OSARCH}/lib"
111113

112114
cargo clean
113115

@@ -117,7 +119,8 @@ EOF
117119
cargo build --lib --release
118120
fi
119121

120-
cp target/release/libipa_multipoint_jni.* "$SCRIPTDIR/ipa-multipoint/build/lib"
122+
mkdir -p "$SCRIPTDIR/ipa-multipoint/build/${OSARCH}/lib"
123+
cp target/release/libipa_multipoint_jni.* "$SCRIPTDIR/ipa-multipoint/build/${OSARCH}/lib"
121124
}
122125

123126
build_bls12_381() {
@@ -127,19 +130,26 @@ build_bls12_381() {
127130
#############################
128131
EOF
129132

130-
cd "$SCRIPTDIR/bls12-381/matterlabs-eip1962"
131-
132-
# delete old build dir, if exists
133-
rm -rf "$SCRIPTDIR/bls12-381/build" || true
134-
mkdir -p "$SCRIPTDIR/bls12-381/build/lib"
135-
136-
cargo clean
137-
if [[ "$OSTYPE" == "darwin"* ]]; then
138-
lipo_lib "libeth_pairings" "--features eip_2357_c_api"
133+
if [[ "${OSARCH}" != "linux-gnu-aarch64" ]]; then
134+
echo "building bls12-381 for ${OSARCH}"
135+
cd "$SCRIPTDIR/bls12-381/matterlabs-eip1962"
136+
137+
# delete old build dir, if exists
138+
rm -rf "$SCRIPTDIR/bls12-381/build" || true
139+
mkdir -p "$SCRIPTDIR/bls12-381/build/${OSARCH}/lib"
140+
141+
cargo clean
142+
if [[ "$OSTYPE" == "darwin"* ]]; then
143+
lipo_lib "libeth_pairings" "--features eip_2357_c_api"
144+
else
145+
cargo build --lib --features eip_2357_c_api --release
146+
fi
147+
mkdir -p "$SCRIPTDIR/bls12-381/build/${OSARCH}/lib"
148+
cp target/release/libeth_pairings.* "$SCRIPTDIR/bls12-381/build/${OSARCH}/lib"
139149
else
140-
cargo build --lib --features eip_2357_c_api --release
150+
echo "skipping bls12-381 on ${OSARCH}"
141151
fi
142-
cp target/release/libeth_pairings.* "$SCRIPTDIR/bls12-381/build/lib"
152+
143153
}
144154

145155
build_jars(){
@@ -217,12 +227,19 @@ EOF
217227
lipo -info ./release/libbesu_native_ec.dylib
218228
lipo -info ./release/libbesu_native_ec_crypto.dylib
219229
fi
230+
231+
mkdir -p "./release/${OSARCH}"
232+
echo `pwd`
233+
cp ./release/libbesu_native_ec* "./release/${OSARCH}/"
234+
220235
}
221236

222237
build_secp256k1
223238
build_altbn128
224239
build_bls12_381
225240
build_ipa_multipoint
226241
build_secp256r1
242+
243+
227244
build_jars
228245
exit

0 commit comments

Comments
 (0)