Skip to content

Commit

Permalink
Improvements for Bazel build support (AcademySoftwareFoundation#1015)
Browse files Browse the repository at this point in the history
* Pin Imath version to 3.0.1 (instead of Imath 3.0.0 beta)

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Add comments for treating compile warnings as errors

Signed-off-by: Vertexwahn <julian.amann@tum.de>

* Improve config headers for Imath

Signed-off-by: Vertexwahn <julian.amann@tum.de>
  • Loading branch information
Vertexwahn authored and cary-ilm committed May 12, 2021
1 parent 5446eee commit 7ff3c34
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 199 deletions.
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 23 additions & 28 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# 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",
values = {"cpu": "x64_windows"},
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 */",
Expand All @@ -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",
)
Expand Down Expand Up @@ -101,9 +96,9 @@ cc_library(
],
includes = ["src/lib/Iex"],
deps = [
":OpenEXRConfig.h",
":IexConfig.h",
":IexConfigInternal.h",
":OpenEXRConfig.h",
],
)

Expand Down Expand Up @@ -363,9 +358,9 @@ cc_library(
}),
visibility = ["//visibility:public"],
deps = [
":IlmThread",
":IexConfig.h",
":IexConfigInternal.h",
":IlmThread",
":IlmThreadConfig.h",
":OpenEXRConfig.h",
":OpenEXRConfigInternal.h",
Expand Down
162 changes: 21 additions & 141 deletions bazel/third_party/Imath.BUILD
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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",
Expand Down Expand Up @@ -194,4 +71,7 @@ cc_library(
],
includes = ["src/Imath"],
visibility = ["//visibility:public"],
deps = [
":ImathConfig.h",
],
)
29 changes: 29 additions & 0 deletions bazel/third_party/generate_header.bzl
Original file line number Diff line number Diff line change
@@ -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,
),
},
)
33 changes: 3 additions & 30 deletions bazel/third_party/openexr.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
},
)

0 comments on commit 7ff3c34

Please sign in to comment.