Parcourir la source

darkirc: Add native Android cross-build instructions

parazyd il y a 2 ans
Parent
commit
3b84503365

+ 4 - 1
bin/darkirc/.gitignore

@@ -1 +1,4 @@
-.jniLibs
+jniLibs
+sqlcipher
+openssl
+darkirc.android64

+ 9 - 0
bin/darkirc/Cargo.toml

@@ -8,6 +8,15 @@ license = "AGPL-3.0-only"
 homepage = "https://dark.fi"
 repository = "https://github.com/darkrenaissance/darkfi"
 
+[lib]
+name = "darkirc"
+crate-type = ["cdylib"]
+path = "src/lib.rs"
+
+[[bin]]
+name = "darkirc"
+path = "src/main.rs"
+
 [dependencies]
 darkfi = {path = "../../", features = ["async-daemonize", "event-graph", "net", "util", "system", "rpc", "zk"]}
 darkfi-sdk = {path = "../../src/sdk", features = ["async"]}

+ 6 - 5
bin/darkirc/Makefile

@@ -24,7 +24,7 @@ SRC = \
 	$(shell find src -type f -name '*.rs') \
 	$(shell find ../../src -type f -name '*.rs') \
 
-BIN = $(shell grep '^name = ' Cargo.toml | cut -d' ' -f3 | tr -d '"')
+BIN = $(shell grep '^name = ' Cargo.toml | sed 1q | cut -d' ' -f3 | tr -d '"')
 
 all: $(BIN)
 
@@ -45,11 +45,12 @@ $(BIN): $(PROOFS_BIN) $(SRC)
 # - rustup target add i686-linux-android
 $(BIN).android64:
 	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) ndk -t arm64-v8a -o ./jniLibs build --release --package $(BIN)
-	cp -f ../../target/aarch64-linux-android/release/$(BIN) $(BIN).$@
+	cp -f ../../target/aarch64-linux-android/release/$(BIN) $@
 
-$(BIN).android32:
-	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) ndk -t armeabi-v7a -o ./jniLibs build --release --package $(BIN)
-	cp -f ../../target/armv7-linux-androideabi/release/$(BIN) $(BIN).$@
+# UNTESTED:
+#$(BIN).android32:
+#	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) ndk -t armeabi-v7a -o ./jniLibs build --release --package $(BIN)
+#	cp -f ../../target/armv7-linux-androideabi/release/$(BIN) $(BIN).$@
 
 clean:
 	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(RUST_TARGET) --release --package $(BIN)

+ 46 - 0
bin/darkirc/README.md

@@ -2,3 +2,49 @@ darkirc
 =======
 
 [Installation Guide](https://darkrenaissance.github.io/darkfi/misc/darkirc/darkirc.html)
+
+## Android build
+
+1. Install `android-ndk`
+2. Compile `openssl` with the Android toolchain
+3. Compile `sqlcipher` with the Android toolchain and the `openssl` lib
+4. Compile `darkirc`
+
+### OpenSSL
+
+```
+$ git clone https://github.com/openssl/openssl
+$ cd openssl
+$ export ANDROID_NDK_ROOT="/opt/android-ndk"
+$ export PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
+$ ./Configure android-arm64 -D__ANDROID_API__=32
+$ make -j$(nproc)
+```
+
+### SQLcipher
+
+```
+$ git clone https://github.com/sqlcipher/sqlcipher
+$ cd sqlcipher
+$ sed -e 's/strchrnul//' -i configure
+$ export ANDROID_NDK_ROOT="/opt/android-ndk"
+$ export PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
+$ CC=aarch64-linux-android32-clang \
+  CPPFLAGS="-I$PWD/../openssl/include" \
+  LDFLAGS="-L$PWD/../openssl" \
+  ./configure \
+      --host=aarch64-linux-android32 \
+      --disable-shared \
+      --enable-static \
+      --enable-cross-thread-connections \
+      --enable-releasemode \
+      --disable-tcl
+$ make -j$(nproc)
+$ ./libtool --mode install install libsqlcipher.la $PWD
+```
+
+### DarkIRC
+
+```
+$ make darkirc.android64
+```

+ 5 - 0
bin/darkirc/build.rs

@@ -0,0 +1,5 @@
+fn main() {
+    if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
+        println!("cargo:rustc-link-search={}/sqlcipher", env!("CARGO_MANIFEST_DIR"));
+    }
+}

+ 17 - 0
bin/darkirc/src/lib.rs

@@ -0,0 +1,17 @@
+/* This file is part of DarkFi (https://dark.fi)
+ *
+ * Copyright (C) 2020-2023 Dyne.org foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */