diff --git a/.bazelversion b/.bazelversion index 0062ac9718..09b254e90c 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.0.0 +6.0.0 diff --git a/.github/workflows/bazel_build.yml b/.github/workflows/bazel_build.yml index 12b88e37d0..d9e8d77add 100644 --- a/.github/workflows/bazel_build.yml +++ b/.github/workflows/bazel_build.yml @@ -27,26 +27,53 @@ on: - '**.md' jobs: - build: + build_and_test_ubuntu: name: Linux Ubuntu 20.04 Bazel build runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Mount bazel cache + - name: Mount Bazel cache uses: actions/cache@v2 with: path: "/home/runner/.cache/bazel" - key: bazel + key: bazel-ubuntu - - name: Install bazelisk + - name: Build + run: | + bazelisk build //... + + build_and_test_windows: + name: Windows Server 2022 build + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v3 + + - name: Mount Bazel cache + uses: actions/cache@v2 + with: + path: "/home/runner/.cache/bazel" + key: bazel-windows + + - name: Build run: | - curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64" - mkdir -p "${GITHUB_WORKSPACE}/bin/" - mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel" - chmod +x "${GITHUB_WORKSPACE}/bin/bazel" + bazelisk build //... + + build_and_test_macos: + name: macOS 12 Bazel build + runs-on: macos-12 + + steps: + - uses: actions/checkout@v3 + + - name: Mount Bazel cache + uses: actions/cache@v2 + with: + path: "/home/runner/.cache/bazel" + key: bazel-macos - name: Build run: | - "${GITHUB_WORKSPACE}/bin/bazel" build //... + bazelisk build //... diff --git a/BUILD.bazel b/BUILD.bazel index 5a08d4c1de..af6a46a3d7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,25 +1,27 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) Contributors to the OpenEXR Project. -load("//:bazel/third_party/generate_header.bzl", "generate_header") +load("@bazel_skylib//rules:expand_template.bzl", "expand_template") config_setting( name = "windows", constraint_values = ["@platforms//os:windows"], ) -generate_header( - name = "IexConfig.h", +expand_template( + name = "IexConfig", + out = "src/lib/Iex/IexConfig.h", substitutions = { - "@IEX_INTERNAL_NAMESPACE@": "Iex_3_0", + "@IEX_INTERNAL_NAMESPACE@": "Iex_3_1", "@IEX_NAMESPACE_CUSTOM@": "0", "@IEX_NAMESPACE@": "Iex", }, template = "cmake/IexConfig.h.in", ) -generate_header( - name = "IexConfigInternal.h", +expand_template( + name = "IexConfigInternal", + out = "src/lib/Iex/IexConfigInternal.h", substitutions = { "#cmakedefine HAVE_UCONTEXT_H 1": "/* #undef HAVE_UCONTEXT_H */", "#cmakedefine IEX_HAVE_CONTROL_REGISTER_SUPPORT 1": "/* #undef IEX_HAVE_CONTROL_REGISTER_SUPPORT */", @@ -28,10 +30,11 @@ generate_header( template = "cmake/IexConfigInternal.h.in", ) -generate_header( - name = "IlmThreadConfig.h", +expand_template( + name = "IlmThreadConfig", + out = "src/lib/IlmThread/IlmThreadConfig.h", substitutions = { - "@ILMTHREAD_INTERNAL_NAMESPACE@": "IlmThread_3_0", + "@ILMTHREAD_INTERNAL_NAMESPACE@": "IlmThread_3_1", "@ILMTHREAD_NAMESPACE_CUSTOM@": "0", "@ILMTHREAD_NAMESPACE@": "IlmThread", "#cmakedefine01 ILMTHREAD_HAVE_POSIX_SEMAPHORES": "#define ILMTHREAD_HAVE_POSIX_SEMAPHORES 0", @@ -40,27 +43,29 @@ generate_header( template = "cmake/IlmThreadConfig.h.in", ) -generate_header( - name = "OpenEXRConfig.h", +expand_template( + name = "OpenEXRConfig", + out = "src/lib/OpenEXR/OpenEXRConfig.h", substitutions = { "@OPENEXR_IMF_NAMESPACE@": "Imf", - "@OPENEXR_INTERNAL_IMF_NAMESPACE@": "Imf_3_0", - "@OPENEXR_LIB_VERSION@": "3.0.4", - "@OPENEXR_NAMESPACE_CUSTOM@": "0", - "@OPENEXR_PACKAGE_NAME@": "OpenEXR 3.0.4", + "@OPENEXR_INTERNAL_IMF_NAMESPACE@": "Imf_3_1", + "@OPENEXR_LIB_VERSION@": "3.1.7", + "@OPENEXR_NAMESPACE_CUSTOM@": "3.1.7", + "@OPENEXR_PACKAGE_NAME@": "OpenEXR 3.1.7", "@OPENEXR_VERSION_EXTRA@": "", "@OPENEXR_VERSION_MAJOR@": "3", - "@OPENEXR_VERSION_MINOR@": "0", - "@OPENEXR_VERSION_PATCH@": "4", - "@OPENEXR_VERSION@": "3.0.4", + "@OPENEXR_VERSION_MINOR@": "1", + "@OPENEXR_VERSION_PATCH@": "7", + "@OPENEXR_VERSION@": "3.1.7", "#cmakedefine OPENEXR_ENABLE_API_VISIBILITY": "#define OPENEXR_ENABLE_API_VISIBILITY", "#cmakedefine OPENEXR_HAVE_LARGE_STACK 1": "/* #undef OPENEXR_HAVE_LARGE_STACK */", }, template = "cmake/OpenEXRConfig.h.in", ) -generate_header( - name = "OpenEXRConfigInternal.h", +expand_template( + name = "OpenEXRConfigInternal", + out = "src/lib/OpenEXR/OpenEXRConfigInternal.h", substitutions = { "#cmakedefine OPENEXR_IMF_HAVE_COMPLETE_IOMANIP 1": "#define OPENEXR_IMF_HAVE_COMPLETE_IOMANIP 1", "#cmakedefine OPENEXR_IMF_HAVE_DARWIN 1": "/* #undef OPENEXR_IMF_HAVE_DARWIN */", @@ -83,6 +88,8 @@ cc_library( hdrs = [ "src/lib/Iex/Iex.h", "src/lib/Iex/IexBaseExc.h", + "src/lib/Iex/IexConfig.h", + "src/lib/Iex/IexConfigInternal.h", "src/lib/Iex/IexErrnoExc.h", "src/lib/Iex/IexExport.h", "src/lib/Iex/IexForward.h", @@ -93,16 +100,15 @@ cc_library( "src/lib/Iex/IexMathIeeeExc.h", "src/lib/Iex/IexNamespace.h", "src/lib/Iex/IexThrowErrnoExc.h", + "src/lib/OpenEXR/OpenEXRConfig.h", ], features = select({ ":windows": ["windows_export_all_symbols"], "//conditions:default": [], }), - includes = ["src/lib/Iex"], - deps = [ - ":IexConfig.h", - ":IexConfigInternal.h", - ":OpenEXRConfig.h", + includes = [ + "src/lib/Iex", + "src/lib/OpenEXR", ], ) @@ -119,6 +125,7 @@ cc_library( ], hdrs = [ "src/lib/IlmThread/IlmThread.h", + "src/lib/IlmThread/IlmThreadConfig.h", "src/lib/IlmThread/IlmThreadExport.h", "src/lib/IlmThread/IlmThreadForward.h", "src/lib/IlmThread/IlmThreadMutex.h", @@ -131,10 +138,7 @@ cc_library( "//conditions:default": [], }), includes = ["src/lib/IlmThread"], - deps = [ - ":Iex", - ":IlmThreadConfig.h", - ], + deps = [":Iex"], ) cc_library( @@ -235,6 +239,9 @@ cc_library( "src/lib/OpenEXR/dwaLookups.h", ], hdrs = [ + "src/lib/Iex/IexConfig.h", + "src/lib/Iex/IexConfigInternal.h", + "src/lib/IlmThread/IlmThreadConfig.h", "src/lib/OpenEXR/ImfAcesFile.h", "src/lib/OpenEXR/ImfArray.h", "src/lib/OpenEXR/ImfAttribute.h", @@ -347,6 +354,8 @@ cc_library( "src/lib/OpenEXR/ImfXdr.h", "src/lib/OpenEXR/ImfZip.h", "src/lib/OpenEXR/ImfZipCompressor.h", + "src/lib/OpenEXR/OpenEXRConfig.h", + "src/lib/OpenEXR/OpenEXRConfigInternal.h", ], copts = select({ ":windows": [], @@ -368,12 +377,7 @@ cc_library( }), visibility = ["//visibility:public"], deps = [ - ":IexConfig.h", - ":IexConfigInternal.h", ":IlmThread", - ":IlmThreadConfig.h", - ":OpenEXRConfig.h", - ":OpenEXRConfigInternal.h", "@Imath", "@net_zlib_zlib//:zlib", ], diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index a453a259f4..28aeff91a6 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -1,5 +1,9 @@ -workspace(name = "openexr") +workspace(name = "com_openexr") load("//:bazel/third_party/openexr_deps.bzl", "openexr_deps") openexr_deps() + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() diff --git a/bazel/example/main.cpp b/bazel/example/main.cpp index 8dfa1a92fc..3cd081cddc 100644 --- a/bazel/example/main.cpp +++ b/bazel/example/main.cpp @@ -3,45 +3,59 @@ #include -// Function copied (with minior modifications) from pbrt-v3 (https://github.com/mmp/pbrt-v3) which is under BSD-2-Clause License -static void WriteImageEXR(const std::string &name, const float *pixels, - int xRes, int yRes, int totalXRes, int totalYRes, - int xOffset, int yOffset) { +// Function copied (with minor modifications) from pbrt-v3 (https://github.com/mmp/pbrt-v3) which is under BSD-2-Clause License +static void +WriteImageEXR ( + const std::string& name, + const float* pixels, + int xRes, + int yRes, + int totalXRes, + int totalYRes, + int xOffset, + int yOffset) +{ using namespace Imf; using namespace Imath; - Rgba *hrgba = new Rgba[xRes * yRes]; + Rgba* hrgba = new Rgba[xRes * yRes]; for (int i = 0; i < xRes * yRes; ++i) - hrgba[i] = Rgba(pixels[3 * i], pixels[3 * i + 1], pixels[3 * i + 2]); + hrgba[i] = Rgba (pixels[3 * i], pixels[3 * i + 1], pixels[3 * i + 2]); // OpenEXR uses inclusive pixel bounds. - Box2i displayWindow(V2i(0, 0), V2i(totalXRes - 1, totalYRes - 1)); - Box2i dataWindow(V2i(xOffset, yOffset), - V2i(xOffset + xRes - 1, yOffset + yRes - 1)); - - try { - RgbaOutputFile file(name.c_str(), displayWindow, dataWindow, - WRITE_RGB); - file.setFrameBuffer(hrgba - xOffset - yOffset * xRes, 1, xRes); - file.writePixels(yRes); - } catch (const std::exception &exc) { - throw std::runtime_error("Error writing"); + Box2i displayWindow (V2i (0, 0), V2i (totalXRes - 1, totalYRes - 1)); + Box2i dataWindow ( + V2i (xOffset, yOffset), V2i (xOffset + xRes - 1, yOffset + yRes - 1)); + + try + { + RgbaOutputFile file ( + name.c_str (), displayWindow, dataWindow, WRITE_RGB); + file.setFrameBuffer (hrgba - xOffset - yOffset * xRes, 1, xRes); + file.writePixels (yRes); + } + catch (const std::exception& exc) + { + throw std::runtime_error ("Error writing"); } delete[] hrgba; } -int main() { - float data [3*100*100]; - - for(int y = 0; y < 100; ++y) - for(int x = 0; x < 100; ++x) { - data[(y*100+x)*3+0] = 0.f; - data[(y*100+x)*3+1] = 1.f; - data[(y*100+x)*3+2] = 0.f; +int +main () +{ + float data[3 * 100 * 100]; + + for (int y = 0; y < 100; ++y) + for (int x = 0; x < 100; ++x) + { + data[(y * 100 + x) * 3 + 0] = 0.f; + data[(y * 100 + x) * 3 + 1] = 1.f; + data[(y * 100 + x) * 3 + 2] = 0.f; } - WriteImageEXR("test.exr", data, 100, 100, 100, 100, 0, 0); + WriteImageEXR ("test.exr", data, 100, 100, 100, 100, 0, 0); return 0; } \ No newline at end of file diff --git a/bazel/third_party/Imath.BUILD b/bazel/third_party/Imath.BUILD index 6e483138bd..4f65c67578 100644 --- a/bazel/third_party/Imath.BUILD +++ b/bazel/third_party/Imath.BUILD @@ -1,20 +1,21 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) Contributors to the OpenEXR Project. -load("@openexr//:bazel/third_party/generate_header.bzl", "generate_header") +load("@bazel_skylib//rules:expand_template.bzl", "expand_template") -generate_header( - name = "ImathConfig.h", +expand_template( + name = "ImathConfig", + out = "src/Imath/ImathConfig.h", substitutions = { "@IMATH_INTERNAL_NAMESPACE@": "Imath_3_1", - "@IMATH_LIB_VERSION@": "3.1.4", + "@IMATH_LIB_VERSION@": "3.1.7", "@IMATH_NAMESPACE_CUSTOM@": "0", "@IMATH_NAMESPACE@": "Imath", - "@IMATH_PACKAGE_NAME@": "Imath 3.1.4", + "@IMATH_PACKAGE_NAME@": "Imath 3.1.7", "@IMATH_VERSION_MAJOR@": "3", "@IMATH_VERSION_MINOR@": "1", - "@IMATH_VERSION_PATCH@": "4", - "@IMATH_VERSION@": "3.1.4", + "@IMATH_VERSION_PATCH@": "7", + "@IMATH_VERSION@": "3.1.7", "#cmakedefine IMATH_HALF_USE_LOOKUP_TABLE": "#define IMATH_HALF_USE_LOOKUP_TABLE", "#cmakedefine IMATH_ENABLE_API_VISIBILITY": "#define IMATH_ENABLE_API_VISIBILITY", "#cmakedefine IMATH_HAVE_LARGE_STACK": "/* #undef IMATH_HAVE_LARGE_STACK */", @@ -38,6 +39,7 @@ cc_library( "src/Imath/ImathBoxAlgo.h", "src/Imath/ImathColor.h", "src/Imath/ImathColorAlgo.h", + "src/Imath/ImathConfig.h", "src/Imath/ImathEuler.h", "src/Imath/ImathExport.h", "src/Imath/ImathForward.h", @@ -71,7 +73,4 @@ 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 deleted file mode 100644 index acec84f000..0000000000 --- a/bazel/third_party/generate_header.bzl +++ /dev/null @@ -1,29 +0,0 @@ -# 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_deps.bzl b/bazel/third_party/openexr_deps.bzl index aeecf4f8f1..f6038e300e 100644 --- a/bazel/third_party/openexr_deps.bzl +++ b/bazel/third_party/openexr_deps.bzl @@ -7,29 +7,34 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") def openexr_deps(): - """Fetches dependencies (zlib and Imath) of OpenEXR.""" + """Fetches dependencies (zlib and Imath) of OpenEXR and Skylib for header generation.""" maybe( http_archive, name = "net_zlib_zlib", - build_file = "@openexr//:bazel/third_party/zlib.BUILD", - sha256 = "91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9", - strip_prefix = "zlib-1.2.12", + build_file = "@com_openexr//:bazel/third_party/zlib.BUILD", + sha256 = "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30", + strip_prefix = "zlib-1.2.13", urls = [ - "https://zlib.net/zlib-1.2.12.tar.gz", - "https://mirror.bazel.build/zlib.net/zlib-1.2.12.tar.gz", + "https://mirror.bazel.build/zlib.net/zlib-1.2.13.tar.gz", + "https://zlib.net/zlib-1.2.13.tar.gz", ], ) - # sha256 was determined using: - # curl -sL https://github.com/AcademySoftwareFoundation/Imath/archive/refs/tags/v3.1.5.tar.gz --output Imath-3.1.5.tar.gz - # sha256sum Imath-3.1.5.tar.gz - # If the hash is incorrect Bazel will report an error and show the actual hash of the file. maybe( http_archive, name = "Imath", - build_file = "@openexr//:bazel/third_party/Imath.BUILD", - strip_prefix = "Imath-3.1.5", - sha256 = "1e9c7c94797cf7b7e61908aed1f80a331088cc7d8873318f70376e4aed5f25fb", - urls = ["https://github.com/AcademySoftwareFoundation/Imath/archive/refs/tags/v3.1.5.tar.gz"], + build_file = "@com_openexr//:bazel/third_party/Imath.BUILD", + strip_prefix = "Imath-3.1.7", + sha256 = "bff1fa140f4af0e7f02c6cb78d41b9a7d5508e6bcdfda3a583e35460eb6d4b47", + urls = ["https://github.com/AcademySoftwareFoundation/Imath/archive/refs/tags/v3.1.7.tar.gz"], + ) + + http_archive( + name = "bazel_skylib", + sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + ], )