From ef5a6448c0c061bc8d46aa51165f7f8eb26ef190 Mon Sep 17 00:00:00 2001 From: openwaygate <27287694+OpenWaygate@users.noreply.github.com> Date: Tue, 27 May 2025 00:27:47 +0800 Subject: [PATCH] :construction_worker: Config bazel cross-compile --- .bazelignore | 9 +++++++++ BUILD.bazel | 38 +++++++++++++++++++++++++++++++++++++- CONTRIBUTING.md | 6 ++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .bazelignore diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000..5f3f706 --- /dev/null +++ b/.bazelignore @@ -0,0 +1,9 @@ +.github +.idea +# Ignore all bazel-* symlinks. There is no full list since this can change +# based on the name of the directory bazel is cloned into. +bazel-* +# Bazelisk version file +.bazelversion + +.DS_Store diff --git a/BUILD.bazel b/BUILD.bazel index 1c5c037..95c0c5b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,5 +1,5 @@ load("@gazelle//:def.bzl", "gazelle") -load("@rules_go//go:def.bzl", "go_binary", "go_library") +load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library") gazelle(name = "gazelle") @@ -39,3 +39,39 @@ go_binary( embed = [":yutu_lib"], visibility = ["//visibility:public"], ) + +go_cross_binary( + name = "yutu-darwin-amd64", + platform = "@rules_go//go/toolchain:darwin_amd64", + target = "yutu", +) + +go_cross_binary( + name = "yutu-darwin-arm64", + platform = "@rules_go//go/toolchain:darwin_arm64", + target = "yutu", +) + +go_cross_binary( + name = "yutu-linux-amd64", + platform = "@rules_go//go/toolchain:linux_amd64", + target = "yutu", +) + +go_cross_binary( + name = "yutu-linux-arm64", + platform = "@rules_go//go/toolchain:linux_arm64", + target = "yutu", +) + +go_cross_binary( + name = "yutu-windows-amd64.exe", + platform = "@rules_go//go/toolchain:windows_amd64", + target = "yutu", +) + +go_cross_binary( + name = "yutu-windows-arm64.exe", + platform = "@rules_go//go/toolchain:windows_arm64", + target = "yutu", +) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d6b3ae2..a54a830 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,12 +14,18 @@ Here are some commands which may useful. # run tests ## unit tests ❯ go test ./... +## or with bazel +❯ bazel test //... ## verify binary commands, detect shorthands conflicts, etc. ❯ ./scripts/command-test.sh # build the binary ## install goreleaser: https://goreleaser.com/install ❯ GITHUB_REPOSITORY=eat-pray-ai/yutu goreleaser build --clean --auto-snapshot +# or with bazel +❯ bazel build //:yutu # build the binary for the current platform +❯ bazel build //... # build all targets +❯ bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:yutu # script to install yutu ❯ ./scripts/install.sh