Skip to content

Commit

Permalink
first category source codes
Browse files Browse the repository at this point in the history
  • Loading branch information
AMIR ABBAS committed May 21, 2023
1 parent 9bc14b7 commit 90de28f
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Build Nekoray
run: |
bash nekoray_macos_builder.sh
bash builder.sh
- name: Upload Artifact for amd64
uses: actions/upload-artifact@v2
with:
Expand Down
63 changes: 63 additions & 0 deletions builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

set -e

# set environment variables from sh file
echo "Setting environment variables"
source config_environment.sh
init_script_variable

# get dependencies and first configure
echo "Getting dependencies"
bash get_dependencies.sh

# clone or update source codes
echo "Cloning or updating source codes"
bash get_sources.sh

# Create or clean build directory
if [ ! -d "$nPath/build" ]; then
mkdir -p "$nPath/build"
else

read -p "Do you want to clean 'build' and 'libs/deps' directories ? [y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi

rm -rf "$nPath/libs/deps"
rm -rf "$nPath/build"
mkdir -p "$nPath/build"
fi

# get dependencies (official source)
echo "Getting dependencies (official source)"
bash build_deps_all.sh

# package nekoray
echo "Packaging nekoray"
bash packaging_nekoray.sh

# Build nekobox_core and nekoray_core
echo "Building nekobox_core and nekoray_core"
bash core_builder.sh

#zip nekoray by arch
echo "Zipping nekoray"
if [ -n "$GITHUB_ACTIONS" ]; then
for arch in "amd64" "arm64"; do
TEMP_PATH=$(pwd)
cd "$nPath/build"
zip -r "nekoray_$arch.zip" "nekoray_$arch.app"
cd "$TEMP_PATH"
done
else
for arch in "amd64" "arm64"; do
zip -r "$nPath/build/nekoray_$arch.zip" "$nPath/build/nekoray_$arch.app"
done
fi

echo "Build finished and output files are in $nPath/build"
cd "$nPath"
open "$nPath/build"
18 changes: 18 additions & 0 deletions config_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# first config environment variables
export MACOSX_DEPLOYMENT_TARGET="10.13"

init_script_variable() {
nRoot="$(pwd)"
nPath="$(pwd)/temp/nekoray"
nApp=$nPath/build/nekoray.app
}

init_nekoray_local() {
neko_common="github.com/matsuridayo/libneko/neko_common"
cd $nRoot/v2ray-core
version_v2ray=$(git log --pretty=format:'%h' -n 1)
cd $nPath
version_standalone="nekoray-"$(cat $nPath/nekoray_version.txt)
}
20 changes: 20 additions & 0 deletions core_builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# set environment variables from sh file
source config_environment.sh

# Build nekobox_core and nekoray_core for both amd64 and arm64
for cmd in "nekobox_core" "nekoray_core"; do
for arch in "amd64" "arm64"; do
cd "$nPath/go/cmd/$cmd"
GOARCH="$arch"

if [ "$cmd" = "nekoray_core" ]; then
go build -o "${cmd}_${arch}" -v -trimpath -ldflags "-w -s -X $neko_common.Version_v2ray=$version_v2ray -X $neko_common.Version_neko=$version_standalone"
else
go build -o "${cmd}_${arch}" -v -trimpath -ldflags "-w -s -X $neko_common.Version_neko=$version_standalone" -tags "with_grpc,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api"
fi

cp "${cmd}_${arch}" "$nPath/build/nekoray_$arch.app/Contents/MacOS/$cmd"
done
done
35 changes: 35 additions & 0 deletions get_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# set environment variables from sh file
source config_environment.sh

# Install dependencies if they are not already installed

command -v "brew" >/dev/null 2>&1 || {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}

check_and_install() {
local cmd="$1"
local package="$2"
command -v "$cmd" >/dev/null 2>&1 || {
echo "$cmd could not be found, installing $package"
brew install "$package"
}
}

check_and_install "cmake" "cmake"
check_and_install "ninja" "ninja"
check_and_install "go" "go"
check_and_install "curl" "curl"

# Set environment variables
export PATH="/usr/local/opt/qt@5/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/qt@5/lib"
export CPPFLAGS="-I/usr/local/opt/qt@5/include"
export PKG_CONFIG_PATH="/usr/local/opt/qt@5/lib/pkgconfig"

check_and_install "macdeployqt" "qt@5"

# golang dependencies
go get github.com/sagernet/sing-box/experimental/clashapi/[email protected]
47 changes: 47 additions & 0 deletions get_sources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# set environment variables from sh file
source config_environment.sh

# if this script running in github action then
# remove unessary directories with check if exist (nekoray, v2ray-core, sing-box-extra, sing-box, libneko)

if [ -n "$GITHUB_ACTIONS" ]; then
if [ -d "nekoray" ]; then
rm -rf nekoray
fi
if [ -d "v2ray-core" ]; then
rm -rf v2ray-core
fi
if [ -d "sing-box-extra" ]; then
rm -rf sing-box-extra
fi
if [ -d "sing-box" ]; then
rm -rf sing-box
fi
if [ -d "libneko" ]; then
rm -rf libneko
fi
fi

# Clone or update repositories

clone_last_valid_source() {
local repo="$1"
local url="$2"
if [ -d "$repo" ]; then
git -C "$repo" reset --hard
git -C "$repo" fetch --all --tags --prune
else
git clone --recursive "$url" "$repo"
fi
if [ -n "$(git -C "$repo" tag --list)" ]; then
git -C "$repo" checkout "$(git -C "$repo" describe --tags $(git -C "$repo" rev-list --tags --max-count=1))"
fi
}

clone_last_valid_source "nekoray" "https://github.com/MatsuriDayo/nekoray.git"
clone_last_valid_source "v2ray-core" "https://github.com/MatsuriDayo/v2ray-core.git"
clone_last_valid_source "sing-box-extra" "https://github.com/MatsuriDayo/sing-box-extra.git"
clone_last_valid_source "sing-box" "https://github.com/MatsuriDayo/sing-box.git"
clone_last_valid_source "libneko" "https://github.com/MatsuriDayo/libneko.git"
1 change: 0 additions & 1 deletion libneko
Submodule libneko deleted from 67ece2
1 change: 0 additions & 1 deletion nekoray
Submodule nekoray deleted from 566820
175 changes: 0 additions & 175 deletions nekoray_macos_builder.sh

This file was deleted.

Loading

0 comments on commit 90de28f

Please sign in to comment.