Skip to content

Commit

Permalink
Merge branch 'sbwml:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pmkol authored Jul 9, 2024
2 parents 1bb2d94 + 68009c9 commit 5e5fa00
Show file tree
Hide file tree
Showing 32 changed files with 12,230 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
build_options:
description: 'Build options (separate multiple options with spaces)'
required: false
default: 'BUILD_FAST=y ENABLE_LTO=y ENABLE_LRNG=y ENABLE_BPF=y USE_GCC13=y USE_MOLD=y'
default: 'BUILD_FAST=y ENABLE_LTO=y ENABLE_MOLD=y ENABLE_LRNG=y ENABLE_BPF=y USE_GCC14=y'
type: string

jobs:
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ sudo apt-get install -y build-essential flex bison g++ gawk gcc-multilib g++-mul
```shell
# 下载并解压
sudo mkdir -p /opt/clang
curl -LO https://github.com/sbwml/redhat-llvm-project/releases/download/18.1.6/clang-18.1.6-x86_64-redhat-linux.tar.xz
sudo tar --strip-components=1 -C /opt/clang -xf clang-18.1.6-x86_64-redhat-linux.tar.xz
rm -rf clang-18.1.6-x86_64-redhat-linux.tar.xz
curl -LO https://github.com/sbwml/redhat-llvm-project/releases/download/18.1.8/clang-18.1.8-x86_64-redhat-linux.tar.xz
sudo tar --strip-components=1 -C /opt/clang -xf clang-18.1.8-x86_64-redhat-linux.tar.xz
rm -rf clang-18.1.8-x86_64-redhat-linux.tar.xz

# 添加 BIN 到系统变量
export PATH="/opt/clang/bin:$PATH"

# clang 版本验证
clang --version

clang version 18.1.6 (https://github.com/llvm/llvm-project 1118c2e05e67a36ed8ca250524525cdb66a55256)
Target: x86_64-redhat-linux
clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /opt/clang/bin
```
Expand All @@ -76,7 +76,7 @@ clang --version

### 启用 [Clang/LLVM](https://docs.kernel.org/kbuild/llvm.html) 构建内核
##### 脚本支持使用 Clang/LLVM 构建内核,NanoPi & X86_64 设备将同时启用 LLVM LTO 链接时优化,这会增加编译的时间,但会获得更优的性能
##### 编译环境需要安装 Clang/LLVM 工具链,推荐使用 clang 16-18 版本
##### 编译环境需要安装 Clang/LLVM 工具链,推荐使用 clang 16~18 版本
##### 只需在构建固件前执行以下命令即可启用 Clang/LLVM 构建内核与内核模块

```
Expand Down Expand Up @@ -112,7 +112,7 @@ export ENABLE_LTO=y
##### 只需在构建固件前执行以下命令即可启用 MOLD 链接,如果使用它建议同时启用 LTO 优化

```
export USE_MOLD=y
export ENABLE_MOLD=y
```

### 启用 [eBPF](https://docs.kernel.org/bpf/) 支持
Expand All @@ -130,11 +130,19 @@ export ENABLE_LRNG=y
```

### 启用 [Glibc](https://www.gnu.org/software/libc/) 库构建 (实验性)
##### 脚本支持使用 glibc 库进行构建,当启用 glibc 进行构建时,构建的固件将会同时兼容 musl/glibc 的预构建二进制程序
##### 启用 glibc 库进行构建时,构建的固件将会同时兼容 musl/glibc 的预构建二进制程序,但缺失 `opkg install` 安装源支持
##### 只需在构建固件前执行以下命令即可启用 glibc 构建

```
export USE_GLIBC=y
export ENABLE_GLIBC=y
```

### 启用 [DPDK](https://www.dpdk.org/) 支持
##### DPDK(Data Plane Development Kit)是一个开源工具集,专为加速数据包处理而设计,通过优化的数据平面技术,实现高性能、低延迟的网络应用
##### 只需在构建固件前执行以下命令即可启用 DPDK 工具集支持

```
export ENABLE_DPDK=y
```

### 快速构建(仅限 Github Actions)
Expand Down
2 changes: 2 additions & 0 deletions openwrt/23-config-musl-x86
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ CONFIG_TARGET_ROOTFS_PARTSIZE=944
### Kernel driver
CONFIG_PACKAGE_kmod-igb=y
CONFIG_PACKAGE_kmod-igc=y
CONFIG_PACKAGE_kmod-mlx4-core=y
CONFIG_PACKAGE_kmod-mlx5-core=y
CONFIG_PACKAGE_kmod-mt76x2=y
CONFIG_PACKAGE_kmod-mt7921e=y
CONFIG_PACKAGE_kmod-mt7921u=y
Expand Down
69 changes: 41 additions & 28 deletions openwrt/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,24 @@ fi
if [ "$USE_GCC13" = y ]; then
export USE_GCC13=y
# use mold
[ "$USE_MOLD" = y ] && USE_MOLD=y
[ "$ENABLE_MOLD" = y ] && export ENABLE_MOLD=y
elif [ "$USE_GCC14" = y ]; then
export USE_GCC14=y
# use mold
[ "$USE_MOLD" = y ] && USE_MOLD=y
[ "$ENABLE_MOLD" = y ] && export ENABLE_MOLD=y
elif [ "$USE_GCC15" = y ]; then
export USE_GCC15=y
# use mold
[ "$USE_MOLD" = y ] && USE_MOLD=y
[ "$ENABLE_MOLD" = y ] && export ENABLE_MOLD=y
fi

