Modify clang build flags?
Closed this issue · 2 comments
Hello. Thank you for this project. Getting started with WebRTC is indeed no easy picnic!
I am cross-compiling from Linux/x86_64 to Linux/arm. I was able to successfully build the library after commenting out util.sh lines 293-295 so that is_clang=true and use_sysroot=true.
It was important to use clang because I want to consume this library in an Android project, but not directly, and the default native NDK toolchain seems to be clang-based. I'm not an expert in any of this. Just trying to make things the same as much as possible between the webrtc and Android native build so that they can link.
My current issue is a difference in how floating point values are passed in registers. I would like to try changing the webrtc project to build using "-mfloat-abi=softfp".
Is it possible in your script to inject or modify the compiler flags?
Thanks!
Hi, thanks, it's been awhile but off the top I think you could pass an additional argument to the common_args variable in the compile step (utils.sh:274) and it would get picked up by the webrtc build system. Try arm_float_abi=\"hard\"
, yes I also commented out 293-295 to use clang and the generated ninja output files seem to have picked up -mfloat-abi=hard, this was run with ./build.sh -t android -c arm
. Sorry currently I don't see a way to pass in any args from the shell environment at runtime.
diff --git a/util.sh b/util.sh
index d889fb4..11a4d8f 100644
--- a/util.sh
+++ b/util.sh
@@ -271,7 +271,7 @@ function compile() {
local target_cpu="$4"
local configs="$5"
local disable_iterator_debug="$6"
- local common_args="is_component_build=false rtc_include_tests=false treat_warnings_as_errors=false"
+ local common_args="arm_float_abi=\"hard\" is_component_build=false rtc_include_tests=false treat_warnings_as_errors=false"
local target_args="target_os=\"$target_os\" target_cpu=\"$target_cpu\""
[ "$disable_iterator_debug" = 1 ] && common_args+=' enable_iterator_debugging=false'
@@ -290,9 +290,9 @@ function compile() {
*)
# On Linux when not cross-compiling, use clang = false and sysroot = false
# to build using gcc. Comment this out to use clang.
- if [[ $platform = 'linux' && $target_os != 'android' && $target_cpu != amd* ]]; then
- target_args+=" is_clang=false use_sysroot=false"
- fi
+ # if [[ $platform = 'linux' && $target_os != 'android' && $target_cpu != amd* ]]; then
+ # target_args+=" is_clang=false use_sysroot=false"
+ # fi
# Debug builds are component builds (shared libraries) by default unless
# is_component_build=false is passed to gn gen --args. Release builds are
Thank you for the quick reply and helpful answer. I'm new to the Android platform, and I've gathered it has discontinued support for "hard" floats some time ago. I was hoping I could build the webrtc lib with "softfp" semantics, but that yielded some build errors like this:
./build.sh -b branch-heads/71 -t linux -c arm -n Release
...
../../build/linux/debian_sid_arm-sysroot/usr/include/arm-linux-gnueabihf/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-soft.h' file not found
# include <gnu/stubs-soft.h>
^~~~~~~~~~~~~~~~~~
Maybe those issues are solvable.. I haven't followed up on that yet, but will if it seems like a promising angle. I thought I should try building for android first, to see how that goes. Even though I won't access this library from android directly (it will be via another .so/.aar that needs it to link with), it might still produce a compatible binary. I get these kinds of errors in that case (arm_float_abi param removed):
./build.sh -b branch-heads/71 -t android -c arm -n Release
...
[2324/3004] ACTION //third_party/android_tools:android_sdk_java(//build/toolchain/android:android_clang_arm)
FAILED: lib.java/third_party/android_tools/android.interface.jar
python ../../build/android/gyp/ijar.py clang_x64/ijar ../../third_party/android_tools/sdk/platforms/android-28/android.jar lib.java/third_party/android_tools/android.interface.jar
ftruncate(): Invalid argument
Traceback (most recent call last):
File "../../build/android/gyp/ijar.py", line 24, in <module>
main()
File "../../build/android/gyp/ijar.py", line 20, in main
subprocess.check_call([ijar_bin, in_jar, f.name])
File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['clang_x64/ijar', '../../third_party/android_tools/sdk/platforms/android-28/android.jar', '/mnt/d/code/vsimon/webrtcbuilds/out/src/out/Release/lib.java/third_party/android_tools/tmppOmFwrandroid.interface.jar']' returned non-zero exit status -6
It's probably not necessary to build android. I think linux should suffice, but these are new waters for me.
Anyhow, thanks again for the quick and helpful response. If you have experience to share about navigating the above I appreciate it, but otherwise I don't want to burden and will close the issue now as you've answered my question.