| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library", "cc_test") |
| |
| genrule( |
| name = "cargo_build", |
| srcs = glob(["src/**/*.rs"]) + [ |
| "Cargo.toml", |
| "build.rs", |
| ], |
| outs = [ |
| "libiggy_cpp.a", |
| "include/lib.rs.h", |
| "cxxbridge/rust/cxx.h", |
| "cxxbridge/sources/lib.rs.cc", |
| ], |
| tools = [ |
| "@rs_host_tools//:cargo", |
| "@rs_host_tools//:rustc", |
| "@rs_host_tools//:rust_toolchain", |
| ], |
| cmd = """ |
| set -euo pipefail |
| |
| EXECROOT="$$(pwd)" |
| CARGO="$$EXECROOT/$(execpath @rs_host_tools//:cargo)" |
| RUSTC="$$EXECROOT/$(execpath @rs_host_tools//:rustc)" |
| CARGO_TARGET_DIR="$$EXECROOT/$(@D)/cargo_target" |
| OUT_LIB="$$EXECROOT/$(location libiggy_cpp.a)" |
| OUT_RS="$$EXECROOT/$(location include/lib.rs.h)" |
| OUT_CXX="$$EXECROOT/$(location cxxbridge/rust/cxx.h)" |
| OUT_CC="$$EXECROOT/$(location cxxbridge/sources/lib.rs.cc)" |
| |
| PROJECT_ROOT="$$(dirname $$(readlink -f $(location Cargo.toml)))" |
| cd "$$PROJECT_ROOT" |
| |
| PROFILE="debug" |
| FLAGS="" |
| if [ "$(COMPILATION_MODE)" = "opt" ]; then |
| PROFILE="release" |
| FLAGS="--release" |
| fi |
| |
| mkdir -p "$$CARGO_TARGET_DIR" |
| env -u PWD \ |
| CARGO_TARGET_DIR="$$CARGO_TARGET_DIR" \ |
| RUSTC="$$RUSTC" \ |
| "$$CARGO" build $$FLAGS |
| |
| cp "$$CARGO_TARGET_DIR/$$PROFILE/libiggy_cpp.a" "$$OUT_LIB" |
| |
| RS_HDR="$$(find "$$CARGO_TARGET_DIR/$$PROFILE/build" -name lib.rs.h -print -quit)" |
| if [ -z "$$RS_HDR" ]; then |
| echo "ERROR: Failed to locate generated lib.rs.h under $$CARGO_TARGET_DIR/$$PROFILE/build" >&2 |
| exit 1 |
| fi |
| cp "$$RS_HDR" "$$OUT_RS" |
| |
| CXX_HDR="$$(find "$$CARGO_TARGET_DIR/$$PROFILE/build" -name cxx.h -print -quit)" |
| if [ -z "$$CXX_HDR" ]; then |
| echo "ERROR: Failed to locate generated cxx.h under $$CARGO_TARGET_DIR/$$PROFILE/build" >&2 |
| exit 1 |
| fi |
| cp "$$CXX_HDR" "$$OUT_CXX" |
| |
| CC_SRC="$$(find "$$CARGO_TARGET_DIR/$$PROFILE/build" -path '*/out/cxxbridge/sources/*/src/lib.rs.cc' -print -quit)" |
| if [ -z "$$CC_SRC" ]; then |
| echo "ERROR: Failed to locate generated lib.rs.cc under $$CARGO_TARGET_DIR/$$PROFILE/build" >&2 |
| exit 1 |
| fi |
| cp "$$CC_SRC" "$$OUT_CC" |
| """, |
| local = 1, |
| ) |
| |
| cc_import( |
| name = "iggy_cpp_static", |
| static_library = ":libiggy_cpp.a", |
| ) |
| |
| cc_library( |
| name = "iggy-cpp", |
| srcs = glob([ |
| "src/*.cpp", |
| ], allow_empty = True) + [ |
| ":cxxbridge/sources/lib.rs.cc", |
| ], |
| hdrs = [ |
| "include/iggy.hpp", |
| ":include/lib.rs.h", |
| ":cxxbridge/rust/cxx.h", |
| ], |
| includes = [ |
| "cxxbridge", |
| "include", |
| ], |
| copts = select({ |
| "@platforms//os:windows": ["/utf-8"], |
| "//conditions:default": [ |
| "-finput-charset=UTF-8", |
| "-fexec-charset=UTF-8", |
| ], |
| }), |
| linkopts = [ |
| "-ldl", |
| "-lpthread", |
| ] + select({ |
| "@platforms//os:macos": [ |
| "-framework", "CoreFoundation", |
| "-framework", "Security", |
| ], |
| "//conditions:default": [], |
| }), |
| deps = [ |
| ":iggy_cpp_static", |
| ], |
| ) |
| |
| cc_test( |
| name = "unit", |
| srcs = glob([ |
| "tests/*/unit_tests.cpp", |
| ]) + [ |
| "tests/unit_tests.cpp", |
| ], |
| copts = select({ |
| "@platforms//os:windows": ["/utf-8"], |
| "//conditions:default": [ |
| "-finput-charset=UTF-8", |
| "-fexec-charset=UTF-8", |
| ], |
| }), |
| deps = [ |
| ":iggy-cpp", |
| "@googletest//:gtest_main", |
| ], |
| ) |
| |
| cc_test( |
| name = "low-level-e2e", |
| srcs = glob([ |
| "tests/**/low_level_e2e.cpp", |
| ]) + [ |
| "tests/common/test_helpers.hpp", |
| ], |
| copts = select({ |
| "@platforms//os:windows": ["/utf-8"], |
| "//conditions:default": [ |
| "-finput-charset=UTF-8", |
| "-fexec-charset=UTF-8", |
| ], |
| }), |
| tags = [ |
| "e2e", |
| ], |
| deps = [ |
| ":iggy-cpp", |
| "@googletest//:gtest_main", |
| ], |
| ) |