# 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 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): 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.