how to set CC, CFLAGS, CXXFLAGS in bazel

6,564 views
Skip to first unread message

Ghilas BELHADJ

unread,
Dec 12, 2016, 5:38:24 AM12/12/16
to bazel-discuss
I'd like to use obfuscator-llvm with bazel.

So, I have to set a special clang, and some flags to get this works.

$ CC=path_to_the/build/bin/clang
$ CFLAGS
+="-mllvm -fla" or CXXFLAGS+="-mllvm -fla" (or any other obfuscation-related flags)
$
./configure
$ make
how can I do that in bazel ?

Damien Martin-guillerez

unread,
Dec 12, 2016, 5:40:25 AM12/12/16
to Ghilas BELHADJ, bazel-discuss
CC is set the same way. We do not parse CFLAGS or CXXFLAGS currently but I think this is an acceptable contribution. See https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl for the file that does it.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/2933bd67-180f-471a-93b5-9a8dbcf5dcbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ghilas BELHADJ

unread,
Dec 12, 2016, 5:51:29 AM12/12/16
to bazel-discuss
@Damien Thank you for your answer.

For CFLAGS and CXXFLAGS I can set them with --copt and --cxxopt ?

Damien Martin-guillerez

unread,
Dec 12, 2016, 5:58:01 AM12/12/16
to Ghilas BELHADJ, bazel-discuss
Just --copt yes.

I don't think we separate C++ and C unfortunately.

On Mon, Dec 12, 2016 at 11:51 AM Ghilas BELHADJ <ghilas...@gmail.com> wrote:
@Damien Thank you for your answer.

For CFLAGS and CXXFLAGS I can set them with --copt and --cxxopt ?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Ghilas BELHADJ

unread,
Dec 12, 2016, 6:35:37 AM12/12/16
to bazel-discuss
I have set CC the same way. and put the flags CFLAGS and CXXFLAGS like this in the bazel build command

'--cxxopt=-mllvm -fla','--copt=-mllvm -fla',

And I got this error

 arm-linux-androideabi-gcc: error: unrecognized command line option '-mllvm -fla'


Damien Martin-guillerez

unread,
Dec 12, 2016, 6:51:23 AM12/12/16
to Ghilas BELHADJ, bazel-discuss, ahum...@google.com
+Alex Humesky Why does --copt propagate to Android NDK?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Ghilas BELHADJ

unread,
Dec 12, 2016, 8:08:57 AM12/12/16
to bazel-discuss
Maybe I'm doing it wrong.

Here is the list of complete options I'm using to build if it can help.

bazel build -c opt
 
--cxxopt=-mllvm -fla
 
--copt=-mllvm -fla
 
//:libfoo.so
 
--crosstool_top=//external:android/crosstool
 
--cpu=armeabi-v7a
 
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain
 
--verbose_failures
 
--genrule_strategy=standalone
 
--spawn_strategy=standalone



Damien Martin-guillerez

unread,
Dec 12, 2016, 8:17:51 AM12/12/16
to Ghilas BELHADJ, bazel-discuss
Oh you need to use --host_copt instead --copt because you want it to apply to the host C++ toolchain, not the target one

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Ghilas BELHADJ

unread,
Dec 12, 2016, 8:28:20 AM12/12/16
to bazel-discuss
The error has changed, now it's:

clang: error: unknown argument: '-mllvm -fla'

I think bazel il always using the default clang.

Damien Martin-guillerez

unread,
Dec 12, 2016, 8:55:14 AM12/12/16
to Ghilas BELHADJ, bazel-discuss
Can you try --host_copt="-mllvm -fla" and --host_copt=-mllvm --host_copt=-fla? I don't rememebr the exact syntax. Also add --verbose_failures for more help.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Ghilas BELHADJ

unread,
Dec 12, 2016, 9:04:21 AM12/12/16
to bazel-discuss
With

--host_copt=-mllvm --host_copt=-fla --verbose_failures

I have this error:

clang (LLVM option parsing): Unknown command line argument '-fla'.  Try: 'clang (LLVM option parsing) -help'
clang
(LLVM option parsing): Did you mean '-help'?

With:

--host_copt="-mllvm -fla" --verbose_failures

I have this one

Ghilas BELHADJ

unread,
Dec 12, 2016, 9:27:51 AM12/12/16
to bazel-discuss
setting a wrong clang path does not affect bazel build.

CC=wrong_path_to_the/build/bin/clang

I think the CC variable is not parsed in bazel.

Maybe I should create a custom toolchain to do this ?



Ghilas BELHADJ

unread,
Dec 12, 2016, 11:12:22 AM12/12/16
to bazel-discuss
It works when I run 

bazel clean

But now standard libraries are not recognised.

external/protobuf/src/google/protobuf/stubs/common.h:38:10: fatal error: 'string' file not found
#include <string>
         
^
1 error generated.


Ghilas BELHADJ

unread,
Dec 13, 2016, 9:20:44 AM12/13/16
to bazel-discuss
I've added -s parameter to bazel build. and now I can see that some paths are not included when I set CC to a new clang.

with original clang
-isystem external/protobuf/src
-isystem bazel-out/arm-linux-androideabi-4.9-v7a-gnu-libstdcpp-opt/genfiles/external/protobuf/src
-isystem external/bazel_tools/tools/cpp/gcc3
-isystem external/eigen_archive
-isystem bazel-out/arm-linux-androideabi-4.9-v7a-gnu-libstdcpp-opt/genfiles/external/eigen_archive
-isystem external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include

-isystem external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include-fixed
-isystem external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include
-isystem external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include
-isystem external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/backward


with new clang
-isystem external/protobuf/src
-isystem bazel-out/host/genfiles/external/protobuf/src
-isystem external/bazel_tools/tools/cpp/gcc3

any help  to fix that ?
Reply all
Reply to author
Forward
0 new messages