# use glibc
export USE_GLIBC=$USE_GLIBC

# lrng
export ENABLE_LRNG=$ENABLE_LRNG

# kernel build with clang lto
export KERNEL_CLANG_LTO=$KERNEL_CLANG_LTO

# bpf
export ENABLE_BPF=$ENABLE_BPF
# build.sh flags
export \
ENABLE_BPF=$ENABLE_BPF \
ENABLE_DPDK=$ENABLE_DPDK \
ENABLE_GLIBC=$ENABLE_GLIBC \
ENABLE_LRNG=$ENABLE_LRNG \
KERNEL_CLANG_LTO=$KERNEL_CLANG_LTO \

# print version
echo -e "\r\n${GREEN_COLOR}Building $branch${RES}\r\n"
Expand Down Expand Up @@ -168,14 +164,16 @@ else
echo -e "${GREEN_COLOR}GCC VERSION: 11${RES}"
fi
[ -n "$LAN" ] && echo -e "${GREEN_COLOR}LAN: $LAN${RES}" || echo -e "${GREEN_COLOR}LAN: 10.0.0.1${RES}"
[ "$USE_MOLD" = "y" ] && echo -e "${GREEN_COLOR}USE_MOLD: true${RES}" || echo -e "${GREEN_COLOR}USE_MOLD: false${RES}"
[ "$ENABLE_OTA" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_OTA: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_OTA: false${RES}"
[ "$ENABLE_BPF" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_BPF: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_BPF: false${RES}"
[ "$ENABLE_LTO" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_LTO: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_LTO: false${RES}"
[ "$ENABLE_LRNG" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_LRNG: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_LRNG: false${RES}"
[ "$BUILD_FAST" = "y" ] && echo -e "${GREEN_COLOR}BUILD_FAST: true${RES}" || echo -e "${GREEN_COLOR}BUILD_FAST: false${RES}"
[ "$ENABLE_GLIBC" = "y" ] && echo -e "${GREEN_COLOR}Standard C Library:${RES} ${BLUE_COLOR}glibc${RES}" || echo -e "${GREEN_COLOR}Standard C Library:${RES} ${BLUE_COLOR}musl${RES}"
[ "$ENABLE_OTA" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_OTA: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_OTA:${RES} ${YELLOW_COLOR}false${RES}"
[ "$ENABLE_DPDK" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_DPDK: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_DPDK:${RES} ${YELLOW_COLOR}false${RES}"
[ "$ENABLE_MOLD" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_MOLD: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_MOLD:${RES} ${YELLOW_COLOR}false${RES}"
[ "$ENABLE_BPF" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_BPF: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_BPF:${RES} ${RED_COLOR}false${RES}"
[ "$ENABLE_LTO" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_LTO: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_LTO:${RES} ${RED_COLOR}false${RES}"
[ "$ENABLE_LRNG" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_LRNG: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_LRNG:${RES} ${RED_COLOR}false${RES}"
[ "$BUILD_FAST" = "y" ] && echo -e "${GREEN_COLOR}BUILD_FAST: true${RES}" || echo -e "${GREEN_COLOR}BUILD_FAST:${RES} ${YELLOW_COLOR}false${RES}"
[ "$MINIMAL_BUILD" = "y" ] && echo -e "${GREEN_COLOR}MINIMAL_BUILD: true${RES}" || echo -e "${GREEN_COLOR}MINIMAL_BUILD: false${RES}"
[ "$KERNEL_CLANG_LTO" = "y" ] && echo -e "${GREEN_COLOR}KERNEL_CLANG_LTO: true${RES}\r\n" || echo -e "${GREEN_COLOR}KERNEL_CLANG_LTO: false${RES}\r\n"
[ "$KERNEL_CLANG_LTO" = "y" ] && echo -e "${GREEN_COLOR}KERNEL_CLANG_LTO: true${RES}\r\n" || echo -e "${GREEN_COLOR}KERNEL_CLANG_LTO:${RES} ${YELLOW_COLOR}false${RES}\r\n"

# clean old files
rm -rf openwrt master && mkdir master
Expand Down Expand Up @@ -322,17 +320,32 @@ export ENABLE_LTO=$ENABLE_LTO
[ "$ENABLE_LTO" = "y" ] && curl -s https://$mirror/openwrt/generic/config-lto >> .config

# glibc
[ "$USE_GLIBC" = "y" ] && {
[ "$ENABLE_GLIBC" = "y" ] && {
curl -s https://$mirror/openwrt/generic/config-glibc >> .config
sed -i '/NaiveProxy/d' .config
}

# DPDK
[ "$ENABLE_DPDK" = "y" ] && {
echo 'CONFIG_PACKAGE_dpdk-tools=y' >> .config
echo 'CONFIG_PACKAGE_numactl=y' >> .config
}

# mold
[ "$USE_MOLD" = "y" ] && echo 'CONFIG_USE_MOLD=y' >> .config
[ "$ENABLE_MOLD" = "y" ] && echo 'CONFIG_USE_MOLD=y' >> .config

# clang
# kernel - CLANG + LTO; Allow CONFIG_KERNEL_CC=clang / clang-18 / clang-xx
if [ "$KERNEL_CLANG_LTO" = "y" ]; then
curl -s https://$mirror/openwrt/generic/config-clang >> .config
echo '# Kernel - CLANG LTO' >> .config
echo 'CONFIG_KERNEL_CC="clang"' >> .config
echo 'CONFIG_EXTRA_OPTIMIZATION=""' >> .config
echo '# CONFIG_PACKAGE_kselftests-bpf is not set' >> .config
fi

# kernel - enable LRNG
if [ "$ENABLE_LRNG" = "y" ]; then
echo -e "\n# Kernel - LRNG" >> .config
echo "CONFIG_KERNEL_LRNG=y" >> .config
fi

# openwrt-23.05 gcc11/13/14/15
Expand All @@ -349,7 +362,7 @@ if [ "$USE_GCC13" = "y" ] || [ "$USE_GCC14" = "y" ] || [ "$USE_GCC15" = "y" ]; t
curl -s https://$mirror/openwrt/patch/generic/gcc-14/910-mbsd_multi.patch > toolchain/gcc/patches-14.x/910-mbsd_multi.patch
cp -a toolchain/gcc/patches-14.x toolchain/gcc/patches-15.x
curl -s https://$mirror/openwrt/patch/generic/gcc-15/970-macos_arm64-building-fix.patch > toolchain/gcc/patches-15.x/970-macos_arm64-building-fix.patch
elif [ ! "$USE_GLIBC" = "y" ]; then
elif [ ! "$ENABLE_GLIBC" = "y" ]; then
curl -s https://$mirror/openwrt/generic/config-gcc11 >> .config
fi
[ "$(whoami)" = "runner" ] && endgroup
Expand All @@ -365,7 +378,7 @@ fi

# Toolchain Cache
if [ "$BUILD_FAST" = "y" ]; then
[ "$USE_GLIBC" = "y" ] && LIBC=glibc || LIBC=musl
[ "$ENABLE_GLIBC" = "y" ] && LIBC=glibc || LIBC=musl
[ "$isCN" = "CN" ] && github_proxy="http://gh.cooluc.com/" || github_proxy=""
echo -e "\n${GREEN_COLOR}Download Toolchain ...${RES}"
PLATFORM_ID=""
Expand Down Expand Up @@ -404,7 +417,7 @@ if [ "$BUILD_TOOLCHAIN" = "y" ]; then
echo -e "\r\n${GREEN_COLOR}Building Toolchain ...${RES}\r\n"
make -j$cores toolchain/compile || make -j$cores toolchain/compile V=s || exit 1
mkdir -p toolchain-cache
[ "$USE_GLIBC" = "y" ] && LIBC=glibc || LIBC=musl
[ "$ENABLE_GLIBC" = "y" ] && LIBC=glibc || LIBC=musl
if [ "$USE_GCC13" = "y" ]; then
tar -zcf toolchain-cache/toolchain_"$LIBC"_"$toolchain_arch"_13.tar.gz ./{build_dir,dl,staging_dir,tmp} && echo -e "${GREEN_COLOR} Build success! ${RES}"
elif [ "$USE_GCC14" = "y" ]; then
Expand Down
5 changes: 5 additions & 0 deletions openwrt/files/etc/sysctl.d/16-udp-buffer-size.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Do not edit, changes to this file will be lost on upgrades
# /etc/sysctl.conf can be used to customize sysctl settings

net.core.rmem_max=7500000
net.core.wmem_max=7500000
4 changes: 0 additions & 4 deletions openwrt/generic/config-clang

This file was deleted.

3 changes: 3 additions & 0 deletions openwrt/nginx/luci.locations
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ location ~ /cgi-bin/cgi-(backup|download|upload|exec) {

location /luci-static {
error_log stderr crit;
if ($request_uri ~* \.(jpg|jpeg|png|gif|ico|webp|mp4|webm)$) {
add_header Cache-Control "public, max-age=2592000";
}
}
Loading

0 comments on commit 5e5fa00

Please sign in to comment.