Skip to content

Commit

Permalink
Attempt to build libmozc.so
Browse files Browse the repository at this point in the history
  • Loading branch information
yukawa committed Oct 27, 2023
1 parent d3151bb commit 45e94f2
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 93 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,11 @@ jobs:
- name: build
working-directory: ./src
run: |
mkdir android_artifacts
mkdir android_artifacts/armeabi-v7a
mkdir android_artifacts/arm64-v8a
mkdir android_artifacts/x86
mkdir android_artifacts/x86_64
bazel build --config oss_android package --cpu=armeabi-v7a
cp bazel-bin/android/jni/libmozcjni.so android_artifacts/armeabi-v7a/
bazel build --config oss_android package --cpu=arm64-v8a
cp bazel-bin/android/jni/libmozcjni.so android_artifacts/arm64-v8a/
bazel build --config oss_android package --cpu=x86
cp bazel-bin/android/jni/libmozcjni.so android_artifacts/x86/
bazel build --config oss_android package --cpu=x86_64
cp bazel-bin/android/jni/libmozcjni.so android_artifacts/x86_64/
bazel build --config oss_android package package
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: libmozcjni.so
path: src/android_artifacts/
name: mozc.apk
path: src/bazel-bin/android/jni/mozc.apk
if-no-files-found: warn
4 changes: 2 additions & 2 deletions src/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ build:prod_windows --define TARGET=prod_windows --build_tag_filters=-nowin

# Android / OSS Android (same configurations)
build:android --define TARGET=oss_android --copt "-DOS_ANDROID"
build:android --crosstool_top=@androidndk//:toolchain --cpu=armeabi-v7a
build:android --android_crosstool_top=@androidndk//:toolchain --fat_apk_cpu=armeabi-v7a,arm64-v8a,x86,x86_64
build:android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
build:android --build_tag_filters=-noandroid
test:android --test_tag_filters=-noandroid
build:oss_android --define TARGET=oss_android --copt "-DOS_ANDROID"
build:oss_android --crosstool_top=@androidndk//:toolchain --cpu=armeabi-v7a
build:oss_android --android_crosstool_top=@androidndk//:toolchain --fat_apk_cpu=armeabi-v7a,arm64-v8a,x86,x86_64
build:oss_android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
build:oss_android --build_tag_filters=-noandroid
test:oss_android --test_tag_filters=-noandroid
30 changes: 20 additions & 10 deletions src/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,34 @@ apple_rules_dependencies()


# Android NDK setup
RULES_ANDROID_NDK_COMMIT= "44dcd014f4b126f8941c29ff1b25e1584bd3eb26"
RULES_ANDROID_NDK_SHA = "79b1857e8e05e3007ad090a3269d2932e988b3ed176d7abd042719d45eb51500"
RULES_ANDROID_NDK_COMMIT= "877c68ef34c9f3353028bf490d269230c1990483"
RULES_ANDROID_NDK_SHA = "b1a5ddd784e6ed915c2035c0db536a278b5f50c64412128c06877115991391ef"

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_android_ndk",
url = "https://github.com/bazelbuild/rules_android_ndk/archive/%s.zip" % RULES_ANDROID_NDK_COMMIT,
sha256 = RULES_ANDROID_NDK_SHA,
strip_prefix = "rules_android_ndk-%s" % RULES_ANDROID_NDK_COMMIT,
)
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")
android_ndk_repository(
name = "androidndk",
api_level = 31,
)

http_archive(
name = "build_bazel_rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
strip_prefix = "rules_android-0.1.1",
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
)

# Check the ANDROID_NDK_HOME envvar, if it is specified set up NDK as follows
# load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")
# android_ndk_repository(name="androidndk")
# If it is empty, do nothing.
load("@//bazel:android_repository.bzl", "android_repository")
android_repository(name = "android_repository")
load("@android_repository//:setup.bzl", "android_ndk_setup")
android_ndk_setup()
load("@build_bazel_rules_android//android:rules.bzl", "android_sdk_repository")

android_sdk_repository(
name = "androidsdk",
)

# Windows Implementation Library (WIL)
# https://github.com/microsoft/wil/
Expand Down
56 changes: 56 additions & 0 deletions src/android/jni/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010-2023, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.mozc.android.build"
android:versionCode="1"
android:versionName="1.0.0.0"
>
<uses-sdk
android:minSdkVersion="31"
android:targetSdkVersion="31" />

<application
android:label="Fake APK for Mozc JNI build"
android:allowBackup="false"
android:supportsRtl="true">
<activity
android:name=".FakeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
21 changes: 21 additions & 0 deletions src/android/jni/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@

load("//:build_defs.bzl", "MOZC_TAGS", "mozc_cc_library")

# https://github.com/bazelbuild/rules_android_ndk/issues/5#issuecomment-1381282580
# To reproduce "libpthread.a", run the following command.
# echo -n -e "create libpthread.a\nsave\nend" | ar -M
cc_library(
name = "fake_pthread",
srcs = ["libpthread.a"],
linkopts = ["-L"+package_name()],
)

mozc_cc_library(
name = "mozcjni",
srcs = ["mozcjni.cc"],
Expand All @@ -56,6 +65,18 @@ mozc_cc_library(
"@com_google_absl//absl/random",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
":fake_pthread",
],
alwayslink = 1,
)

android_binary(
name = "mozc",
srcs = glob([
"NoOpActivity.java",
]),
manifest = "AndroidManifest.xml",
deps = [
":mozcjni",
],
)
40 changes: 40 additions & 0 deletions src/android/jni/FakeActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2010-2023, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package org.mozc.android.build;

import andorid.app.Activity;

public class FakeActivity extends Activity {
@Override
public void OnCreate() {
super.OnCreate();
System.loadLibrary("mozc");
}
}
1 change: 1 addition & 0 deletions src/android/jni/libpthread.a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!<arch>
66 changes: 0 additions & 66 deletions src/bazel/android_repository.bzl

This file was deleted.

0 comments on commit 45e94f2

Please sign in to comment.