一、编译C++程序
1、在项目根目录的WROKSPACE文件添加以下配置
//WORKSPACE文件
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_android_ndk",
sha256 = "b1a5ddd784e6ed915c2035c0db536a278b5f50c64412128c06877115991391ef",
strip_prefix = "rules_android_ndk-877c68ef34c9f3353028bf490d269230c1990483",
url = "https://github.com/bazelbuild/rules_android_ndk/archive/877c68ef34c9f3353028bf490d269230c1990483.zip",
)
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")
android_ndk_repository(
name = "androidndk",
path = "/home/client/Documents/program/android-sdk/ndk/25.2.9519653"
)
2、添加BUILD文件,配置源码&平台
配置platform在交叉编译时使用
//BUILD.bazel文件
cc_binary(
name = "hello-world",
srcs = ["hello-world.cc"],
)
platform(
name = "arm64-v8a",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:android",
],
)
3、编译源码
$ bazel build //main:hello-world --platforms=//main:arm64-v8a