Hi, I want to use Intel compiler(icpc or icc) in Bazel because I want to use a lot of options with Intel machine.But, CROSSTOOL didn't work and I don't know what I set the entire job.
In the link(https://github.com/bazelbuild/bazel/issues/629), people say "Try to modify tools/cpp/CROSSTOOL"
So, I just modify CROSSTOOL with below process
First, I downloaded bazel source file(git clone https://github.com/google/bazel/)
Second, I edited the CROSSTOOL file in [BAZEL_HOME]/tools/cpp/CROSSTOOL(Because I use CentOs 7.2, I just edit local_linux)
toolchain { abi_version: "local" abi_libc_version: "local" builtin_sysroot: "" compiler: "compiler" host_system_name: "local" needsPic: true supports_gold_linker: false supports_incremental_linker: false supports_fission: false supports_interface_shared_objects: false supports_normalizing_ar: false supports_start_end_lib: false target_libc: "local" target_cpu: "local" target_system_name: "local" toolchain_identifier: "local_linux"
tool_path { name: "ar" path: "/usr/bin/ar" } tool_path { name: "compat-ld" path: "/usr/bin/ld" } tool_path { name: "cpp" path: "/usr/bin/cpp" } tool_path { name: "dwp" path: "/usr/bin/dwp" }
- tool_path { name: "gcc" path: "/usr/bin/gcc" }
+ tool_path { name: "gcc" path: "/usr/bin/icpc" } cxx_flag: "-std=c++0x" linker_flag: "-lstdc++" linker_flag: "-B/usr/bin/"
# TODO(bazel-team): In theory, the path here ought to exactly match the path # used by gcc. That works because bazel currently doesn't track files at # absolute locations and has no remote execution, yet. However, this will need # to be fixed, maybe with auto-detection?
- cxx_builtin_include_directory: "/usr/lib/gcc"
+ cxx_builtin_include_directory: "/opt/intel/compilers_and_libraries_2016.3.210/linux/bin/intel64" cxx_builtin_include_directory: "/usr/local/include" cxx_builtin_include_directory: "/usr/include" tool_path { name: "gcov" path: "/usr/bin/gcov" }
# C(++) compiles invoke the compiler (as that is the one knowing where # to find libraries), but we provide LD so other rules can invoke the linker. tool_path { name: "ld" path: "/usr/bin/ld" }
tool_path { name: "nm" path: "/usr/bin/nm" } tool_path { name: "objcopy" path: "/usr/bin/objcopy" } objcopy_embed_flag: "-I" objcopy_embed_flag: "binary" tool_path { name: "objdump" path: "/usr/bin/objdump" } tool_path { name: "strip" path: "/usr/bin/strip" }
# Anticipated future default. unfiltered_cxx_flag: "-no-canonical-prefixes" unfiltered_cxx_flag: "-fno-canonical-system-headers"
# Make C++ compilation deterministic. Use linkstamping instead of these # compiler symbols. unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
# Security hardening on by default. # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. # We need to undef it before redefining it as some distributions now have # it enabled by default. compiler_flag: "-U_FORTIFY_SOURCE" compiler_flag: "-D_FORTIFY_SOURCE=1" compiler_flag: "-fstack-protector" linker_flag: "-Wl,-z,relro,-z,now"
# Enable coloring even if there's no attached terminal. Bazel removes the # escape sequences if --nocolor is specified. This isn't supported by gcc # on Ubuntu 14.04. # compiler_flag: "-fcolor-diagnostics"
# All warnings are enabled. Maybe enable -Werror as well? compiler_flag: "-Wall" # Enable a few more warnings that aren't part of -Wall. compiler_flag: "-Wunused-but-set-parameter" # But disable some that are problematic. compiler_flag: "-Wno-free-nonheap-object" # has false positives
# Keep stack frames for debugging, even in opt mode. compiler_flag: "-fno-omit-frame-pointer"
# Anticipated future default. linker_flag: "-no-canonical-prefixes" # Have gcc return the exit code from ld. linker_flag: "-pass-exit-codes" # Stamp the binary with a unique identifier. linker_flag: "-Wl,--build-id=md5" linker_flag: "-Wl,--hash-style=gnu" # Gold linker only? Can we enable this by default? # linker_flag: "-Wl,--warn-execstack" # linker_flag: "-Wl,--detect-odr-violations"
compilation_mode_flags { mode: DBG # Enable debug symbols. compiler_flag: "-g" } compilation_mode_flags { mode: OPT
# No debug symbols. # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or # even generally? However, that can't happen here, as it requires special # handling in Bazel. compiler_flag: "-g0"
# Conservative choice for -O # -O3 can increase binary size and even slow down the resulting binaries. # Profile first and / or use FDO if you need better performance than this. compiler_flag: "-O2"
# Disable assertions compiler_flag: "-DNDEBUG"
# Removal of unused code and data at link time (can this increase binary size in some cases?). compiler_flag: "-ffunction-sections" compiler_flag: "-fdata-sections" linker_flag: "-Wl,--gc-sections" } linking_mode_flags { mode: DYNAMIC }}Third, build with command "./compile.sh" (That's all)
after compile process, I thought that default compiler changed from gcc to icpc.
However, when I build the simple example, bazel continually use the gcc.
[bazel_test]$ bazel build --verbose_failures --config debug -c opt //src:main
INFO: Found 1 target...
INFO: From Compiling src/main.cc:
gcc: warning: /opt/intel/vtune_amplifier_xe_2016/lib64/libittnotify.a: linker input file unused because linking not done
ERROR: /home/xxxxx/bazel_test/src/BUILD:1:1: Linking of rule '//src:main' failed: linux-sandbox failed: error executing command
(cd /home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-1/bazel_test/execroot/bazel_test &&\
exec env - \
/home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/execroot/bazel_test/_bin/linux-sandbox @/home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-1/bazel_test/linux-sandbox.params -- /usr/bin/gcc -o bazel-out/local-opt/bin/src/main -Wl,-no-as-needed -B/usr/bin -B/usr/bin -pass-exit-codes '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -Wl,--gc-sections -Wl,@bazel-out/local-opt/bin/src/main-2.params).
bazel-out/local-opt/bin/src/_objs/main/src/main.o: In function `main':
/home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-0/bazel_test/execroot/bazel_test/src/main.cc:36: undefined reference to `__itt_pause_ptr__3_0'
/home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-0/bazel_test/execroot/bazel_test/src/main.cc:42: undefined reference to `__itt_resume_ptr__3_0'
collect2: error: ld returned 1 exit status
Target //src:main failed to build
INFO: Elapsed time: 0.463s, Critical Path: 0.35s
I want to use icpc with default bazel compiler because icpc only can build some option.
Please tell me about solution. thank you!
--
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-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0d2e81bd-17fb-4132-9bc4-3423a424975f%40googlegroups.com.
On a related note: have you tried just setting CC=icpc when you run `bazel build` instead of hand-writing a CROSSTOOL? cc_configure.bzl tries to auto-detect the settings for a compiler specified that way. However, I'm not sure it'll work with anything other than GCC or Clang.
I do recommend looking through that tutorial (you can ignore the parts about wrapper scripts and downloading the toolchain). If you want to use a different system compiler, you should probably start by copying Bazel's tools/cpp/BUILD and tools/cpp/CROSSTOOL into a folder in your source tree and pointing --crosstool_top there. The tutorial explains a bit more about what goes in that BUILD file.I think the two pieces you were missing are needing to rebuild Bazel (and use the newly built bazel binary) to pick up changes to the tools/cpp folder in the Bazel source tree, and that on Linux it defaults to using tools/cpp/cc_configure.bzl to generate a CROSSTOOL instead of the tools/cpp/CROSSTOOL file in the source tree directly. Using your own --crosstool_top avoids both of those.On a related note: have you tried just setting CC=icpc when you run `bazel build` instead of hand-writing a CROSSTOOL? cc_configure.bzl tries to auto-detect the settings for a compiler specified that way. However, I'm not sure it'll work with anything other than GCC or Clang.
On Tue, Sep 20, 2016 at 9:41 AM, Ningyu Shi <shin...@gmail.com> wrote:
There is nothing to do with bazel itself's CROSSTOOL file. You can follow this Tutorial to setup any non-default compiler.ThanksNingyu
On Sunday, September 18, 2016 at 12:35:14 AM UTC-5, Sunjung Lee wrote:Hi, I want to use Intel compiler(icpc or icc) in Bazel because I want to use a lot of options with Intel machine.But, CROSSTOOL didn't work and I don't know what I set the entire job.I use CentOs 7.2 and default compiler is gcc 4.8.3If anyone know about that, Please tell me.Thank you for reading!
--
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.
On a related note: have you tried just setting CC=icpc when you run `bazel build` instead of hand-writing a CROSSTOOL? cc_configure.bzl tries to auto-detect the settings for a compiler specified that way. However, I'm not sure it'll work with anything other than GCC or Clang.I don't understand the sentence 'just setting CC=icpc'.The meaning is weather change the linux default CC to icpc or add bazel option?(like --compiler name)If you said about add bazel option, what is the option command?Thank you.