Skip to main content

golang编译源码

  1. generate-password

    git clone https://github.com/m1/go-generate-password.git
    cd go-generate-password/cmd/go-generate-password
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -o ycycxz-generate-password-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-generate-password-linux-arm64 &
    CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-generate-password-windows-amd64.exe &
    CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-generate-password-windows-386.exe &
    CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-generate-password-macos-amd64 &
    CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-generate-password-macos-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-generate-password*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  2. xray

    git clone -b main https://github.com/XTLS/Xray-core.git
    cd Xray-core/main
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-xray-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-xray-linux-arm64 &
    CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-xray-windows-amd64.exe &
    CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-xray-windows-386.exe &
    CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-xray-macos-amd64 &
    CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-xray-macos-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-xray*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  3. v2ray

    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid="  -o ycycxz-v2ray-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-v2ray-linux-arm64 &
    CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-v2ray-windows-amd64.exe &
    CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-v2ray-windows-386.exe &
    CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-v2ray-macos-amd64 &
    CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-v2ray-macos-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-v2ray*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  4. sing-box

    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags with_acme,with_clash_api,with_dhcp,with_ech,with_gvisor,with_quic,with_reality_server,with_shadowsocksr,with_utls,with_v2ray_api,with_wireguard -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'" -o ycycxz-sing-box-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags with_acme,with_clash_api,with_dhcp,with_ech,with_gvisor,with_quic,with_reality_server,with_shadowsocksr,with_utls,with_v2ray_api,with_wireguard -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'" -o ycycxz-sing-box-linux-arm64 &
    CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags with_acme,with_clash_api,with_dhcp,with_ech,with_gvisor,with_quic,with_reality_server,with_shadowsocksr,with_utls,with_v2ray_api,with_wireguard -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'" -o ycycxz-sing-box-windows-amd64.exe &
    CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -tags with_acme,with_clash_api,with_dhcp,with_ech,with_gvisor,with_quic,with_reality_server,with_shadowsocksr,with_utls,with_v2ray_api,with_wireguard -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'" -o ycycxz-sing-box-windows-arm64.exe &
    CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags with_acme,with_clash_api,with_dhcp,with_ech,with_gvisor,with_quic,with_reality_server,with_shadowsocksr,with_utls,with_v2ray_api,with_wireguard -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'" -o ycycxz-sing-box-macos-amd64 &
    CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags with_acme,with_clash_api,with_dhcp,with_ech,with_gvisor,with_quic,with_reality_server,with_shadowsocksr,with_utls,with_v2ray_api,with_wireguard -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'" -o ycycxz-sing-box-macos-arm64 &

    find * -type f -name "ycycxz-*" | xargs split -b 25000000 --numeric-suffixes=1 --suffix-length=1
    wait;echo DONE!
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best


    cp ycycxz*-[0-9]*
    CGO_ENABLED=1 go build -tags with_quic,with_grpc,with_dhcp,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_reality_server,with_clash_api,with_v2ray_api,with_gvisor,with_lwip,with_acme,with_embedded_tor,musl,staticOpenssl,staticZlib,staticLibevent -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'"
    apt install gcc-mingw-w64 -y
    CGO_ENABLED=0 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -tags with_quic,with_dhcp,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_reality_server,with_clash_api,with_v2ray_api,with_gvisor,with_acme -trimpath -ldflags "-extldflags=-static -s -w -buildid= -X 'github.com/sagernet/sing-box/constant.Version=ycycxz'"
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags with_quic,with_grpc,with_acme -trimpath -ldflags "-extldflags=-static -s -w -buildid=" -o ycycxz-sing-box-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags with_quic,with_grpc,with_acme -trimpath -ldflags "-extldflags=-static -s -w -buildid=" -o ycycxz-sing-box-linux-arm64 &
    CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags with_quic,with_grpc,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_acme,with_clash_api,with_v2ray_api,with_gvisor -trimpath -ldflags "-s -w -buildid=" -o ycycxz-sing-box-windows-amd64.exe &
    wait;echo DONE!
    #upx --best ycycxz-sing-box*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
    cmd
    set CGO_ENABLED = 0; set GOOS = linux; set GOARCH = amd64
    go build -tags with_quic,with_grpc,with_acme -trimpath -ldflags "-extldflags=-static -s -w -buildid=" -o ycycxz-sing-box-linux-amd64
    powershell
    $env:CGO_ENABLED = 0; $env:GOOS = "linux"; $env:GOARCH = "amd64"
    go build -tags with_quic,with_grpc,with_acme -trimpath -ldflags "-extldflags=-static -s -w -buildid=" -o ycycxz-sing-box-linux-amd64
    $env:CGO_ENABLED=0
    $env:GOOS="windows"
    $env:GOARCH="amd64"
    go build -tags with_quic,with_grpc,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_acme,with_clash_api,with_v2ray_api,with_gvisor -trimpath -ldflags "-s -w -buildid=" -o ycycxz-sing-box-windows-amd64.exe
    wait;echo DONE!

    没有窗口版本

    $env:CGO_ENABLED=0
    $env:GOOS="windows"
    $env:GOARCH="amd64"
    go build -tags with_quic,with_grpc,with_wireguard,with_shadowsocksr,with_ech,with_utls,with_acme,with_clash_api,with_v2ray_api,with_gvisor -trimpath -ldflags "-H=windowsgui -extldflags=-static -s -w -buildid=" -o ycycxz-sing-box-windows-amd64_no_windows.exe
  5. xui

    sudo apt install gcc-aarch64-linux-gnu -y
    git clone https://github.com/mainians/x-ui
    cd x-ui
    CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -tags musl,osusergo,netgo,sqlite_omit_load_extension -o ycycxz-xui-linux-amd64 &
    CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -tags musl,osusergo,netgo,sqlite_omit_load_extension -o ycycxz-xui-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-xui*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  6. dasel

    git clone https://github.com/TomWright/dasel
    cd dasel/cmd/dasel
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -o ycycxz-dasel-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -o ycycxz-dasel-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-dasel*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  7. hysteria

    git clone https://github.com/HyNetwork/hysteria
    cd hysteria/app/cmd
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-hysteria-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-hysteria-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-hysteria*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  8. clash-meta

    git clone -b Meta https://github.com/MetaCubeX/Clash.Meta > /dev/null
    cd Clash.Meta
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -o ycycxz-clash-meta-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -o ycycxz-clash-meta-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-clash-meta*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  9. glider

    git clone -b master https://github.com/nadoo/glider > /dev/null
    cd glider
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -o ycycxz-glider-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid= -extldflags=-static" -o ycycxz-glider-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-glider*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  10. gost

    git clone -b master https://github.com/go-gost/gost  > /dev/null
    cd gost/cmd/gost
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-gost-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-gost-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-gost*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
  11. caddy with cloudflare dns and naiveproxy

    go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ~/go/bin/xcaddy build --with github.com/caddy-dns/cloudflare --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive --output ycycxz-caddy-with-cloudflare-dns-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 ~/go/bin/xcaddy build --with github.com/caddy-dns/cloudflare --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive --output ycycxz-caddy-with-cloudflare-dns-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-caddy*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best
    {
    acme_dns cloudflare Y1PN
    }
  12. shadowsocks-rust

    rustup toolchain install nightly
    rustup override set nightly
    #cargo install cross

    git clone https://github.com/shadowsocks/shadowsocks-rust.git ss-rust > /dev/null
    cd ss-rust

    cargo build -Z unstable-options -rq --out-dir ../
    cd ../
    rm -rf ss-rust
    #upx --best ss*
  13. geoip geosite

    wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/raw/release/geoip.dat &> /dev/null
    wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/raw/release/geosite.dat &> /dev/null
    wget -q https://github.com/SagerNet/sing-geoip/releases/download/20230812/geoip.db &> /dev/null
    wget -q https://github.com/SagerNet/sing-geosite/releases/download/20230807051510/geosite.db &> /dev/null
  14. cloudflare-go

    git clone -b master https://github.com/cloudflare/cloudflare-go  > /dev/null
    cd cloudflare-go/cmd/flarectl
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-flarectl-linux-amd64 &
    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w -buildid=" -o ycycxz-flarectl-linux-arm64 &
    wait;echo DONE!
    #upx --best ycycxz-flarectl*
    find * -type f -name "ycycxz*" ! -name "*macos-arm64*" | xargs upx --best

    视频教程