1
1
#! /bin/bash
2
-
3
- # When developing locally, one should call this script to
4
- # build the necessary binaries needed for the other languages
2
+ # When developing locally, one should call this script to
3
+ # build the necessary binaries needed for the other languages
5
4
# to interact with the rust library.
6
5
# Note: This is specifically for libraries that need to have a compiled
7
6
# dynamic or static library.
8
7
9
8
# Determine the script's directory
10
9
SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
11
10
PROJECT_ROOT=" $( cd " $SCRIPT_DIR /.." && pwd) "
12
-
13
11
OS=$( uname)
14
12
ARCH=$( uname -m)
15
13
16
- # Compile rust code for java library
17
- OUT_DIR=" $PROJECT_ROOT /bindings/java/java_code/src/main/resources"
18
- LIB_TYPE=" dynamic"
19
- LIB_NAME=" java_peerdas_kzg"
20
- $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH $LIB_NAME $LIB_TYPE $OUT_DIR
21
-
22
- # Compile Rust code for c sharp
23
- OUT_DIR=" $PROJECT_ROOT /bindings/csharp/csharp_code/PeerDASKZG.bindings/runtimes"
24
- LIB_TYPE=" dynamic"
25
- LIB_NAME=" c_peerdas_kzg"
26
- $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH $LIB_NAME $LIB_TYPE $OUT_DIR
27
-
28
- # Compile Rust code for golang
29
- OUT_DIR=" $PROJECT_ROOT /bindings/golang/build"
30
- LIB_TYPE=" static"
31
- LIB_NAME=" c_peerdas_kzg"
32
- $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH $LIB_NAME $LIB_TYPE $OUT_DIR
33
- # Copy header file
34
- cp $PROJECT_ROOT /bindings/c/build/c_peerdas_kzg.h $OUT_DIR
35
-
36
- # Compile Rust code for nimble
37
- OUT_DIR=" $PROJECT_ROOT /bindings/nim/nim_code/build"
38
- LIB_TYPE=" static"
39
- LIB_NAME=" c_peerdas_kzg"
40
-
41
- # Check if the OS is Darwin (macOS) and set ARCH_MODIFIED to universal if true.
42
- # nim has issues with M1s where they will install an x86_64 version of nim
43
- # on an arm chip, so we need compile a universal binary so that nim can use whichever
44
- # architecture it needs.
45
- if [[ " $OS " == " Darwin" ]]; then
46
- # Install both targets for mac, so that it won't fail in CI
47
- rustup target add x86_64-apple-darwin
48
- rustup target add aarch64-apple-darwin
49
- ARCH_MODIFIED=" universal"
50
- else
51
- ARCH_MODIFIED=$ARCH
14
+ # Function to compile for Java
15
+ compile_java () {
16
+ echo " Compiling for Java..."
17
+ OUT_DIR=" $PROJECT_ROOT /bindings/java/java_code/src/main/resources"
18
+ LIB_TYPE=" dynamic"
19
+ LIB_NAME=" java_peerdas_kzg"
20
+ $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH $LIB_NAME $LIB_TYPE $OUT_DIR
21
+ }
22
+
23
+ # Function to compile for C#
24
+ compile_csharp () {
25
+ echo " Compiling for C#..."
26
+ OUT_DIR=" $PROJECT_ROOT /bindings/csharp/csharp_code/PeerDASKZG.bindings/runtimes"
27
+ LIB_TYPE=" dynamic"
28
+ LIB_NAME=" c_peerdas_kzg"
29
+ $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH $LIB_NAME $LIB_TYPE $OUT_DIR
30
+ }
31
+
32
+ # Function to compile for Golang
33
+ compile_golang () {
34
+ echo " Compiling for Golang..."
35
+ OUT_DIR=" $PROJECT_ROOT /bindings/golang/build"
36
+ LIB_TYPE=" static"
37
+ LIB_NAME=" c_peerdas_kzg"
38
+ $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH $LIB_NAME $LIB_TYPE $OUT_DIR
39
+ # Copy header file
40
+ cp $PROJECT_ROOT /bindings/c/build/c_peerdas_kzg.h $OUT_DIR
41
+ }
42
+
43
+ # Function to compile for Nim
44
+ compile_nim () {
45
+ echo " Compiling for Nim..."
46
+ OUT_DIR=" $PROJECT_ROOT /bindings/nim/nim_code/build"
47
+ LIB_TYPE=" static"
48
+ LIB_NAME=" c_peerdas_kzg"
49
+ # Check if the OS is Darwin (macOS) and set ARCH_MODIFIED to universal if true.
50
+ if [[ " $OS " == " Darwin" ]]; then
51
+ # Install both targets for mac, so that it won't fail in CI
52
+ rustup target add x86_64-apple-darwin
53
+ rustup target add aarch64-apple-darwin
54
+ ARCH_MODIFIED=" universal"
55
+ else
56
+ ARCH_MODIFIED=$ARCH
57
+ fi
58
+ $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH_MODIFIED $LIB_NAME $LIB_TYPE $OUT_DIR
59
+ }
60
+
61
+ # Function to compile for all languages
62
+ compile_all () {
63
+ compile_java
64
+ compile_csharp
65
+ compile_golang
66
+ compile_nim
67
+ }
68
+
69
+ # If no argument is provided, compile for all languages
70
+ if [ $# -eq 0 ]; then
71
+ compile_all
72
+ exit 0
52
73
fi
53
- $PROJECT_ROOT /scripts/compile_to_native.sh $OS $ARCH_MODIFIED $LIB_NAME $LIB_TYPE $OUT_DIR
74
+
75
+ # Compile based on the argument
76
+ case $1 in
77
+ java)
78
+ compile_java
79
+ ;;
80
+ csharp)
81
+ compile_csharp
82
+ ;;
83
+ golang)
84
+ compile_golang
85
+ ;;
86
+ nim)
87
+ compile_nim
88
+ ;;
89
+ * )
90
+ echo " Invalid argument. Use java, csharp, golang, nim, or run without arguments to compile for all languages."
91
+ exit 1
92
+ ;;
93
+ esac
0 commit comments