Skip to content

Instantly share code, notes, and snippets.

@royshil
Created March 8, 2018 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royshil/56a6746f8d6724aeb9928efa88ba7add to your computer and use it in GitHub Desktop.
Save royshil/56a6746f8d6724aeb9928efa88ba7add to your computer and use it in GitHub Desktop.
Scripts for cross-compiling Tensorflow 1.5+ for the Jetson TK1 arm-based SoM
package(default_visibility = ["//visibility:public"])
cc_toolchain_suite(
name = "toolchain",
toolchains = {
"armeabi-v7a|compiler": ":cc-compiler-armeabi",
"k8|compiler": ":cc-compiler-local",
},
)
filegroup(
name = "empty",
srcs = [],
)
filegroup(
name = "arm_linux_all_files",
srcs = [
"@toolchain_target_arm_linux_gnueabi//:compiler_pieces",
],
)
cc_toolchain(
name = "cc-compiler-local",
all_files = ":empty",
compiler_files = ":empty",
cpu = "local",
dwp_files = ":empty",
dynamic_runtime_libs = [":empty"],
linker_files = ":empty",
objcopy_files = ":empty",
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 1,
)
cc_toolchain(
name = "cc-compiler-armeabi",
all_files = ":arm_linux_all_files",
compiler_files = ":arm_linux_all_files",
cpu = "armeabi-v7a",
dwp_files = ":empty",
dynamic_runtime_libs = [":empty"],
linker_files = ":arm_linux_all_files",
objcopy_files = "arm_linux_all_files",
static_runtime_libs = [":empty"],
strip_files = "arm_linux_all_files",
supports_param_files = 1,
)
package(default_visibility = ['//visibility:public'])
filegroup(
name = 'gcc',
srcs = [
'bin/arm-linux-gnueabi-gcc',
],
)
filegroup(
name = 'ar',
srcs = [
'bin/arm-linux-gnueabi-ar',
],
)
filegroup(
name = 'ld',
srcs = [
'bin/arm-linux-gnueabi-ld',
],
)
filegroup(
name = 'nm',
srcs = [
'bin/arm-linux-gnueabi-nm',
],
)
filegroup(
name = 'objcopy',
srcs = [
'bin/arm-linux-gnueabi-objcopy',
],
)
filegroup(
name = 'objdump',
srcs = [
'bin/arm-linux-gnueabi-objdump',
],
)
filegroup(
name = 'strip',
srcs = [
'bin/arm-linux-gnueabi-strip',
],
)
filegroup(
name = 'as',
srcs = [
'bin/arm-linux-gnueabi-as',
],
)
filegroup(
name = 'compiler_pieces',
srcs = glob([
'arm-linux-gnueabi/**',
'libexec/**',
'lib/gcc/arm-linux-gnueabi/**',
'include/**',
]),
)
filegroup(
name = 'compiler_components',
srcs = [
':gcc',
':ar',
':ld',
':nm',
':objcopy',
':objdump',
':strip',
':as',
],
)
major_version: "local"
minor_version: ""
default_target_cpu: "armeabi-v7a"
default_toolchain {
cpu: "armeabi-v7a"
toolchain_identifier: "gcc-linaro-4.9.4"
}
default_toolchain {
cpu: "k8"
toolchain_identifier: "local"
}
toolchain {
abi_version: "armeabi-v7a"
abi_libc_version: "glibc_2.19"
builtin_sysroot: ""
compiler: "compiler"
host_system_name: "armeabi-v7a"
needsPic: true
supports_gold_linker: false
supports_incremental_linker: false
supports_fission: false
supports_interface_shared_objects: false
supports_normalizing_ar: true
supports_start_end_lib: false
supports_thin_archives: true
target_libc: "glibc_2.19"
target_cpu: "armeabi-v7a"
target_system_name: "armeabi-v7a"
toolchain_identifier: "gcc-linaro-4.9.4"
tool_path { name: "ar" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-ar" }
tool_path { name: "compat-ld" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-ld" }
tool_path { name: "cpp" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-cpp" }
tool_path { name: "dwp" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-dwp" }
tool_path { name: "gcc" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-gcc" }
tool_path { name: "gcov" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-gcov" }
tool_path { name: "ld" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-ld" }
tool_path { name: "nm" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-nm" }
tool_path { name: "objcopy" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-objcopy" }
objcopy_embed_flag: "-I"
objcopy_embed_flag: "binary"
tool_path { name: "objdump" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-objdump" }
tool_path { name: "strip" path: "$GCC_ROOT/bin/arm-linux-gnueabihf-strip" }
compiler_flag: "--sysroot=$GCC_ROOT/arm-linux-gnueabihf/libc/"
compiler_flag: "-mfloat-abi=hard"
cxx_builtin_include_directory: "$GCC_ROOT/arm-linux-gnueabihf/include"
cxx_builtin_include_directory: "$GCC_ROOT/arm-linux-gnueabihf/libc/usr/include"
cxx_builtin_include_directory: "$GCC_ROOT/arm-linux-gnueabihf/libc/usr/lib/include"
cxx_builtin_include_directory: "$GCC_ROOT/arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/4.9.3/include-fixed"
cxx_builtin_include_directory: "$GCC_ROOT/include/c++/4.9.4"
cxx_builtin_include_directory: "$GCC_ROOT/arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/4.9.3/include"
cxx_builtin_include_directory: "$GCC_ROOT/arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/4.9.3/include-fixed"
cxx_builtin_include_directory: "$GCC_ROOT/lib/gcc/arm-linux-gnueabihf/4.9.4/include"
cxx_builtin_include_directory: "$GCC_ROOT/lib/gcc/arm-linux-gnueabihf/4.9.4/include-fixed"
cxx_builtin_include_directory: "$GCC_ROOT/arm-linux-gnueabihf/include)%/c++/4.9.4"
linker_flag: "--sysroot=$GCC_ROOT/arm-linux-gnueabihf/libc/"
linker_flag: "-lstdc++"
linker_flag: "-L$GCC_ROOT/arm-linux-gnueabihf/lib"
linker_flag: "-L$GCC_ROOT/arm-linux-gnueabihf/libc/lib"
linker_flag: "-L$GCC_ROOT/arm-linux-gnueabihf/libc/usr/lib"
linker_flag: "-B$GCC_ROOT/arm-linux-gnueabihf/bin"
# Anticipated future default.
# This makes GCC and Clang do what we want when called through symlinks.
unfiltered_cxx_flag: "-no-canonical-prefixes"
linker_flag: "-no-canonical-prefixes"
# 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: "-fstack-protector"
compiler_flag: "-fPIE"
linker_flag: "-pie"
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.
compiler_flag: "-fdiagnostics-color=always"
# 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"
# Stamp the binary with a unique identifier.
linker_flag: "-Wl,--build-id=md5"
linker_flag: "-Wl,--hash-style=gnu"
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"
}
}
toolchain {
toolchain_identifier: "local"
abi_libc_version: "local"
abi_version: "local"
builtin_sysroot: ""
compiler: "compiler"
compiler_flag: "-U_FORTIFY_SOURCE"
compiler_flag: "-D_FORTIFY_SOURCE=2"
compiler_flag: "-fstack-protector"
compiler_flag: "-Wall"
compiler_flag: "-Wl,-z,-relro,-z,now"
compiler_flag: "-B/usr/bin"
compiler_flag: "-B/usr/bin"
compiler_flag: "-Wunused-but-set-parameter"
compiler_flag: "-Wno-free-nonheap-object"
compiler_flag: "-fno-omit-frame-pointer"
cxx_builtin_include_directory: "/usr/include/c++/5"
cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu/c++/5"
cxx_builtin_include_directory: "/usr/include/c++/5/backward"
cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/5/include"
cxx_builtin_include_directory: "/usr/local/include"
cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed"
cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu"
cxx_builtin_include_directory: "/usr/include"
cxx_flag: "-std=c++0x"
host_system_name: "local"
linker_flag: "-lstdc++"
linker_flag: "-lm"
linker_flag: "-Wl,-no-as-needed"
linker_flag: "-B/usr/bin"
linker_flag: "-B/usr/bin"
linker_flag: "-pass-exit-codes"
needsPic: true
objcopy_embed_flag: "-I"
objcopy_embed_flag: "binary"
supports_fission: false
supports_gold_linker: false
supports_incremental_linker: false
supports_interface_shared_objects: false
supports_normalizing_ar: false
supports_start_end_lib: false
supports_thin_archives: false
target_cpu: "k8"
target_libc: "local"
target_system_name: "local"
unfiltered_cxx_flag: "-fno-canonical-system-headers"
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\""
tool_path {name: "ar" path: "/usr/bin/ar" }
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: "gcov" path: "/usr/bin/gcov" }
tool_path {name: "ld" path: "/usr/bin/ld" }
tool_path {name: "nm" path: "/usr/bin/nm" }
tool_path {name: "objcopy" path: "/usr/bin/objcopy" }
tool_path {name: "objdump" path: "/usr/bin/objdump" }
tool_path {name: "strip" path: "/usr/bin/strip" }
compilation_mode_flags {
mode: DBG
compiler_flag: "-g"
}
compilation_mode_flags {
mode: OPT
compiler_flag: "-g0"
compiler_flag: "-O2"
compiler_flag: "-DNDEBUG"
compiler_flag: "-ffunction-sections"
compiler_flag: "-fdata-sections"
linker_flag: "-Wl,--gc-sections"
}
linking_mode_flags { mode: DYNAMIC }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment