Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android c++ build under Windows, command line to long #7982

Closed
MarkaRagnos0815 opened this issue Apr 9, 2019 · 7 comments
Closed

Android c++ build under Windows, command line to long #7982

MarkaRagnos0815 opened this issue Apr 9, 2019 · 7 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) platform: windows team-Android Issues for Android team type: bug

Comments

@MarkaRagnos0815
Copy link

MarkaRagnos0815 commented Apr 9, 2019

Description of the problem / feature requests

I am trying to build a c++ library using bazel under windows. I am using the following command:
bazel build <target> --compilation_mode=opt --crosstool_top=@androidndk//:default_crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a
I am getting the following error message:
Action failed to execute: java.io.IOException: ERROR: src/main/native/windows/processes-jni.cc(429): CreateProcessWithExplicitHandles("<user>\_bazel_exb_a\kkszmrzt\execroot\dbsdk\external\androidndk\ndk\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ar" rcsD bazel-out/armeabi-v7a-(...)): command is longer than CreateProcessW's limit (32767 characters)
Unlike Linux/windows build that are using a linker input file for commands the ndk version passes all parameters via command line

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  • create a cc_binary for android
  • add as much as possible files to exceed 32K of characters in command line
  • see failing build

What operating system are you running Bazel on?

  • windows 10

What's the output of bazel info release?

  • release 0.24.1

Have you found anything relevant by searching the web?

  • no
@MarkaRagnos0815 MarkaRagnos0815 changed the title Android c++ build under Windows Android c++ build under Windows, command line to long Apr 9, 2019
@jin jin added team-Android Issues for Android team untriaged labels Apr 9, 2019
@jin
Copy link
Member

jin commented Apr 10, 2019

@laszlocsomor how do you typical deal with issues like this on Windows? Param files?

@MarkaRagnos0815
Copy link
Author

MarkaRagnos0815 commented Apr 10, 2019

yes, param files should work (like normal bazel k8 build does)

@laszlocsomor
Copy link
Contributor

@jin: Yes, with param files. Beware there's no standard encoding (that I know), so use ASCII to stay safe.

@ahumesky ahumesky added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Apr 16, 2019
@meteorcloudy
Copy link
Member

_bazel_exb_a\kkszmrzt\execroot\dbsdk\external\androidndk\ndk\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ar"

It's weird to run an arm linux binary on Windows, I guess the rule doesn't work on Windows at all?

Anyway, this issue looks obsolete, please reopen if the issue still exists.

@homuler
Copy link
Contributor

homuler commented Nov 27, 2021

This issue still exist, but I'm sorry for not being able to show you the smallest example.

Windows: 10 Pro 21H2 (19044.1348)
Bazel: 4.2.1
Android SDK Build Tools: 30.0.3
Android NDK: 21.4.7075529

At least, I can reproduce this error with google/mediapipe repository.
For now, mediapipe does not support Android build on Windows, so we need to apply a following patch.

diff --git a/WORKSPACE b/WORKSPACE
index 9dbbff3..1cfaecc 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -96,6 +96,7 @@ http_archive(
     ],
     patches = [
         "@//third_party:com_github_glog_glog_9779e5ea6ef59562b030248947f787d1256132ae.diff",
+        "@//third_party:com_github_glog_glog_no_gflags.diff",
     ],
     patch_args = [
         "-p1",
diff --git a/third_party/com_github_glog_glog_no_gflags.diff b/third_party/com_github_glog_glog_no_gflags.diff
new file mode 100644
index 0000000..f266d7e
--- /dev/null
+++ b/third_party/com_github_glog_glog_no_gflags.diff
@@ -0,0 +1,28 @@
+diff --git a/bazel/glog.bzl b/bazel/glog.bzl
+index a46e2d1..5f63514 100644
+--- a/bazel/glog.bzl
++++ b/bazel/glog.bzl
+@@ -107,12 +107,12 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
+             "src/utilities.h",
+             "src/vlog_is_on.cc",
+         ] + select({
+-            "@bazel_tools//src/conditions:windows": windows_only_srcs,
++            "@//mediapipe:windows": windows_only_srcs,
+             "//conditions:default": [":config_h"],
+         }),
+         copts =
+             select({
+-                "@bazel_tools//src/conditions:windows": common_copts + windows_only_copts,
++                "@//mediapipe:windows": common_copts + windows_only_copts,
+                 "@bazel_tools//src/conditions:darwin": common_copts + linux_or_darwin_copts + darwin_only_copts,
+                 "@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts,
+                 ":wasm": common_copts + wasm_copts,
+@@ -128,7 +128,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
+     native.cc_library(
+         name = "glog_headers",
+         deps = select({
+-            "@bazel_tools//src/conditions:windows": [":windows_glog_headers"],
++            "@//mediapipe:windows": [":windows_glog_headers"],
+             "//conditions:default": [":default_glog_headers"],
+         }),
+     )

After that, when I run the below command, then this error occurs (total parameter's length is about 35,000).

bazel build -c opt --action_env PYTHON_BIN_PATH="C://path//to//python.exe" --verbose_failures --config=android_arm64 --noenable_platform_specific_config --cxxopt=-std=c++17 //mediapipe/examples/android/src/java/com/google/mediapipe/apps/facedetectiongpu:facedetectiongpu

Action failed to execute: java.io.IOException: ERROR: src/main/native/windows/process.cc(165): CreateProcessWithExplicitHandles("C:\users\homul_bazel_homul\auxtleee\execroot\mediapipe\external\androidndk\ndk\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\bin\aarch64-linux-android-ar" rcsD bazel-out/android-arm64-v8a-opt/bin/external/XNNPACK/libneonfma_ukernels.pic.a bazel-out/android-arm64-v8a-opt/bin/external/XNNPACK/_objs/neonfma_ukernels/up4x4-minmax-neonfma-acc2.pic.o bazel-out/android-arm64-v8a-opt/bin/external/XNNPACK/_objs/neonfma_ukernels/up4x4-minmax-neonfma.pic.o bazel-out/android-arm64-v8a-(...)): command is longer than CreateProcessW's limit (32767 characters)
Target //mediapipe/examples/android/src/java/com/google/mediapipe/apps/facedetectiongpu:facedetectiongpu failed to build
INFO: Elapsed time: 11.464s, Critical Path: 9.91s
INFO: 219 processes: 129 internal, 90 local.
FAILED: Build did NOT complete successfully

@homuler
Copy link
Contributor

homuler commented Nov 28, 2021

I'm not sure but it may be caused by the below line.

If I change 0 to 1, the error has gone.

@meteorcloudy
Copy link
Member

@ahumesky Do all android toolchains support parameter files? If so we probably could turn it on by default to avoid this command length issue on Windows.

bazel-io pushed a commit that referenced this issue May 12, 2022
Fix #7982

Currently, on Windows, `ar` command can fail when using Android NDK and the arguments length is too long.
This PR resolves it by enabling `--features=compiler_param_file` option for Android NDK, but I'm not sure if all commands in all versions of NDK that should be supported are compatible with this.

Closes #14457.

PiperOrigin-RevId: 448334050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) platform: windows team-Android Issues for Android team type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants