diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..798df90 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,69 @@ +name: Build Executable + +on: + workflow_dispatch: + +concurrency: + group: build-comp-groups + +jobs: + build_exec: + needs: get_commit_hash + runs-on: ubuntu-latest + permissions: + contents: write + strategy: + matrix: + platform: [arm, aarch64, i686, x86_64] + + steps: + - name: Install Docker + run: | + sudo apt-get update + sudo apt-get install -y ca-certificates curl gnupg + sudo install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg + sudo chmod a+r /etc/apt/keyrings/docker.gpg + echo "deb [arch=\"$(dpkg --print-architecture)\" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update + sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + + - name: Set Build Architecture + run: | + if [ "${{ matrix.platform }}" = "aarch64" ]; then + echo "arch_name=arm64" >> $GITHUB_ENV + elif [ "${{ matrix.platform }}" = "i686" ]; then + echo "arch_name=x86" >> $GITHUB_ENV + else + echo "arch_name=${{ matrix.platform }}" >> $GITHUB_ENV + fi + + - name: Build Competition Groups + run: | + mkdir -p build + + # Support for ARM and AARCH64 + if [[ "${{ matrix.platform }}" == "arm" || "${{ matrix.platform }}" == "aarch64" ]]; then + docker pull aptman/qus + docker run --rm --privileged aptman/qus -s -- -p arm aarch64 + fi + + docker pull termux/termux-docker:${{ matrix.platform }} + docker run --privileged --name cgroups-${{ matrix.platform }} termux/termux-docker:${{ matrix.platform }} bash -c "yes | pkg upgrade -y && pkg install -y git && git clone https://github.com/IMXEren/competition-groups --depth 1 repo && cd repo && bash build_package.sh" + docker cp cgroups-${{ matrix.platform }}:/data/data/com.termux/files/home/repo/build/cgroups.zip build/cgroups-${{ env.arch_name }}.zip + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: cgroups-${{ env.arch_name }} + path: build/cgroups-${{ env.arch_name }}.zip + + - name: Upload Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build/cgroups-${{ env.arch_name }}.zip + asset_name: cgroups-${{ env.arch_name }}.zip + tag: "Assets" + release_name: "Assets for Project" + overwrite: true diff --git a/Cargo.toml b/Cargo.toml index ea8378f..3cffe99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ lto = true codegen-units = 1 [dependencies] -thirtyfour = { git = "https://github.com/stevepryde/thirtyfour", features = ["native-tls"]} +thirtyfour = { git = "https://github.com/stevepryde/thirtyfour", rev = "231ab54", features = ["native-tls"]} tokio = { version = "1.36.0", features = ["macros", "rt", "signal", "process"] } anyhow = "1.0.80" serde_json = "1.0.114" diff --git a/build_package.sh b/build_package.sh new file mode 100644 index 0000000..f0793c4 --- /dev/null +++ b/build_package.sh @@ -0,0 +1,98 @@ +#!/usr/bin/bash + +if [ -n $TERMUX_VERSION ]; then + apt update + yes | pkg install -y git rust termux-elf-cleaner p7zip 2>/dev/null | grep -E '(Need to get |Get:|Unpacking |Setting up )' +else + echo "The script should run on Termux" + exit 1 +fi + +rustc --version +cargo --version + +current_dir="$(pwd)" +tmpdir="$(mktemp -d)" + +cd $tmpdir + +git clone https://github.com/IMXEren/competition-groups + +if [ -n $TERM ]; then + clear +fi + +# fix Termux permissions +if [ -n $TERMUX_VERSION ]; then + value="true"; key="allow-external-apps"; file="/data/data/com.termux/files/home/.termux/termux.properties"; mkdir -p "$(dirname "$file")"; chmod 700 "$(dirname "$file")"; if ! grep -E '^'"$key"'=.*' $file &>/dev/null; then [[ -s "$file" && ! -z "$(tail -c 1 "$file")" ]] && newline=$'\n' || newline=""; echo "$newline$key=$value" >> "$file"; else sed -i'' -E 's/^'"$key"'=.*/'"$key=$value"'/' $file; fi +fi + +echo -e "\nFinal step, building compgroups binary. Takes about 10s~1min" + +package_script='#!/system/bin/sh + +dir="$(cd "$(dirname "$0")"; pwd)" +bin_name="$(basename "$0")" +chmod 744 "$0" &>/dev/null +chmod 744 "$dir/${bin_name}.bin" &>/dev/null +export LD_LIBRARY_PATH="$dir/lib-${bin_name}:$LD_LIBRARY_PATH" + +if [ $(getprop ro.build.version.sdk) -gt 28 ]; then + if getprop ro.product.cpu.abilist | grep -q "64" + then + exec /system/bin/linker64 "$dir/${bin_name}.bin" "$@" + else + exec /system/bin/linker "$dir/${bin_name}.bin" "$@" + fi +else + exec "$dir/${bin_name}.bin" "$@" +fi' + +cargo build --release +bin_path="${tmpdir}/competition-groups/target/release/competition-groups" +package="compgroups" +zip_name="cgroups.zip" + +if [ $? -eq 0 ]; then + if [ -n $TERMUX_VERSION ]; then + termux-elf-cleaner ${tmpdir}/cgroups/${package}.bin &>/dev/null + fi + cd $current_dir + rm -rf build/${zip_name} build/${package} build/${package}.bin build/lib-${package} &>/dev/null + mkdir -p build + cd build + cp ${tmpdir}/cgroups/${package}.bin . + if [ $? -ne 0 ]; then + rm -rf $tmpdir &>/dev/null + echo "Error occured, exiting..." + exit 1 + fi + echo "$package_script" > ${package} + for libpath in $(ldd ${package}.bin | grep -F "/data/data/com.termux/" | sed "s/.* //g"); do + cp -L "$libpath" lib-${package} &>/dev/null + done + echo -e "\n Zipping package..." + chmod 744 ${package} ${package}.bin &>/dev/null + 7z a -tzip -mx=9 -bd -bso0 ${zip_name} ${package} ${package}.bin lib-${package} + rm -rf ${package} ${package}.bin lib-${package} &>/dev/null +else + rm -rf $tmpdir &>/dev/null + echo "Error occured, exiting..." + exit 1 +fi + +rm -rf $tmpdir &>/dev/null + + +if [ -n $TERMUX_VERSION ]; then + pkg clean +fi + +mkdir -p ~/cgroups + +7z x -aoa ${zip_name} -o$HOME/cgroups &>/dev/null + +chmod 744 ~/cgroups/compgroups + +echo -e "All done! You can type this -\n \n\" cd ~/cgroups; ./compgroups \"\n\nType without quotes to run executable\n" +