- Notifications
You must be signed in to change notification settings - Fork3
yicm/BazelMixedLanguage
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
[toc]
- Support to build cpp application or library with bazel platform
- Support to build golang application or library with bazel platform
- Support to build android jni library with bazel platform(generate jni header automatically, end-to-end)
- Support to build android application(non-platform)
- WSL,Ubuntu18.04
- Bazel 3.3+
- Android JNI Library
- Local JDK 8+(just for using
javah
orjavac
to generate native headers)sudo apt install openjdk-8-jdk-headless
- Android sdkmanager (https://developer.android.com/studio#command-tools)
- config the environment of
sdkmanager
sdkmanager --sdk_root=$HOME/Android --list
sdkmanager --sdk_root=$HOME/Android 'build-tools;29.0.2'
sdkmanager --sdk_root=$HOME/Android 'platforms;android-28'
sdkmanager --sdk_root=$HOME/Android --install "ndk;18.1.5063045"
- more older releases:https://developer.android.com/ndk/downloads/older_releases ,also you can get the support list by
--list
- more older releases:https://developer.android.com/ndk/downloads/older_releases ,also you can get the support list by
- config the environment of
- Local JDK 8+(just for using
$ sudo apt-get install gcc$ sudo apt-get install g++$ sudo apt-get install gcc-arm-linux-gnueabihf$ sudo apt-get install g++-arm-linux-gnueabihf
- Open
.bazelrc
file:
build --toolchain_resolution_debug# --------------------------# Way1: enable/disable --crosstool_top,--cpu# --------------------------build:compiler_config --crosstool_top=//toolchains/cpp:compiler_suitebuild:compiler_config --cpu=ubuntu_gccbuild:compiler_config --host_crosstool_top=@bazel_tools//tools/cpp:toolchain# --------------------------# Way2: enable/diable platform# --------------------------#build --incompatible_enable_cc_toolchain_resolution
- Open
toolchains/cpp/BUILD
, and commentgenerate_toolchains
function, and uncommentgenerate_toolchain_suite
function.
To build this example you can use:
$ bazel build //cpp:hello-world
This compilation will only use the default compiler of the local machine.
- step1: config your toolchains path:
toolchain/cpp/supported.bzl
- step2: build
# Default compilation configuration, --cpu : ubuntu_gcc$ bazel build --config=compiler_config //cpp:hello-world# Specify the toolchain to compile the target$ bazel build --config=compiler_config --cpu=ubuntu_arm_linux_gnueabihf //cpp:hello-world
- cpp
- golang
- Open
.bazelrc
file:
build --toolchain_resolution_debug# --------------------------# Way1: enable/disable --crosstool_top,--cpu# --------------------------#build:compiler_config --crosstool_top=//toolchains/cpp:compiler_suite#build:compiler_config --cpu=ubuntu_gcc#build:compiler_config --host_crosstool_top=@bazel_tools//tools/cpp:toolchain# --------------------------# Way2: enable/diable platform# --------------------------build --incompatible_enable_cc_toolchain_resolution
- Open
toolchains/cpp/BUILD
, and commentgenerate_toolchain_suite
function, and uncommentgenerate_toolchains
function.
# to view all supported platforms$ bazel cquery"//platforms:all"# to view all android_sdk targets generated by android_sdk_repository$ bazel query"kind(android_sdk, @androidsdk//...)"
# p_ubuntu_gcc$ bazel build cpp:hello-world --platforms=//platforms:p_ubuntu_gcc# p_ubuntu_arm_linux_gnueabihf$ bazel build cpp:hello-world --platforms=//platforms:p_ubuntu_arm_linux_gnueabihf
$ bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 golang/cmd/hello$ bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm //golang/cmd/hello
# build all targets$ bazel build --platforms=//platforms:p_ubuntu_gcc //...
# Remote caching$ bazel clean$ bazel build --remote_cache=grpc://10.151.176.11:8980 cpp:hello-world --platforms=//platforms:p_ubuntu_arm_linux_gnueabihf
# Only Build Android JNI Library$ bazel build --platforms=//platforms:p_android_armv7a android:gen_jni_header$ bazel build --platforms=//platforms:p_android_armv7a android:jni_lib_shared$ bazel build --platforms=//platforms:p_android_aarch64 android:jni_lib_shared
# Build and Install Android Application(including jni/java library)# First, you need to turn off the bazel platform feature in .bazelrc# archs: armeabi-v7a/arm64-v8/x86# way1$ bazel build android/demo/app/src/main:app --fat_apk_cpu=arm64-v8a# way2$ bazel build android/demo/app/src/main:app --config=android_arm64-v8a# Install apk# Maybe you'll have this problem: https://github.com/bazelbuild/examples/issues/120# way1$ bazel mobile-install android/demo/app/src/main:app# way2$ adb install bazel-bin/android/demo/app/src/main/app.apk
# view APK package information$ zipinfo -l app.apk# view application stack information$ adb shell dumpsys meminfo net.xiaobaiai.app
All toolchain information is in file
toolchains/cpp/supported.bzl
.