123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- # Copyright Materialize, Inc. and contributors. All rights reserved.
- #
- # Licensed 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 in the LICENSE file at the
- # root of this repository, or online 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.
- """Additive BUILD file for the librocksdb-sys Rust crate."""
- load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
- load("@bazel_skylib//rules:select_file.bzl", "select_file")
- load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
- load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen")
- # Derived from <https://github.com/rust-rocksdb/rust-rocksdb/blob/7f9cba4a819e76d8022733b4c82509aec6056938/librocksdb-sys/build.rs>
- cc_library(
- name = "snappy",
- srcs = [
- "snappy/snappy.cc",
- "snappy/snappy-c.cc",
- "snappy/snappy-sinksource.cc",
- ],
- hdrs = [
- "snappy-stubs-public.h",
- "snappy/snappy.h",
- "snappy/snappy-c.h",
- "snappy/snappy-internal.h",
- "snappy/snappy-sinksource.h",
- "snappy/snappy-stubs-internal.h",
- ],
- copts = ["-std=c++11"],
- includes = [
- "",
- "snappy",
- ],
- local_defines = ["NDEBUG=1"],
- )
- filegroup(
- name = "rocksdb_srcs",
- srcs = glob(["**"]),
- visibility = ["//visibility:public"],
- )
- cmake(
- name = "rocksdb",
- build_args = ["-j8"],
- copts = [
- # https://github.com/facebook/rocksdb/issues/13558
- "-Wno-nontrivial-memaccess",
- ] + select(
- {
- "@platforms//cpu:x86_64": [
- # rocksdb requires these flags to be enabled, all instances we
- # run on support them.
- "-msse4.2",
- "-mpclmul",
- ],
- "@platforms//cpu:aarch64": [],
- },
- no_match_error = "Building rocksdb for the specified CPU is not supported.",
- ),
- generate_args = [
- "-DWITH_SNAPPY=1",
- "-DWITH_LZ4=1",
- "-DWITH_ZSTD=1",
- "-DWITH_GFLAGS=OFF",
- "-DWITH_ALL_TESTS=OFF",
- "-DWITH_TESTS=OFF",
- "-DWITH_TOOLS=OFF",
- "-DUSE_RTTI=1",
- "-DROCKSDB_BUILD_SHARED=OFF",
- # Without this set, rocksdb enables `-march=native` which prevents us
- # from running across various different instances.
- "-DPORTABLE=1",
- # `cmake` tries _very_ hard to find libraries to link against, and it
- # generally prefers dynamic libraries in the sysroot, which is exactly
- # what we don't want because it breaks hermeticity.
- #
- # We set a number of options here to limit what `cmake` will search for
- # so we link against our static libraries.
- "-DCMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH=0",
- "-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=0",
- "-DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=0",
- # Uncomment this if you ever need to debug what library cmake is resolving.
- # "-DCMAKE_FIND_DEBUG_MODE=TRUE",
- ] + select(
- {
- "@platforms//os:macos": [
- "-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0",
- "-DCMAKE_SYSTEM_NAME=Darwin",
- ],
- "@platforms//os:linux": ["-DCMAKE_SYSTEM_NAME=Linux"],
- },
- no_match_error = "Building rocksdb for the specified OS is not supported.",
- ) + select(
- {
- "@platforms//cpu:x86_64": ["-DCMAKE_SYSTEM_PROCESSOR=x86_64"],
- "@platforms//cpu:aarch64": ["-DCMAKE_SYSTEM_PROCESSOR=aarch64"],
- },
- no_match_error = "Building rocksdb for the specified CPU is not supported.",
- ),
- includes = ["include/rocksdb/c.h"],
- lib_source = ":rocksdb_srcs",
- out_static_libs = ["librocksdb.a"],
- targets = ["rocksdb"],
- visibility = ["//visibility:public"],
- working_directory = "rocksdb/",
- deps = [
- ":snappy",
- "@lz4",
- "@zstd",
- ],
- )
- select_file(
- name = "librocksdb_a",
- srcs = ":rocksdb",
- subpath = "librocksdb.a",
- )
- filegroup(
- name = "rocksdb_include",
- srcs = glob(
- include = ["rocksdb/include/rocksdb/**/*.h"],
- ),
- )
- # We need to expose the header files with the rocksdb static lib. The `cmake`
- # rules doesn't give us a way to do that, so we manually piece it together.
- cc_import(
- name = "librocksdb",
- hdrs = [":rocksdb_include"],
- static_library = ":librocksdb_a",
- )
- rust_bindgen(
- name = "bindings",
- bindgen_flags = [
- "--no-derive-debug",
- "--blocklist-type=max_align_t",
- "--ctypes-prefix=libc",
- ],
- cc_lib = ":librocksdb",
- header = "rocksdb/include/rocksdb/c.h",
- )
- # Place the generated artifacts into an OUT_DIR.
- #
- # TODO(parkmycar): <https://github.com/bazelbuild/rules_rust/issues/3184>
- copy_to_directory(
- name = "out_dir",
- srcs = [":bindings"],
- visibility = ["//visibility:public"],
- )
- # 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.
- #
- # Copyright 2015 The TensorFlow Authors. All Rights Reserved.
- # Licensed 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.
|