From fd0deca524ed1fc824ca3e3cb5f9e4de4e0f3d5b Mon Sep 17 00:00:00 2001 From: Vertexwahn Date: Mon, 10 May 2021 22:10:26 +0200 Subject: [PATCH] Improvements for Bazel build support (#1015) * Pin Imath version to 3.0.1 (instead of Imath 3.0.0 beta) Signed-off-by: Vertexwahn * Add comments for treating compile warnings as errors Signed-off-by: Vertexwahn * Improve config headers for Imath Signed-off-by: Vertexwahn Signed-off-by: Cary Phillips --- .bazelrc | 5 + BUILD.bazel | 51 ++++---- bazel/third_party/Imath.BUILD | 162 ++++---------------------- bazel/third_party/generate_header.bzl | 29 +++++ bazel/third_party/openexr.bzl | 33 +----- 5 files changed, 81 insertions(+), 199 deletions(-) create mode 100644 bazel/third_party/generate_header.bzl diff --git a/.bazelrc b/.bazelrc index c25ae004ae..739b8e7ead 100644 --- a/.bazelrc +++ b/.bazelrc @@ -2,3 +2,8 @@ # Copyright (c) Contributors to the OpenEXR Project. build --symlink_prefix=/ # Out of source build + +# Uncomment this to treat C++ compile warnings as errors +#build --cxxopt=-Wall +#build --cxxopt=-Werror +#build --cxxopt=-Wextra diff --git a/BUILD.bazel b/BUILD.bazel index 27a122b592..f08d2aa3bc 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) Contributors to the OpenEXR Project. -load("//:bazel/third_party/openexr.bzl", "openexr_generate_header") +load("//:bazel/third_party/generate_header.bzl", "generate_header") config_setting( name = "windows_x86_64", @@ -9,19 +9,17 @@ config_setting( visibility = ["//visibility:public"], ) -# generate "IexConfig.h" -openexr_generate_header( +generate_header( name = "IexConfig.h", substitutions = { - "@IEX_NAMESPACE_CUSTOM@": "0", "@IEX_INTERNAL_NAMESPACE@": "Iex_3_0", + "@IEX_NAMESPACE_CUSTOM@": "0", "@IEX_NAMESPACE@": "Iex", }, template = "cmake/IexConfig.h.in", ) -# generate "IexConfigInternal.h" -openexr_generate_header( +generate_header( name = "IexConfigInternal.h", substitutions = { "#cmakedefine HAVE_UCONTEXT_H 1": "/* #undef HAVE_UCONTEXT_H */", @@ -31,48 +29,45 @@ openexr_generate_header( template = "cmake/IexConfigInternal.h.in", ) -# generate "IlmThreadConfig.h" -openexr_generate_header( +generate_header( name = "IlmThreadConfig.h", substitutions = { - "#cmakedefine01 ILMTHREAD_THREADING_ENABLED": "#define ILMTHREAD_THREADING_ENABLED 1", - "#cmakedefine01 ILMTHREAD_HAVE_POSIX_SEMAPHORES": "#define ILMTHREAD_HAVE_POSIX_SEMAPHORES 0", - "@ILMTHREAD_NAMESPACE_CUSTOM@": "0", "@ILMTHREAD_INTERNAL_NAMESPACE@": "IlmThread_3_0", + "@ILMTHREAD_NAMESPACE_CUSTOM@": "0", "@ILMTHREAD_NAMESPACE@": "IlmThread", + "#cmakedefine01 ILMTHREAD_HAVE_POSIX_SEMAPHORES": "#define ILMTHREAD_HAVE_POSIX_SEMAPHORES 0", + "#cmakedefine01 ILMTHREAD_THREADING_ENABLED": "#define ILMTHREAD_THREADING_ENABLED 1", }, template = "cmake/IlmThreadConfig.h.in", ) -# generate "OpenEXRConfig.h" -openexr_generate_header( +generate_header( name = "OpenEXRConfig.h", substitutions = { - "@OPENEXR_NAMESPACE_CUSTOM@": "0", - "@OPENEXR_INTERNAL_IMF_NAMESPACE@": "Imf_3_0", "@OPENEXR_IMF_NAMESPACE@": "Imf", - "@OPENEXR_VERSION@": "3.0.0", - "@OPENEXR_PACKAGE_NAME@": "OpenEXR 3.0.0", + "@OPENEXR_INTERNAL_IMF_NAMESPACE@": "Imf_3_0", + "@OPENEXR_LIB_VERSION@": "3.0.1", + "@OPENEXR_NAMESPACE_CUSTOM@": "0", + "@OPENEXR_PACKAGE_NAME@": "OpenEXR 3.0.1", + "@OPENEXR_VERSION_EXTRA@": "", "@OPENEXR_VERSION_MAJOR@": "3", "@OPENEXR_VERSION_MINOR@": "0", - "@OPENEXR_VERSION_PATCH@": "0", - "@OPENEXR_VERSION_EXTRA@": "", - "#cmakedefine OPENEXR_HAVE_LARGE_STACK 1": "/* #undef OPENEXR_HAVE_LARGE_STACK */", + "@OPENEXR_VERSION_PATCH@": "1", + "@OPENEXR_VERSION@": "3.0.1", "#cmakedefine OPENEXR_ENABLE_API_VISIBILITY": "#define OPENEXR_ENABLE_API_VISIBILITY", - "// This file is auto-generated by the configure step": "// This file is auto-generated by Bazel", + "#cmakedefine OPENEXR_HAVE_LARGE_STACK 1": "/* #undef OPENEXR_HAVE_LARGE_STACK */", }, template = "cmake/OpenEXRConfig.h.in", ) -# generate "OpenEXRConfigInternal.h" -openexr_generate_header( +generate_header( name = "OpenEXRConfigInternal.h", substitutions = { - "#cmakedefine OPENEXR_IMF_HAVE_LINUX_PROCFS 1": "/* #undef OPENEXR_IMF_HAVE_LINUX_PROCFS */", - "#cmakedefine OPENEXR_IMF_HAVE_DARWIN 1": "/* #undef OPENEXR_IMF_HAVE_DARWIN */", "#cmakedefine OPENEXR_IMF_HAVE_COMPLETE_IOMANIP 1": "#define OPENEXR_IMF_HAVE_COMPLETE_IOMANIP 1", - "#cmakedefine OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN 1": "/* #undef OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN */", + "#cmakedefine OPENEXR_IMF_HAVE_DARWIN 1": "/* #undef OPENEXR_IMF_HAVE_DARWIN */", "#cmakedefine OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX 1": "/* #undef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX */", + "#cmakedefine OPENEXR_IMF_HAVE_LINUX_PROCFS 1": "/* #undef OPENEXR_IMF_HAVE_LINUX_PROCFS */", + "#cmakedefine OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN 1": "/* #undef OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN */", }, template = "cmake/OpenEXRConfigInternal.h.in", ) @@ -101,9 +96,9 @@ cc_library( ], includes = ["src/lib/Iex"], deps = [ - ":OpenEXRConfig.h", ":IexConfig.h", ":IexConfigInternal.h", + ":OpenEXRConfig.h", ], ) @@ -363,9 +358,9 @@ cc_library( }), visibility = ["//visibility:public"], deps = [ - ":IlmThread", ":IexConfig.h", ":IexConfigInternal.h", + ":IlmThread", ":IlmThreadConfig.h", ":OpenEXRConfig.h", ":OpenEXRConfigInternal.h", diff --git a/bazel/third_party/Imath.BUILD b/bazel/third_party/Imath.BUILD index 7f2c860501..ec46898d68 100644 --- a/bazel/third_party/Imath.BUILD +++ b/bazel/third_party/Imath.BUILD @@ -1,147 +1,25 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) Contributors to the OpenEXR Project. -# generate "ImathConfig.h" -IMATH_CONFIG_H = """ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenEXR Project. - -// This file is auto-generated by Bazel - -#ifndef INCLUDED_IMATH_CONFIG_H -#define INCLUDED_IMATH_CONFIG_H 1 - -#pragma once - -// -// Options / configuration based on O.S. / compiler -///////////////////// - -// -// Define if the target system has support for large -// stack sizes. -// -/* #undef IMATH_HAVE_LARGE_STACK */ - -////////////////////// -// -// C++ namespace configuration / options - -// Current (internal) library namepace name and corresponding public -// client namespaces. -#define IMATH_INTERNAL_NAMESPACE_CUSTOM 0 -#define IMATH_INTERNAL_NAMESPACE Imath_3_0 - - -#define IMATH_NAMESPACE_CUSTOM 0 -#define IMATH_NAMESPACE Imath - - -// -// Version information -// -#define IMATH_VERSION_STRING "3.0.0" -#define IMATH_PACKAGE_STRING "Imath 3.0.0" - -#define IMATH_VERSION_MAJOR 3 -#define IMATH_VERSION_MINOR 0 -#define IMATH_VERSION_PATCH 0 - -#define IMATH_VERSION_HEX ((uint32_t(IMATH_VERSION_MAJOR) << 24) | \ - (uint32_t(IMATH_VERSION_MINOR) << 16) | \ - (uint32_t(IMATH_VERSION_PATCH) << 8)) +load("@openexr//:bazel/third_party/generate_header.bzl", "generate_header") - -// -// By default, opt into the interoparability constructors and assignments. -// If this causes problems, it can be disabled by defining this symbol to -// be 0 prior to including any Imath headers. -// -// If no such definition is found, we enable automatically unless we are -// using gcc 4.x, which appears to have bugs that prevent the interop -// templates from compiling correctly. -// -#ifndef IMATH_FOREIGN_VECTOR_INTEROP -# if defined(__GNUC__) && __GNUC__ == 4 && !defined(__clang__) -# define IMATH_FOREIGN_VECTOR_INTEROP 0 -# else -# define IMATH_FOREIGN_VECTOR_INTEROP 1 -# endif -#endif - - -// -// Decorator that makes a function available for both CPU and GPU, when -// compiling for Cuda. -// -#ifdef __CUDACC__ - #define IMATH_HOSTDEVICE __host__ __device__ -#else - #define IMATH_HOSTDEVICE -#endif - - -// -// Some compilers define a special intrinsic to use in conditionals that can -// speed up extremely performance-critical spots if the conditional is -// usually (or rarely) is true. You use it by replacing -// if (x) ... -// with -// if (IMATH_LIKELY(x)) ... // if you think x will usually be true -// or -// if (IMATH_UNLIKELY(x)) ... // if you think x will rarely be true -// -// Caveat: Programmers are notoriously bad at guessing this, so it should be -// used only with thorough benchmarking. -// -#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) -# define IMATH_LIKELY(x) (__builtin_expect(bool(x), true)) -# define IMATH_UNLIKELY(x) (__builtin_expect(bool(x), false)) -#else -# define IMATH_LIKELY(x) (x) -# define IMATH_UNLIKELY(x) (x) -#endif - - -// -// Simple way to mark things as deprecated. -// When we are sure that C++14 is our true minimum, then we can just -// directly use [[deprecated(msg)]]. -// -#if defined(_MSC_VER) -# define IMATH_DEPRECATED(msg) __declspec(deprecated(msg)) -#elif __cplusplus >= 201402L -# define IMATH_DEPRECATED(msg) [[deprecated(msg)]] -#elif defined(__GNUC__) || defined(__clang__) -# define IMATH_DEPRECATED(msg) __attribute__((deprecated(msg))) -#else -# define IMATH_DEPRECATED(msg) /* unsupported on this platform */ -#endif - -// Whether the user configured the library to have symbol visibility -// tagged -#define IMATH_ENABLE_API_VISIBILITY - -// MSVC does not do the same visibility attributes, and when we are -// compiling a static library we won't be in DLL mode, but just don't -// define these and the export headers will work out -#if ! defined(_MSC_VER) && defined(IMATH_ENABLE_API_VISIBILITY) -# define IMATH_PUBLIC_SYMBOL_ATTRIBUTE __attribute__ ((__visibility__ ("default"))) -# define IMATH_PRIVATE_SYMBOL_ATTRIBUTE __attribute__ ((__visibility__ ("hidden"))) -// clang differs from gcc and has type visibility which is needed for enums and templates -# if __has_attribute(__type_visibility__) -# define IMATH_PUBLIC_TYPE_VISIBILITY_ATTRIBUTE __attribute__ ((__type_visibility__ ("default"))) -# endif -#endif - -#endif // INCLUDED_IMATH_CONFIG_H -""" - -genrule( - name = "generate_ImathConfig_h", - outs = ["//:ImathConfig.h"], - cmd = ("echo '%s' > $(OUTS)" % IMATH_CONFIG_H), - visibility = ["//visibility:private"], +# generate "ImathConfig.h" +generate_header( + name = "ImathConfig.h", + substitutions = { + "@IMATH_INTERNAL_NAMESPACE@": "Imath_3_0", + "@IMATH_LIB_VERSION@": "3.0.1", + "@IMATH_NAMESPACE_CUSTOM@": "0", + "@IMATH_NAMESPACE@": "Imath", + "@IMATH_PACKAGE_NAME@": "Imath 3.0.1", + "@IMATH_VERSION_MAJOR@": "3", + "@IMATH_VERSION_MINOR@": "0", + "@IMATH_VERSION_PATCH@": "1", + "@IMATH_VERSION@": "3.0.1", + "#cmakedefine IMATH_ENABLE_API_VISIBILITY": "", + "#cmakedefine IMATH_HAVE_LARGE_STACK": "", + }, + template = "config/ImathConfig.h.in", ) cc_library( @@ -154,7 +32,6 @@ cc_library( "src/Imath/eLut.h", "src/Imath/half.cpp", "src/Imath/toFloat.h", - "//:ImathConfig.h", ], hdrs = [ "src/Imath/ImathBox.h", @@ -194,4 +71,7 @@ cc_library( ], includes = ["src/Imath"], visibility = ["//visibility:public"], + deps = [ + ":ImathConfig.h", + ], ) diff --git a/bazel/third_party/generate_header.bzl b/bazel/third_party/generate_header.bzl new file mode 100644 index 0000000000..acec84f000 --- /dev/null +++ b/bazel/third_party/generate_header.bzl @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) Contributors to the OpenEXR Project. + +def _generate_header_impl(ctx): + out = ctx.actions.declare_file(ctx.label.name) + ctx.actions.expand_template( + output = out, + template = ctx.file.template, + substitutions = ctx.attr.substitutions, + ) + return [CcInfo( + compilation_context = cc_common.create_compilation_context( + includes = depset([out.dirname]), + headers = depset([out]), + ), + )] + +generate_header = rule( + implementation = _generate_header_impl, + attrs = { + "substitutions": attr.string_dict( + mandatory = True, + ), + "template": attr.label( + allow_single_file = [".h.in"], + mandatory = True, + ), + }, +) diff --git a/bazel/third_party/openexr.bzl b/bazel/third_party/openexr.bzl index 2bcce61ff8..6b236eadd8 100644 --- a/bazel/third_party/openexr.bzl +++ b/bazel/third_party/openexr.bzl @@ -21,34 +21,7 @@ def openexr_deps(): http_archive, name = "Imath", build_file = "@openexr//:bazel/third_party/Imath.BUILD", - strip_prefix = "Imath-3.0.0-beta", - sha256 = "69fe9cb97bcaf155a1441aac8e12f35cfe826fb1f60feeb7afb4ceec079e5034", - urls = ["https://github.com/AcademySoftwareFoundation/Imath/archive/v3.0.0-beta.tar.gz"], + strip_prefix = "Imath-3.0.1", + sha256 = "9cd984bb6b0a9572dd4a373b1fab60bc4c992a52ec5c68328fe0f48f194ba3c0", + urls = ["https://github.com/AcademySoftwareFoundation/Imath/archive/refs/tags/v3.0.1.tar.gz"], ) - -def _generate_header_impl(ctx): - out = ctx.actions.declare_file(ctx.label.name) - ctx.actions.expand_template( - output = out, - template = ctx.file.template, - substitutions = ctx.attr.substitutions, - ) - return [CcInfo( - compilation_context = cc_common.create_compilation_context( - includes = depset([out.dirname]), - headers = depset([out]), - ), - )] - -openexr_generate_header = rule( - implementation = _generate_header_impl, - attrs = { - "substitutions": attr.string_dict( - mandatory = True, - ), - "template": attr.label( - allow_single_file = [".h.in"], - mandatory = True, - ), - }, -)