commit 94c9688e27de31042033e23e016cc35f353ca462 Author: DarkCat09 Date: Mon Jul 3 14:24:45 2023 +0400 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a2be9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +piped.jar +config.properties + +backend/ +reqwest4j/ +reqwest4j.jar +libreqwest_jni.so +META-INF/ + +.vscode/ +*.swp diff --git a/backend.patch b/backend.patch new file mode 100644 index 0000000..60498ed --- /dev/null +++ b/backend.patch @@ -0,0 +1,27 @@ +diff --git a/build.gradle b/build.gradle +index f68c2d6..977c514 100644 +--- a/build.gradle ++++ b/build.gradle +@@ -40,7 +40,8 @@ dependencies { + implementation 'com.squareup.okhttp3:okhttp' + implementation 'com.squareup.okhttp3:okhttp-brotli' + implementation 'io.sentry:sentry:6.24.0' +- implementation 'rocks.kavin:reqwest4j:1.0.5' ++ // implementation 'rocks.kavin:reqwest4j:1.0.5' ++ implementation files('libs/reqwest4j.jar') + implementation 'io.minio:minio:8.5.4' + } + +diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java +index 4f338c0..8c606b5 100644 +--- a/src/main/java/me/kavin/piped/consts/Constants.java ++++ b/src/main/java/me/kavin/piped/consts/Constants.java +@@ -142,7 +142,7 @@ public class Constants { + DISABLE_SERVER = Boolean.parseBoolean(getProperty(prop, "DISABLE_SERVER", "false")); + DISABLE_LBRY = Boolean.parseBoolean(getProperty(prop, "DISABLE_LBRY", "false")); + SUBSCRIPTIONS_EXPIRY = Integer.parseInt(getProperty(prop, "SUBSCRIPTIONS_EXPIRY", "30")); +- SENTRY_DSN = getProperty(prop, "SENTRY_DSN", ""); ++ SENTRY_DSN = /*getProperty(prop, "SENTRY_DSN", "")*/ ""; + S3_ENDPOINT = getProperty(prop, "S3_ENDPOINT"); + S3_ACCESS_KEY = getProperty(prop, "S3_ACCESS_KEY"); + S3_SECRET_KEY = getProperty(prop, "S3_SECRET_KEY"); diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e338ca7 --- /dev/null +++ b/build.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env ash +# shellcheck shell=dash + +BOLD=$(tput bold) +RESET=$(tput sgr0) + +WORKDIR=$(pwd) + + +# --- +dep () { + which "$1" || (echo "$1 not found" && exit 1) +} + +clone () { + git clone --single-branch --depth 1 "$1" "$2" || exit 2 +} + +cd_and_exec () { + old=$(pwd) + cd "$1" || exit 3 + shift + "$@" || exit 4 + cd "$old" || exit 3 +} + +try_exec () { + "$@" + return 0 +} + +title () { + echo + echo "$BOLD$1$RESET" +} + + +# --- +title 'Checking dependencies...' +dep git +dep java +dep cargo +dep 7z + +title 'Cloning repositories...' +[ -e backend ] || clone https://github.com/TeamPiped/Piped-Backend backend +[ -e reqwest4j ] || clone https://github.com/TeamPiped/reqwest4j reqwest4j + +title 'Applying patches...' +cd_and_exec backend try_exec git apply ../backend.patch +cd_and_exec reqwest4j try_exec git apply ../reqwest4j.patch + + +# --- +export RUSTFLAGS="-C target-feature=-crt-static" + +title 'Building reqwest-jni...' +cd_and_exec reqwest4j/reqwest-jni cargo build --release + +title 'Building reqwest4j...' +cd_and_exec reqwest4j ./gradlew shadowJar +cd_and_exec reqwest4j ./gradlew --stop + + +# --- +title 'Adding built reqwest-jni into reqwest4j...' + +# Copy JAR into workdir +REQ4J_NAME="reqwest4j.jar" +REQ4J="$WORKDIR/$REQ4J_NAME" +cd_and_exec reqwest4j/build/libs \ + find . -maxdepth 1 -name 'reqwest4j-*-all.jar' -exec \ + cp {} "$REQ4J" \; + +# Copy built reqwest-jni into workdir +REQJNI_NAME="libreqwest_jni.so" +REQJNI="$WORKDIR/$REQJNI_NAME" +cd_and_exec reqwest4j/reqwest-jni/target/release cp libreqwest_jni.so "$REQJNI" + +# Create JAR native libraries tree +NATIVES="META-INF/natives/linux/x86_64" +mkdir -p "$NATIVES" + +# Move reqwest-jni to native libraries directory +mv "$REQJNI" "$NATIVES/$REQJNI_NAME" + +# Add native libraries into JAR +7z u "$REQ4J" META-INF + +# Clean up +rm -rf META-INF +rm -f "$REQJNI" + + +# --- +title 'Adding reqwest4j JAR into Piped...' +cd_and_exec backend mkdir libs +cd_and_exec backend/libs mv "$REQ4J" ./ + +title 'Building Piped...' +cd_and_exec backend ./gradlew shadowJar +cd_and_exec backend ./gradlew --stop + + +# --- +title 'Copying Piped JAR...' +cd_and_exec backend/build/libs \ + find . -maxdepth 1 -name 'piped-*-all.jar' -exec \ + cp {} "$WORKDIR/piped.jar" \; + +title 'Copying config...' +cd_and_exec backend cp config.properties "$WORKDIR" + +title 'Cleaning up...' +rm -rf backend reqwest4j + + +# --- +echo '*** **** ***' +echo '*** DONE ***' +title 'You need these files:' +for f in "piped.jar" "config.properties" +do + echo " $(readlink -f "$f")" +done diff --git a/reqwest4j.patch b/reqwest4j.patch new file mode 100644 index 0000000..f5267cd --- /dev/null +++ b/reqwest4j.patch @@ -0,0 +1,18 @@ +diff --git a/reqwest-jni/build.gradle.kts b/reqwest-jni/build.gradle.kts +index 189a81d..8c5895e 100644 +--- a/reqwest-jni/build.gradle.kts ++++ b/reqwest-jni/build.gradle.kts +@@ -4,8 +4,10 @@ plugins { + + rust { + release.set(true) +- command.set("cross") ++ command.set("cargo") ++ cargoInstallTargets.set(true) + +- targets += target("aarch64-unknown-linux-gnu", "libreqwest.so") +- targets += target("x86_64-unknown-linux-gnu", "libreqwest.so") ++ // targets += target("aarch64-unknown-linux-gnu", "libreqwest.so") ++ // targets += target("x86_64-unknown-linux-gnu", "libreqwest.so") ++ targets += target("x86_64-unknown-linux-musl", "libreqwest.so") + }