diff --git a/.buckconfig.d/common.buckconfig b/.buckconfig.d/common.buckconfig index edac3a7f820..8765e411b79 100644 --- a/.buckconfig.d/common.buckconfig +++ b/.buckconfig.d/common.buckconfig @@ -3,6 +3,7 @@ prelude = prelude none = none [cell_aliases] +antlir = gh_facebookincubator_antlir config = prelude ovr_config = prelude bazel_skylib = gh_facebook_buck2_shims_meta diff --git a/.buckconfig.d/external_cells/facebookincubator/antlir/external_cell.buckconfig b/.buckconfig.d/external_cells/facebookincubator/antlir/external_cell.buckconfig new file mode 100644 index 00000000000..461f0af2bb3 --- /dev/null +++ b/.buckconfig.d/external_cells/facebookincubator/antlir/external_cell.buckconfig @@ -0,0 +1,9 @@ +[cells] +gh_facebookincubator_antlir = gh_facebookincubator_antlir + +[external_cells] +gh_facebookincubator_antlir = git + +[external_cell_gh_facebookincubator_antlir] +git_origin = https://github.com/facebookincubator/antlir.git +commit_hash = de5b0f6e8b434a72a03f5868fd62533629004a44 diff --git a/.github/scripts/bad_targets b/.github/scripts/bad_targets index a9023beb53a..23d68cde0ef 100644 --- a/.github/scripts/bad_targets +++ b/.github/scripts/bad_targets @@ -1,46 +1,46 @@ # This is a list of bad targets that do not build in OSS. Ideally this list goes away -# with time. -root//folly/debugging/exception_tracer:exception_counter -root//folly/debugging/exception_tracer:exception_tracer -root//folly/debugging/exception_tracer:exception_tracer_callbacks -root//folly/debugging/exception_tracer:smart_exception_stack_trace_hooks -root//folly/debugging/exception_tracer:smart_exception_tracer -root//folly/debugging/symbolizer/tool:folly-addr2line -root//folly/debugging/symbolizer/tool:libFollySegFault.so -root//folly/docs/examples/folly:baton_demo -root//folly/docs/examples/folly:cancellation_callback_demo -root//folly/docs/examples/folly:cancellation_source_demo -root//folly/docs/examples/folly:cancellation_token_demo -root//folly/docs/examples/folly:dynamic_converter_demo -root//folly/docs/examples/folly:dynamic_demo -root//folly/docs/examples/folly:executor_guide -root//folly/docs/examples/folly:file_demo -root//folly/docs/examples/folly:format_demo -root//folly/docs/examples/folly:function_demo -root//folly/docs/examples/folly:ipaddress_demo -root//folly/docs/examples/folly:likely_demo -root//folly/docs/examples/folly:map_util_demo -root//folly/docs/examples/folly:scope_guard_demo -root//folly/docs/examples/folly:scope_guard2_demo -root//folly/docs/examples/folly:scoped_event_base_thread_demo -root//folly/docs/examples/folly:scoped_event_base_thread2_demo -root//folly/docs/examples/folly:synchronized_demo -root//folly/docs/examples/folly/container:array_demo -root//folly/docs/examples/folly/dynamic:array_demo -root//folly/docs/examples/folly/dynamic:object_demo -root//folly/docs/examples/folly/coro:async_scope_demo -root//folly/docs/examples/folly/coro:cancellable_async_scope_demo -root//folly/docs/examples/folly/coro:detach_on_cancel_demo -root//folly/docs/examples/folly/coro:promise_demo -root//folly/docs/examples/folly/coro:retry_demo -root//folly/docs/examples/folly/coro:task_demo -root//folly/docs/examples/folly/coro:with_cancellation_demo -root//folly/docs/examples/folly/hash:hash_demo -root//folly/docs/examples/folly/io:i_o_buf_demo -root//folly/experimental/io:async_io -root//folly/experimental/io:simple_async_io -root//folly/logging/example:example -root//folly/python:executor_lib -root//folly/python:fibers_lib -root//folly/python:iobuf_lib -root//folly/tool:benchmark_compare +# with time. Note: Use //folly (not root//folly) so grep -F matches any cell prefix. +//folly/debugging/exception_tracer:exception_counter +//folly/debugging/exception_tracer:exception_tracer +//folly/debugging/exception_tracer:exception_tracer_callbacks +//folly/debugging/exception_tracer:smart_exception_stack_trace_hooks +//folly/debugging/exception_tracer:smart_exception_tracer +//folly/debugging/symbolizer/tool:folly-addr2line +//folly/debugging/symbolizer/tool:libFollySegFault.so +//folly/docs/examples/folly:baton_demo +//folly/docs/examples/folly:cancellation_callback_demo +//folly/docs/examples/folly:cancellation_source_demo +//folly/docs/examples/folly:cancellation_token_demo +//folly/docs/examples/folly:dynamic_converter_demo +//folly/docs/examples/folly:dynamic_demo +//folly/docs/examples/folly:executor_guide +//folly/docs/examples/folly:file_demo +//folly/docs/examples/folly:format_demo +//folly/docs/examples/folly:function_demo +//folly/docs/examples/folly:ipaddress_demo +//folly/docs/examples/folly:likely_demo +//folly/docs/examples/folly:map_util_demo +//folly/docs/examples/folly:scope_guard_demo +//folly/docs/examples/folly:scope_guard2_demo +//folly/docs/examples/folly:scoped_event_base_thread_demo +//folly/docs/examples/folly:scoped_event_base_thread2_demo +//folly/docs/examples/folly:synchronized_demo +//folly/docs/examples/folly/container:array_demo +//folly/docs/examples/folly/dynamic:array_demo +//folly/docs/examples/folly/dynamic:object_demo +//folly/docs/examples/folly/coro:async_scope_demo +//folly/docs/examples/folly/coro:cancellable_async_scope_demo +//folly/docs/examples/folly/coro:detach_on_cancel_demo +//folly/docs/examples/folly/coro:promise_demo +//folly/docs/examples/folly/coro:retry_demo +//folly/docs/examples/folly/coro:task_demo +//folly/docs/examples/folly/coro:with_cancellation_demo +//folly/docs/examples/folly/hash:hash_demo +//folly/docs/examples/folly/io:i_o_buf_demo +//folly/experimental/io:async_io +//folly/experimental/io:simple_async_io +//folly/logging/example:example +//folly/python:executor_lib +//folly/python:fibers_lib +//folly/python:iobuf_lib +//folly/tool:benchmark_compare diff --git a/.github/scripts/buck_build_and_test.sh b/.github/scripts/buck_build_and_test.sh index 049dc0c1466..3798e855b73 100755 --- a/.github/scripts/buck_build_and_test.sh +++ b/.github/scripts/buck_build_and_test.sh @@ -14,7 +14,7 @@ # limitations under the License. TARGETS_FILE=$(mktemp) -./buck2 targets //... | grep -F -v -f .github/scripts/bad_targets | grep -v test >"$TARGETS_FILE" +./buck2 ctargets //... | sed 's/ ([^)]*)$//' | grep -F -v -f .github/scripts/bad_targets | grep -v test >"$TARGETS_FILE" ./buck2 build @"$TARGETS_FILE" # ./buck2 test @"$TARGETS_FILE" diff --git a/.github/workflows/oss-build-and-test.yml b/.github/workflows/oss-build-and-test.yml index 4b74ec65708..fcd4427d101 100644 --- a/.github/workflows/oss-build-and-test.yml +++ b/.github/workflows/oss-build-and-test.yml @@ -8,6 +8,10 @@ jobs: with: submodules: 'true' - uses: facebook/install-dotslash@latest + - name: Set PATH for dotslash + run: | + echo "PATH=$PATH:/tmp/install-dotslash/bin" >> $GITHUB_ENV + shell: bash - name: get_buck_graph run: | BUCK_GRAPH=$(./buck2 cquery ... --output-attribute '^buck.type$|^name$') @@ -61,25 +65,83 @@ jobs: - run: sudo apt-get update shell: bash - uses: facebook/install-dotslash@latest - - name: Install Rust toolchain - if: needs.get-toolchains-to-install.outputs.uses_rust == 'true' - uses: dtolnay/rust-toolchain@stable + - name: Install C++ toolchain if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' run: | - sudo apt-get install cmake llvm cppcheck python3-pip - sudo pip3 install conan==1.* + sudo apt-get install -y \ + clang \ + cmake \ + cppcheck \ + git \ + lld \ + llvm \ + pkg-config shell: bash + - name: Install OCaml toolchain if: needs.get-toolchains-to-install.outputs.uses_ocaml == 'true' uses: ocaml/setup-ocaml@v2 with: ocaml-compiler: "5.1" - name: Install Python toolchain - if: needs.get-toolchains-to-install.outputs.uses_python == 'true' + if: needs.get-toolchains-to-install.outputs.uses_python == 'true' || needs.get-toolchains-to-install.outputs.uses_cxx == 'true' uses: actions/setup-python@v5 with: python-version: '3.10' + - name: Install Cython + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + run: pip install cython + shell: bash + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: Install Conan (C/C++ package manager) + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + uses: conan-io/setup-conan@v1 + with: + version: "2.23" + - name: Install dependencies via Conan + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + run: | + case $(uname -m) in + x86_64) CONAN_ARCH="x86_64" ;; + aarch64) CONAN_ARCH="armv8" ;; + *) echo "Unsupported architecture: $(uname -m)"; exit 1 ;; + esac + conan install . \ + --build=missing \ + --output-folder=conan-build \ + --profile=conan-profile-linux-clang \ + -s arch=$CONAN_ARCH \ + -c tools.system.package_manager:mode=install \ + -c tools.system.package_manager:sudo=True + + # Required by Conan's CMakeDeps-generated config files + echo "CMAKE_BUILD_TYPE=Release" >> $GITHUB_ENV + CONAN_INCLUDE_DIRS=$( + for pc in $PWD/conan-build/*.pc; do + pkg-config --variable=includedir "$pc" 2>/dev/null + done | sort -u | tr '\n' ':' | sed 's/:$//' + ) + if [ -n "$CONAN_INCLUDE_DIRS" ]; then + echo "CMAKE_INCLUDE_PATH=$CONAN_INCLUDE_DIRS" >> $GITHUB_ENV + fi + echo "CMAKE_PREFIX_PATH=$PWD/conan-build:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV + + echo "PKG_CONFIG_PATH=$PWD/conan-build:$PKG_CONFIG_PATH" >> $GITHUB_ENV + shell: bash + + - name: Install cxx bridge tools + run: cargo install cxxbridge-cmd + shell: bash + - name: Install cxx headers + run: | + sudo mkdir -p /usr/local/include/rust + cxxbridge --header > /tmp/cxx.h + sudo mv /tmp/cxx.h /usr/local/include/rust/cxx.h + shell: bash + - name: buck2 build and test run: bash ./.github/scripts/buck_build_and_test.sh windows-os-buck-build-and-test: @@ -90,25 +152,60 @@ jobs: with: submodules: 'true' - uses: facebook/install-dotslash@latest - - name: Install Rust toolchain - if: needs.get-toolchains-to-install.outputs.uses_rust == 'true' - uses: dtolnay/rust-toolchain@stable + - name: Install C++ toolchain if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' run: | - choco install llvm cmake conan cppcheck -y + choco install cmake cppcheck llvm -y if ($LASTEXITCODE -eq 3010) { $LASTEXITCODE = 0 } shell: pwsh + - name: Install OCaml toolchain if: needs.get-toolchains-to-install.outputs.uses_ocaml == 'true' uses: ocaml/setup-ocaml@v2 with: ocaml-compiler: "4.12.0" - name: Install Python toolchain - if: needs.get-toolchains-to-install.outputs.uses_python == 'true' + if: needs.get-toolchains-to-install.outputs.uses_python == 'true' || needs.get-toolchains-to-install.outputs.uses_cxx == 'true' uses: actions/setup-python@v5 with: python-version: '3.10' + - name: Install Cython + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + run: pip install cython + shell: bash + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: Install Conan (C/C++ package manager) + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + uses: conan-io/setup-conan@v1 + with: + version: "2.23" + - name: Install dependencies via Conan + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + run: | + conan install . ` + --build=missing ` + --output-folder=conan-build ` + --profile=conan-profile-windows-msvc ` + -s arch=x86_64 ` + -c tools.system.package_manager:mode=install + + echo "CMAKE_BUILD_TYPE=Release" >> $env:GITHUB_ENV + echo "CMAKE_PREFIX_PATH=$PWD/conan-build;$env:CMAKE_PREFIX_PATH" >> $env:GITHUB_ENV + echo "PKG_CONFIG_PATH=$PWD/conan-build;$env:PKG_CONFIG_PATH" >> $env:GITHUB_ENV + shell: pwsh + + - name: Install cxx bridge tools + run: cargo install cxxbridge-cmd + shell: bash + - name: Install cxx headers + run: | + mkdir -p "C:/Program Files/rust/include" + cxxbridge --header > "C:/Program Files/rust/include/cxx.h" + shell: bash + - name: buck2 build and test run: bash ./.github/scripts/buck_build_and_test.sh mac-os-buck-build-and-test: @@ -119,29 +216,74 @@ jobs: with: submodules: 'true' - uses: facebook/install-dotslash@latest - - name: Install Rust toolchain - if: needs.get-toolchains-to-install.outputs.uses_rust == 'true' - uses: dtolnay/rust-toolchain@stable + - name: Install C++ toolchain if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' run: | - brew install cmake llvm cppcheck python3 conan@1 + brew install cmake cppcheck llvm pkg-config shell: bash + - name: Install OCaml toolchain if: needs.get-toolchains-to-install.outputs.uses_ocaml == 'true' uses: ocaml/setup-ocaml@v2 with: ocaml-compiler: "5.1" - name: Install Python toolchain - if: needs.get-toolchains-to-install.outputs.uses_python == 'true' + if: needs.get-toolchains-to-install.outputs.uses_python == 'true' || needs.get-toolchains-to-install.outputs.uses_cxx == 'true' uses: actions/setup-python@v5 with: python-version: '3.10' - - name: Install homebrew deps + - name: Install Cython + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + run: pip install cython + shell: bash + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: Install Conan (C/C++ package manager) + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + uses: conan-io/setup-conan@v1 + with: + version: "2.23" + - name: Install dependencies via Conan + if: needs.get-toolchains-to-install.outputs.uses_cxx == 'true' + run: | + case $(uname -m) in + x86_64) CONAN_ARCH="x86_64" ;; + arm64) CONAN_ARCH="armv8" ;; + *) echo "Unsupported architecture: $(uname -m)"; exit 1 ;; + esac + conan install . \ + --build=missing \ + --output-folder=conan-build \ + --profile=conan-profile-macos-clang \ + -s arch=$CONAN_ARCH \ + -c tools.system.package_manager:mode=install + + # Required by Conan's CMakeDeps-generated config files + echo "CMAKE_BUILD_TYPE=Release" >> $GITHUB_ENV + CONAN_INCLUDE_DIRS=$( + for pc in $PWD/conan-build/*.pc; do + pkg-config --variable=includedir "$pc" 2>/dev/null + done | sort -u | tr '\n' ':' | sed 's/:$//' + ) + if [ -n "$CONAN_INCLUDE_DIRS" ]; then + echo "CMAKE_INCLUDE_PATH=$CONAN_INCLUDE_DIRS" >> $GITHUB_ENV + fi + echo "CMAKE_PREFIX_PATH=$PWD/conan-build:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV + + echo "PKG_CONFIG_PATH=$PWD/conan-build:$PKG_CONFIG_PATH" >> $GITHUB_ENV + shell: bash + + - name: Install cxx bridge tools + run: cargo install cxxbridge-cmd + shell: bash + - name: Install cxx headers run: | - BUCK_GRAPH=$(./buck2 cquery "attrregexfilter(labels, 'third-party:homebrew:', deps(//...))" --json --output-attribute=labels) - HOMEBREW_PACKAGES=$(echo $BUCK_GRAPH | jq '[.[] | .labels] | flatten | unique | map(select(contains("third-party:homebrew:")) | sub("third-party:homebrew:"; "")) | .[] | @text') - echo $HOMEBREW_PACKAGES - echo $HOMEBREW_PACKAGES | xargs brew install pkg-config + sudo mkdir -p /usr/local/include/rust + cxxbridge --header > /tmp/cxx.h + sudo mv /tmp/cxx.h /usr/local/include/rust/cxx.h + shell: bash + - name: buck2 build and test run: bash ./.github/scripts/buck_build_and_test.sh diff --git a/.gitignore b/.gitignore index 226e904ffba..5bf12dce5b1 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,7 @@ folly/FingerprintTables.cpp _build # Ignore all files generated by Buck2 buck-out/ +# Conan creations +conan-build/ +CMakeUserPresets.json +buck_graph_results.json diff --git a/BUCK b/BUCK index 3cce3e42a32..5a71157f228 100644 --- a/BUCK +++ b/BUCK @@ -10,7 +10,7 @@ buck_genrule( ])} | {"CMakeLists.txt": "CMakeListsForBuck2.txt"}, out = "folly-config.h", - cmd = "cmake . && mv folly/folly-config.h $OUT", + cmd = "cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++' . && mv folly/folly-config.h $OUT", default_target_platform = "prelude//platforms:default", labels = [ "third-party:fedora:cmake", diff --git a/CMakeLists.txt b/CMakeLists.txt index 50dd7ec12fd..a17e1ded720 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -976,7 +976,7 @@ if (BUILD_TESTS OR BUILD_BENCHMARKS) TEST io_async_event_base_test BROKEN SOURCES EventBaseTest.cpp TEST io_async_event_base_local_test WINDOWS_DISABLED SOURCES EventBaseLocalTest.cpp - TEST io_async_hh_wheel_timer_test SOURCES HHWheelTimerTest.cpp + TEST io_async_hh_wheel_timer_test APPLE_DISABLED SOURCES HHWheelTimerTest.cpp TEST io_async_hh_wheel_timer_slow_tests SLOW SOURCES HHWheelTimerSlowTests.cpp TEST io_async_notification_queue_test WINDOWS_DISABLED @@ -1060,7 +1060,7 @@ if (BUILD_TESTS OR BUILD_BENCHMARKS) TEST stats_quantile_estimator_test SOURCES QuantileEstimatorTest.cpp TEST stats_sliding_window_test SOURCES SlidingWindowTest.cpp BENCHMARK stats_tdigest_benchmark SOURCES TDigestBenchmark.cpp - TEST stats_tdigest_test SOURCES TDigestTest.cpp + TEST stats_tdigest_test WINDOWS_DISABLED SOURCES TDigestTest.cpp TEST stats_timeseries_histogram_test SOURCES TimeseriesHistogramTest.cpp TEST stats_timeseries_test SOURCES TimeSeriesTest.cpp @@ -1134,7 +1134,7 @@ if (BUILD_TESTS OR BUILD_BENCHMARKS) SOURCES ExceptionWrapperBenchmark.cpp TEST exception_wrapper_test WINDOWS_DISABLED SOURCES ExceptionWrapperTest.cpp - TEST expected_coroutines_test SOURCES ExpectedCoroutinesTest.cpp + TEST expected_coroutines_test WINDOWS_DISABLED SOURCES ExpectedCoroutinesTest.cpp TEST expected_test WINDOWS_DISABLED SOURCES ExpectedTest.cpp BENCHMARK fbstring_benchmark WINDOWS_DISABLED @@ -1172,7 +1172,7 @@ if (BUILD_TESTS OR BUILD_BENCHMARKS) TEST memory_idler_test SOURCES MemoryIdlerTest.cpp TEST memory_test WINDOWS_DISABLED SOURCES MemoryTest.cpp - BENCHMARK memset_benchmark SOURCES MemsetBenchmark.cpp + BENCHMARK memset_benchmark WINDOWS_DISABLED SOURCES MemsetBenchmark.cpp TEST move_wrapper_test SOURCES MoveWrapperTest.cpp TEST mpmc_pipeline_test SOURCES MPMCPipelineTest.cpp TEST mpmc_queue_test SLOW diff --git a/CMakeListsForBuck2.txt b/CMakeListsForBuck2.txt index 5bbf526b599..cc26f7d4f22 100644 --- a/CMakeListsForBuck2.txt +++ b/CMakeListsForBuck2.txt @@ -27,6 +27,12 @@ if(POLICY CMP0075) cmake_policy(SET CMP0075 NEW) endif() +# CMP0091 MSVC runtime library flags are selected by an abstraction +# Required by Conan's toolchain +if(POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() + # includes set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" diff --git a/conan-profile-linux-clang b/conan-profile-linux-clang new file mode 100644 index 00000000000..edfa7fa53a7 --- /dev/null +++ b/conan-profile-linux-clang @@ -0,0 +1,14 @@ +[settings] +os=Linux +compiler=clang +compiler.version=18 +compiler.libcxx=libc++ +compiler.cppstd=20 +build_type=Release +# libunwind is a C library with clang ARM64 inline asm issues +libunwind/*:compiler=gcc +libunwind/*:compiler.version=13 + +[conf] +tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} +libunwind/*:tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} diff --git a/conan-profile-macos-clang b/conan-profile-macos-clang new file mode 100644 index 00000000000..9d391ba9953 --- /dev/null +++ b/conan-profile-macos-clang @@ -0,0 +1,7 @@ +[settings] +os=Macos +compiler=apple-clang +compiler.version=15 +compiler.libcxx=libc++ +compiler.cppstd=20 +build_type=Release diff --git a/conan-profile-windows-msvc b/conan-profile-windows-msvc new file mode 100644 index 00000000000..77fa18696c1 --- /dev/null +++ b/conan-profile-windows-msvc @@ -0,0 +1,7 @@ +[settings] +os=Windows +compiler=msvc +compiler.version=194 +compiler.runtime=dynamic +compiler.cppstd=20 +build_type=Release diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 00000000000..9ea2cbf421e --- /dev/null +++ b/conanfile.py @@ -0,0 +1,101 @@ +import os +import shutil +import subprocess + +from conan import ConanFile +from conan.tools.system.package_manager import Apt, Brew, Chocolatey + +BLAKE3_GIT_URL = "https://github.com/BLAKE3-team/BLAKE3.git" + + +class FollyConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "PkgConfigDeps", "CMakeDeps", "CMakeToolchain" + requires = [ + "bzip2/[*]", + "fast_float/[*]", + "fmt/[*]", + "gflags/[*]", + "glog/[*]", + "libdwarf/[<100]", + ] + + def configure(self): + if self.settings.os != "Windows": + self.requires("libiberty/[*]") + if self.settings.os in ("Linux", "FreeBSD"): + self.requires("libunwind/[*]") + if self.settings.os == "Linux": + self.requires("liburing/[*]") + + def _run(self, args, **kwargs): + """Run a command, raising on failure.""" + subprocess.run(args, check=True, **kwargs) + + def _install_blake3(self): + """Build and install BLAKE3 C library from source.""" + blake3_dir = os.path.join(os.getcwd(), "conan-build", "tmp", "BLAKE3") + build_dir = os.path.join(blake3_dir, "c", "build") + + # Clean any previous build + if os.path.exists(blake3_dir): + shutil.rmtree(blake3_dir) + + # Platform-specific install prefix + if self.settings.os == "Windows": + install_prefix = "C:/Program Files/BLAKE3" + else: + install_prefix = "/usr/local" + + # Clone and build + self._run(["git", "clone", "--depth", "1", BLAKE3_GIT_URL, blake3_dir]) + self._run(["cmake", "-B", build_dir, f"-DCMAKE_INSTALL_PREFIX={install_prefix}"], + cwd=os.path.join(blake3_dir, "c")) + + # Install (sudo required on Unix, not on Windows) + # Windows MSBuild needs --config Release for both build and install + if self.settings.os == "Windows": + self._run(["cmake", "--build", build_dir, "--config", "Release"]) + self._run(["cmake", "--install", build_dir, "--config", "Release"]) + else: + self._run(["cmake", "--build", build_dir]) + self._run(["sudo", "cmake", "--install", build_dir]) + + def system_requirements(self): + # Linux (Debian/Ubuntu) + Apt(self).install([ + "libboost-all-dev", + "libc++-dev", + "libc++abi-dev", + "libdouble-conversion-dev", + "libevent-dev", + "libgtest-dev", + "libjemalloc-dev", + "liblz4-dev", + "libsnappy-dev", + "libsodium-dev", + "libssl-dev", + "libxxhash-dev", + ], update=True, check=True) + + # macOS + Brew(self).install([ + "boost", + "double-conversion", + "googletest", + "jemalloc", + "libevent", + "libsodium", + "lz4", + "openssl", + "snappy", + "xxhash", + ], update=True, check=True) + + # Windows + Chocolatey(self).install([ + "boost-msvc-14.3", + "openssl", + ], update=True, check=True) + + self._install_blake3() diff --git a/do/build b/do/build new file mode 100755 index 00000000000..c8f9a8edefb --- /dev/null +++ b/do/build @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +if [ ${1-} = --clean ]; then + if [ -d "$(dotslash -- cache-dir)" ]; then + dotslash -- clean + fi + rm -rf ~/.cache/act ~/.cache/actcache + rm -rf build/fbcode_builder/getdeps/__pycache__/ + + rm -rf buck-out/ + rm -rf conan-build/ + + act \ + --bind \ + -W .github/workflows/oss-build-and-test.yml \ + --job ubuntu-os-buck-build-and-test \ + --rebuild \ + --container-options --init +else + act \ + --bind \ + -W .github/workflows/oss-build-and-test.yml \ + --job ubuntu-os-buck-build-and-test \ + --reuse +fi diff --git a/folly/BUCK b/folly/BUCK index 30505994a84..f70a1f8f76b 100644 --- a/folly/BUCK +++ b/folly/BUCK @@ -1350,7 +1350,7 @@ fb_dirsync_cpp_library( ] + select({ "DEFAULT": [], "antlir//antlir/distro:build-for-distro": ["third-party//binutils:iberty"], - "fbsource//xplat/folly:folly_demangle_macos_disable_iberty_config": [], + ":folly_demangle_macos_disable_iberty_config": [], "ovr_config//os:linux": ["fbsource//third-party/binutils:iberty-demangle"], "ovr_config//os:macos": ["fbsource//third-party/binutils:iberty-demangle"], "ovr_config//runtime:fbcode": ["third-party//binutils:iberty"], @@ -5381,9 +5381,10 @@ fbcode_target( "FollyMemset.cpp", ] + select({ "DEFAULT": [], - "ovr_config//cpu:x86_64": [ - "memset.S", - ], + "ovr_config//cpu:x86_64": select({ + "DEFAULT": ["memset.S"], + "ovr_config//compiler:msvc": [], + }), "ovr_config//os:linux-arm64": [ "memset_select_aarch64.cpp", ], @@ -5422,9 +5423,10 @@ fbcode_target( "FollyMemset.cpp", ] + select({ "DEFAULT": [], - "ovr_config//cpu:x86_64": [ - "memset.S", - ], + "ovr_config//cpu:x86_64": select({ + "DEFAULT": ["memset.S"], + "ovr_config//compiler:msvc": [], + }), "ovr_config//os:linux-arm64": [ "memset_select_aarch64.cpp", ], @@ -5457,9 +5459,11 @@ fbcode_target( srcs = [ "FollyMemcpy.cpp", ] + select({ - "ovr_config//cpu:x86_64": [ - "memcpy.S", - ], + "DEFAULT": [], + "ovr_config//cpu:x86_64": select({ + "DEFAULT": ["memcpy.S"], + "ovr_config//compiler:msvc": [], + }), "ovr_config//os:linux-arm64": [ "memcpy_select_aarch64.cpp", ], @@ -5498,9 +5502,10 @@ fbcode_target( "FollyMemcpy.cpp", ] + select({ "DEFAULT": [], - "ovr_config//cpu:x86_64": [ - "memcpy.S", - ], + "ovr_config//cpu:x86_64": select({ + "DEFAULT": ["memcpy.S"], + "ovr_config//compiler:msvc": [], + }), "ovr_config//os:linux-arm64": [ "memcpy_select_aarch64.cpp", ], @@ -6090,9 +6095,9 @@ fbcode_target( exported_deps = [], ) -fb_native.export_file( - name = "src-tree", - src = ".", - mode = "reference", - visibility = ["PUBLIC"], -) +# @fb-only: fb_native.export_file( +# @fb-only: name = "src-tree", +# @fb-only: src = ".", +# @fb-only: mode = "reference", +# @fb-only: visibility = ["PUBLIC"], +# @fb-only: ) diff --git a/folly/buck_config/BUCK b/folly/buck_config/BUCK index 382c1faf917..457ce21def8 100644 --- a/folly/buck_config/BUCK +++ b/folly/buck_config/BUCK @@ -5,7 +5,7 @@ oncall("fbcode_entropy_wardens_folly") fb_native.config_setting( name = "folly-singleton-schedule-at-exit-disabled", constraint_values = [ - "fbsource//xplat/folly/buck_config/constraints:singleton-schedule-at-exit-disabled", + "//" + package_name() + "/constraints:singleton-schedule-at-exit-disabled", ], visibility = ["PUBLIC"], ) @@ -13,7 +13,7 @@ fb_native.config_setting( fb_native.config_setting( name = "folly-f14-fallback-disabled", constraint_values = [ - "fbsource//xplat/folly/buck_config/constraints:f14-fallback-disabled", + "//" + package_name() + "/constraints:f14-fallback-disabled", ], visibility = ["PUBLIC"], ) @@ -21,7 +21,7 @@ fb_native.config_setting( fb_native.config_setting( name = "folly-gflags-enabled", constraint_values = [ - "fbsource//xplat/folly/buck_config/constraints:gflags-enabled", + "//" + package_name() + "/constraints:gflags-enabled", ], visibility = ["PUBLIC"], ) diff --git a/folly/buck_config/constraints/BUCK b/folly/buck_config/constraints/BUCK index a55bf53d336..b76af49f1c6 100644 --- a/folly/buck_config/constraints/BUCK +++ b/folly/buck_config/constraints/BUCK @@ -3,40 +3,34 @@ load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native") oncall("fbcode_entropy_wardens_folly") -non_fbcode_target( - _kind = fb_native.constraint_setting, +fb_native.constraint_setting( name = "singleton", visibility = ["PUBLIC"], ) -non_fbcode_target( - _kind = fb_native.constraint_value, +fb_native.constraint_value( name = "singleton-schedule-at-exit-disabled", constraint_setting = ":singleton", visibility = ["PUBLIC"], ) -non_fbcode_target( - _kind = fb_native.constraint_setting, +fb_native.constraint_setting( name = "f14-fallback", visibility = ["PUBLIC"], ) -non_fbcode_target( - _kind = fb_native.constraint_value, +fb_native.constraint_value( name = "f14-fallback-disabled", constraint_setting = ":f14-fallback", visibility = ["PUBLIC"], ) -non_fbcode_target( - _kind = fb_native.constraint_setting, +fb_native.constraint_setting( name = "gflags", visibility = ["PUBLIC"], ) -non_fbcode_target( - _kind = fb_native.constraint_value, +fb_native.constraint_value( name = "gflags-enabled", constraint_setting = ":gflags", visibility = ["PUBLIC"], diff --git a/folly/cli/BUCK b/folly/cli/BUCK index 7509f5e70c4..8fca2a74945 100644 --- a/folly/cli/BUCK +++ b/folly/cli/BUCK @@ -10,7 +10,8 @@ load( "MACOSX", "WINDOWS", ) -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("@fbsource//xplat/pfh/triage_InfrastructureSupermoduleOptou:DEFS.bzl", "triage_InfrastructureSupermoduleOptou") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/container/test/heap_vector_types_test.cpp b/folly/container/test/heap_vector_types_test.cpp index ef98bc07a76..62d52571a12 100644 --- a/folly/container/test/heap_vector_types_test.cpp +++ b/folly/container/test/heap_vector_types_test.cpp @@ -193,12 +193,12 @@ TEST(HeapVectorTypes, SimpleSetTest) { EXPECT_FALSE(cs2.find(32) == cs2.end()); EXPECT_TRUE(cs2.contains(32)); - // Bad insert hint. - s2.insert(s2.begin() + 3, 33); - EXPECT_TRUE(s2.find(33) != s2.begin()); - EXPECT_TRUE(s2.find(33) != s2.end()); + // Bad insert hint. Use value outside random range (0-99999). + s2.insert(s2.begin() + 3, 100002); + EXPECT_TRUE(s2.find(100002) != s2.begin()); + EXPECT_TRUE(s2.find(100002) != s2.end()); check_invariant(s2); - s2.erase(33); + s2.erase(100002); check_invariant(s2); it = s2.find(32); diff --git a/folly/coro/BUCK b/folly/coro/BUCK index 386259fb9bb..f6f60924a2b 100644 --- a/folly/coro/BUCK +++ b/folly/coro/BUCK @@ -50,8 +50,8 @@ fbcode_target( "//folly/coro:base_promise", "//folly/coro:coroutine", "//folly/coro:current_executor", - "//folly/coro:detail_malloc", - "//folly/coro:detail_manual_lifetime", + "//folly/coro/detail:malloc", + "//folly/coro/detail:manual_lifetime", "//folly/coro:invoke", "//folly/coro:result", "//folly/coro:scope_exit", @@ -138,8 +138,8 @@ fbcode_target( exported_deps = [ ":coroutine", ":current_executor", - ":detail_barrier", - ":detail_barrier_task", + "//folly/coro/detail:barrier", + "//folly/coro/detail:barrier_task", ":task", "//folly:cancellation_token", "//folly:exception_wrapper", @@ -317,8 +317,8 @@ fbcode_target( exported_deps = [ "//folly:try", "//folly/coro:coroutine", - "//folly/coro:detail_malloc", - "//folly/coro:detail_traits", + "//folly/coro/detail:malloc", + "//folly/coro/detail:traits", "//folly/coro:task", "//folly/coro:traits", "//folly/coro:via_if_async", @@ -396,11 +396,11 @@ fbcode_target( "//folly/coro:async_pipe", "//folly/coro:async_scope", "//folly/coro:coroutine", - "//folly/coro:detail_barrier", - "//folly/coro:detail_barrier_task", - "//folly/coro:detail_current_async_frame", - "//folly/coro:detail_helpers", - "//folly/coro:detail_traits", + "//folly/coro/detail:barrier", + "//folly/coro/detail:barrier_task", + "//folly/coro/detail:current_async_frame", + "//folly/coro/detail:helpers", + "//folly/coro/detail:traits", "//folly/coro:mutex", "//folly/coro:task", "//folly/coro:via_if_async", @@ -531,7 +531,7 @@ fbcode_target( exported_deps = [ "//folly/coro:baton", "//folly/coro:coroutine", - "//folly/coro:detail_helpers", + "//folly/coro/detail:helpers", "//folly/coro:invoke", "//folly/coro:task", "//folly/coro:traits", @@ -554,176 +554,6 @@ non_fbcode_target( ### this line is a hint for source control merge -fbcode_target( - _kind = cpp_library, - name = "detail_barrier", - headers = ["detail/Barrier.h"], - exported_deps = [ - ":coroutine", - ":traits", - ":with_async_stack", - "//folly/tracing:async_stack", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "detail_barrier", - raw_headers = ["detail/Barrier.h"], - exported_deps = [ - "//xplat/folly/experimental/coro:coroutine", - "//xplat/folly/experimental/coro:traits", - "//xplat/folly/experimental/coro:with_async_stack", - "//xplat/folly/tracing:async_stack", - ], -) - -### this line is a hint for source control merge - -fbcode_target( - _kind = cpp_library, - name = "detail_barrier_task", - headers = ["detail/BarrierTask.h"], - exported_deps = [ - ":coroutine", - ":detail_barrier", - ":detail_malloc", - ":with_async_stack", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "detail_barrier_task", - raw_headers = ["detail/BarrierTask.h"], - exported_deps = [ - "//xplat/folly/experimental/coro:coroutine", - "//xplat/folly/experimental/coro:detail_barrier", - "//xplat/folly/experimental/coro:detail_malloc", - "//xplat/folly/experimental/coro:with_async_stack", - ], -) - -### this line is a hint for source control merge - -fbcode_target( - _kind = cpp_library, - name = "detail_current_async_frame", - headers = ["detail/CurrentAsyncFrame.h"], - exported_deps = [ - ":coroutine", - ":with_async_stack", - "//folly:executor", - "//folly/tracing:async_stack", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "detail_current_async_frame", - raw_headers = ["detail/CurrentAsyncFrame.h"], - exported_deps = [ - "//xplat/folly:executor", - "//xplat/folly/experimental/coro:coroutine", - "//xplat/folly/experimental/coro:with_async_stack", - "//xplat/folly/tracing:async_stack", - ], -) - -### this line is a hint for source control merge - -fbcode_target( - _kind = cpp_library, - name = "detail_helpers", - headers = ["detail/Helpers.h"], - exported_deps = [ - ":coroutine", - "//folly:executor", - "//folly:singleton_thread_local", - "//folly/io/async:request_context", - "//folly/tracing:async_stack", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "detail_helpers", - raw_headers = ["detail/Helpers.h"], - exported_deps = [ - "//xplat/folly:executor", - "//xplat/folly:singleton_thread_local", - "//xplat/folly/experimental/coro:coroutine", - "//xplat/folly/io/async:request_context", - "//xplat/folly/tracing:async_stack", - ], -) - -### this line is a hint for source control merge - -fbcode_target( - _kind = cpp_library, - name = "detail_malloc", - srcs = ["detail/Malloc.cpp"], - headers = ["detail/Malloc.h"], - deps = [ - "//folly/lang:hint", - "//folly/lang:new", - ], - exported_deps = [ - "//folly:c_portability", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "detail_malloc", - srcs = ["detail/Malloc.cpp"], - raw_headers = ["detail/Malloc.h"], - deps = [ - "//xplat/folly/lang:hint", - "//xplat/folly/lang:new", - ], - exported_deps = ["//xplat/folly:c_portability"], -) - -### this line is a hint for source control merge - -fbcode_target( - _kind = cpp_library, - name = "detail_manual_lifetime", - headers = ["detail/ManualLifetime.h"], - exported_deps = [ - "//folly:scope_guard", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "detail_manual_lifetime", - raw_headers = ["detail/ManualLifetime.h"], - exported_deps = ["//xplat/folly:scope_guard"], -) - -### this line is a hint for source control merge - -fbcode_target( - _kind = cpp_library, - name = "detail_traits", - headers = ["detail/Traits.h"], - exported_deps = [ - "//folly:traits", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "detail_traits", - raw_headers = ["detail/Traits.h"], - exported_deps = ["//xplat/folly:traits"], -) - -### this line is a hint for source control merge - fbcode_target( _kind = cpp_library, name = "error", @@ -890,38 +720,6 @@ non_fbcode_target( ### this line is a hint for source control merge -fbcode_target( - _kind = cpp_library, - name = "inline_task", - headers = ["detail/InlineTask.h"], - exported_deps = [ - ":coroutine", - ":detail_malloc", - ":with_async_stack", - "//folly:scope_guard", - "//folly:try", - "//folly/lang:assume", - "//folly/tracing:async_stack", - ], -) - -non_fbcode_target( - _kind = folly_xplat_cxx_library, - name = "inline_task", - raw_headers = ["detail/InlineTask.h"], - exported_deps = [ - "//xplat/folly:scope_guard", - "//xplat/folly:try", - "//xplat/folly/experimental/coro:coroutine", - "//xplat/folly/experimental/coro:detail_malloc", - "//xplat/folly/experimental/coro:with_async_stack", - "//xplat/folly/lang:assume", - "//xplat/folly/tracing:async_stack", - ], -) - -### this line is a hint for source control merge - fbcode_target( _kind = cpp_library, name = "invoke", @@ -958,10 +756,10 @@ fbcode_target( "//folly/coro:async_generator", "//folly/coro:baton", "//folly/coro:coroutine", - "//folly/coro:detail_barrier", - "//folly/coro:detail_barrier_task", - "//folly/coro:detail_current_async_frame", - "//folly/coro:detail_helpers", + "//folly/coro/detail:barrier", + "//folly/coro/detail:barrier_task", + "//folly/coro/detail:current_async_frame", + "//folly/coro/detail:helpers", "//folly/coro:mutex", "//folly/coro:task", "//folly/coro:via_if_async", @@ -1442,9 +1240,6 @@ fbcode_target( "//folly/coro:base_promise", "//folly/coro:coroutine", "//folly/coro:current_executor", - "//folly/coro:detail_malloc", - "//folly/coro:detail_traits", - "//folly/coro:inline_task", "//folly/coro:invoke", "//folly/coro:result", "//folly/coro:scope_exit", @@ -1452,6 +1247,9 @@ fbcode_target( "//folly/coro:via_if_async", "//folly/coro:with_async_stack", "//folly/coro:with_cancellation", + "//folly/coro/detail:inline_task", + "//folly/coro/detail:malloc", + "//folly/coro/detail:traits", "//folly/futures:core", "//folly/io/async:request_context", "//folly/lang:assume", @@ -1536,7 +1334,7 @@ fbcode_target( "//folly:optional", "//folly/coro:baton", "//folly/coro:coroutine", - "//folly/coro:detail_helpers", + "//folly/coro/detail:helpers", "//folly/coro:invoke", "//folly/coro:task", "//folly/coro:traits", @@ -1744,7 +1542,7 @@ fbcode_target( "//folly:executor", "//folly:traits", "//folly/coro:coroutine", - "//folly/coro:detail_malloc", + "//folly/coro/detail:malloc", "//folly/coro:traits", "//folly/coro:with_async_stack", "//folly/coro:with_cancellation", diff --git a/folly/coro/detail/BUCK b/folly/coro/detail/BUCK index 8aa6f619042..2f227f5930e 100644 --- a/folly/coro/detail/BUCK +++ b/folly/coro/detail/BUCK @@ -1,6 +1,7 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_cxx_library") +load("@fbsource//xplat/pfh/triage_InfrastructureSupermoduleOptou:DEFS.bzl", "triage_InfrastructureSupermoduleOptou") +load("../../defs.bzl", "folly_xplat_cxx_library") oncall("fbcode_entropy_wardens_folly") @@ -25,3 +26,205 @@ non_fbcode_target( "//xplat/folly/lang:safe_alias_fwd", ], ) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "barrier", + headers = ["Barrier.h"], + exported_deps = [ + "//folly/coro:coroutine", + "//folly/coro:traits", + "//folly/coro:with_async_stack", + "//folly/tracing:async_stack", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "barrier", + raw_headers = ["Barrier.h"], + exported_deps = [ + "//xplat/folly/experimental/coro:coroutine", + "//xplat/folly/experimental/coro:traits", + "//xplat/folly/experimental/coro:with_async_stack", + "//xplat/folly/tracing:async_stack", + ], +) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "barrier_task", + headers = ["BarrierTask.h"], + exported_deps = [ + ":barrier", + ":malloc", + "//folly/coro:coroutine", + "//folly/coro:with_async_stack", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "barrier_task", + raw_headers = ["BarrierTask.h"], + exported_deps = [ + ":barrier", + ":malloc", + "//xplat/folly/experimental/coro:coroutine", + "//xplat/folly/experimental/coro:with_async_stack", + ], +) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "current_async_frame", + headers = ["CurrentAsyncFrame.h"], + exported_deps = [ + "//folly:executor", + "//folly/coro:coroutine", + "//folly/coro:with_async_stack", + "//folly/tracing:async_stack", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "current_async_frame", + raw_headers = ["CurrentAsyncFrame.h"], + exported_deps = [ + "//xplat/folly:executor", + "//xplat/folly/experimental/coro:coroutine", + "//xplat/folly/experimental/coro:with_async_stack", + "//xplat/folly/tracing:async_stack", + ], +) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "helpers", + headers = ["Helpers.h"], + exported_deps = [ + "//folly:executor", + "//folly:singleton_thread_local", + "//folly/coro:coroutine", + "//folly/io/async:request_context", + "//folly/tracing:async_stack", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "helpers", + raw_headers = ["Helpers.h"], + exported_deps = [ + "//xplat/folly:executor", + "//xplat/folly:singleton_thread_local", + "//xplat/folly/experimental/coro:coroutine", + "//xplat/folly/io/async:request_context", + "//xplat/folly/tracing:async_stack", + ], +) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "inline_task", + headers = ["InlineTask.h"], + exported_deps = [ + ":malloc", + "//folly:scope_guard", + "//folly:try", + "//folly/coro:coroutine", + "//folly/coro:with_async_stack", + "//folly/lang:assume", + "//folly/tracing:async_stack", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "inline_task", + raw_headers = ["InlineTask.h"], + exported_deps = [ + "//xplat/folly:scope_guard", + "//xplat/folly:try", + "//xplat/folly/experimental/coro:coroutine", + "//xplat/folly/experimental/coro:detail_malloc", + "//xplat/folly/experimental/coro:with_async_stack", + "//xplat/folly/lang:assume", + "//xplat/folly/tracing:async_stack", + ], +) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "malloc", + srcs = ["Malloc.cpp"], + headers = ["Malloc.h"], + deps = [ + "//folly/lang:hint", + "//folly/lang:new", + ], + exported_deps = [ + "//folly:c_portability", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "malloc", + srcs = ["Malloc.cpp"], + raw_headers = ["Malloc.h"], + deps = [ + "//xplat/folly/lang:hint", + "//xplat/folly/lang:new", + ], + exported_deps = ["//xplat/folly:c_portability"], +) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "manual_lifetime", + headers = ["ManualLifetime.h"], + exported_deps = [ + "//folly:scope_guard", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "manual_lifetime", + raw_headers = ["ManualLifetime.h"], + exported_deps = ["//xplat/folly:scope_guard"], +) + +### this line is a hint for source control merge + +fbcode_target( + _kind = cpp_library, + name = "traits", + headers = ["Traits.h"], + exported_deps = [ + "//folly:traits", + ], +) + +non_fbcode_target( + _kind = folly_xplat_cxx_library, + name = "traits", + raw_headers = ["Traits.h"], + exported_deps = ["//xplat/folly:traits"], +) diff --git a/folly/coro/test/BUCK b/folly/coro/test/BUCK index 03183792a39..3bb739b53a4 100644 --- a/folly/coro/test/BUCK +++ b/folly/coro/test/BUCK @@ -178,7 +178,6 @@ fbcode_target( "//folly/coro:future_util", "//folly/coro:generator", "//folly/coro:gtest_helpers", - "//folly/coro:inline_task", "//folly/coro:invoke", "//folly/coro:merge", "//folly/coro:mutex", @@ -194,6 +193,7 @@ fbcode_target( "//folly/coro:unbounded_queue", "//folly/coro:value_or_error", "//folly/coro:with_cancellation", + "//folly/coro/detail:inline_task", "//folly/coro/safe:captures", "//folly/coro/safe:now_task", "//folly/executors:cpu_thread_pool_executor", diff --git a/folly/debugging/symbolizer/BUCK b/folly/debugging/symbolizer/BUCK index df124470b55..9e76ba8ff65 100644 --- a/folly/debugging/symbolizer/BUCK +++ b/folly/debugging/symbolizer/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/debugging/symbolizer/detail/BUCK b/folly/debugging/symbolizer/detail/BUCK index d862af99201..67b824bcd3f 100644 --- a/folly/debugging/symbolizer/detail/BUCK +++ b/folly/debugging/symbolizer/detail/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/debugging/symbolizer/tool/BUCK b/folly/debugging/symbolizer/tool/BUCK index a525c752e37..406352ada32 100644 --- a/folly/debugging/symbolizer/tool/BUCK +++ b/folly/debugging/symbolizer/tool/BUCK @@ -41,19 +41,19 @@ fbcode_target( linker_flags = [ # Trim runtime `DT_NEEDED` deps. - "--as-needed", + "-Wl,--as-needed", # Use a version script to prevent exporting any symbols. - "--version-script=$(location :libFollySegFault.so.v)", + "-Wl,--version-script=$(location :libFollySegFault.so.v)", ] + select({ "DEFAULT": [], "ovr_config//runtime:fbcode": [ # This how we can statically link `libstdc++.so` w/ the fbcode # toolchain. - "--push-state", - "-Bstatic", - "-lstdc++_pic", - "--pop-state", + "-Wl,--push-state", + "-Wl,-Bstatic", + "-Wl,-lstdc++_pic", + "-Wl,--pop-state", ], }), # Statically link libstdc++ to avoid an external dep which could make @@ -69,7 +69,6 @@ fbcode_target( }), ), ], - target_compatible_with = ["fbcode//opensource/macros:broken-in-oss"], deps = [ "//folly:range", "//folly/debugging/symbolizer:signal_handler", diff --git a/folly/docs/BUCK b/folly/docs/BUCK index 0f343788348..5bdac2f2bc8 100644 --- a/folly/docs/BUCK +++ b/folly/docs/BUCK @@ -1,5 +1,5 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") -load("@fbsource//xplat/folly/docs:defs.bzl", "copy", "html") +load(":defs.bzl", "copy", "html") # # Actual listing of source files diff --git a/folly/executors/task_queue/BUCK b/folly/executors/task_queue/BUCK index 974b5869eea..0b5da81261d 100644 --- a/folly/executors/task_queue/BUCK +++ b/folly/executors/task_queue/BUCK @@ -1,11 +1,7 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_cxx_library") -load( - "../../defs.bzl", - "folly_xplat_library", -) +load("../../defs.bzl", "folly_xplat_cxx_library", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/experimental/BUCK b/folly/experimental/BUCK index 593ebf3e33b..0bbb35e0f34 100644 --- a/folly/experimental/BUCK +++ b/folly/experimental/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/experimental/coro/BUCK b/folly/experimental/coro/BUCK index 3d2e0358178..dc11a0607c7 100644 --- a/folly/experimental/coro/BUCK +++ b/folly/experimental/coro/BUCK @@ -130,7 +130,7 @@ non_fbcode_target( name = "detail_barrier", raw_headers = ["detail/Barrier.h"], exported_deps = [ - "//xplat/folly/coro:detail_barrier", + "//xplat/folly/coro/detail:barrier", ], ) @@ -139,7 +139,7 @@ non_fbcode_target( name = "detail_barrier_task", raw_headers = ["detail/BarrierTask.h"], exported_deps = [ - "//xplat/folly/coro:detail_barrier_task", + "//xplat/folly/coro/detail:barrier_task", ], ) @@ -148,7 +148,7 @@ non_fbcode_target( name = "detail_current_async_frame", raw_headers = ["detail/CurrentAsyncFrame.h"], exported_deps = [ - "//xplat/folly/coro:detail_current_async_frame", + "//xplat/folly/coro/detail:current_async_frame", ], ) @@ -157,7 +157,7 @@ non_fbcode_target( name = "detail_helpers", raw_headers = ["detail/Helpers.h"], exported_deps = [ - "//xplat/folly/coro:detail_helpers", + "//xplat/folly/coro/detail:helpers", ], ) @@ -166,7 +166,7 @@ non_fbcode_target( name = "detail_malloc", raw_headers = ["detail/Malloc.h"], exported_deps = [ - "//xplat/folly/coro:detail_malloc", + "//xplat/folly/coro/detail:malloc", ], ) @@ -175,7 +175,7 @@ non_fbcode_target( name = "detail_manual_lifetime", raw_headers = ["detail/ManualLifetime.h"], exported_deps = [ - "//xplat/folly/coro:detail_manual_lifetime", + "//xplat/folly/coro/detail:manual_lifetime", ], ) @@ -184,7 +184,7 @@ non_fbcode_target( name = "detail_traits", raw_headers = ["detail/Traits.h"], exported_deps = [ - "//xplat/folly/coro:detail_traits", + "//xplat/folly/coro/detail:traits", ], ) @@ -241,7 +241,7 @@ non_fbcode_target( name = "inline_task", raw_headers = ["detail/InlineTask.h"], exported_deps = [ - "//xplat/folly/coro:inline_task", + "//xplat/folly/coro/detail:inline_task", ], ) @@ -620,7 +620,7 @@ fbcode_target( "detail/Barrier.h", ], exported_deps = [ - "//folly/coro:detail_barrier", + "//folly/coro/detail:barrier", ], ) @@ -631,7 +631,7 @@ fbcode_target( "detail/BarrierTask.h", ], exported_deps = [ - "//folly/coro:detail_barrier_task", + "//folly/coro/detail:barrier_task", ], ) @@ -642,7 +642,7 @@ fbcode_target( "detail/CurrentAsyncFrame.h", ], exported_deps = [ - "//folly/coro:detail_current_async_frame", + "//folly/coro/detail:current_async_frame", ], ) @@ -653,7 +653,7 @@ fbcode_target( "detail/Helpers.h", ], exported_deps = [ - "//folly/coro:detail_helpers", + "//folly/coro/detail:helpers", ], ) @@ -664,7 +664,7 @@ fbcode_target( "detail/Malloc.h", ], exported_deps = [ - "//folly/coro:detail_malloc", + "//folly/coro/detail:malloc", ], ) @@ -675,7 +675,7 @@ fbcode_target( "detail/ManualLifetime.h", ], exported_deps = [ - "//folly/coro:detail_manual_lifetime", + "//folly/coro/detail:manual_lifetime", ], ) @@ -686,7 +686,7 @@ fbcode_target( "detail/Traits.h", ], exported_deps = [ - "//folly/coro:detail_traits", + "//folly/coro/detail:traits", ], ) @@ -753,7 +753,7 @@ fbcode_target( "detail/InlineTask.h", ], exported_deps = [ - "//folly/coro:inline_task", + "//folly/coro/detail:inline_task", ], ) diff --git a/folly/experimental/io/BUCK b/folly/experimental/io/BUCK index 6b173cc7d32..870315419d9 100644 --- a/folly/experimental/io/BUCK +++ b/folly/experimental/io/BUCK @@ -31,6 +31,7 @@ fb_dirsync_cpp_library( "Liburing.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:liburing", ], @@ -43,6 +44,7 @@ fb_dirsync_cpp_library( "AsyncIoUringSocketFactory.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:async_io_uring_socket", ], @@ -54,6 +56,7 @@ fb_dirsync_cpp_library( "SimpleAsyncIO.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:simple_async_io", ], @@ -89,6 +92,7 @@ fb_dirsync_cpp_library( "EventBasePoller.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:event_base_poller", ], @@ -111,6 +115,7 @@ fb_dirsync_cpp_library( "IoUring.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:io_uring", ], @@ -123,6 +128,7 @@ fb_dirsync_cpp_library( "IoUringBase.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:io_uring_backend", "//folly/io/async:io_uring_provided_buffer_ring", @@ -137,6 +143,7 @@ fb_dirsync_cpp_library( "IoUringProvidedBufferRing.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:io_uring_provided_buffer_ring", ], @@ -148,6 +155,7 @@ fb_dirsync_cpp_library( "IoUringEvent.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:io_uring_event", ], @@ -159,6 +167,7 @@ fb_dirsync_cpp_library( "IoUringEventBaseLocal.h", ], xplat_impl = folly_xplat_library, + target_compatible_with = ["ovr_config//os:linux"], exported_deps = [ "//folly/io/async:io_uring_event_base_local", ], diff --git a/folly/experimental/settings/BUCK b/folly/experimental/settings/BUCK index 4989c2cd2ca..35565dff2a8 100644 --- a/folly/experimental/settings/BUCK +++ b/folly/experimental/settings/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/experimental/symbolizer/BUCK b/folly/experimental/symbolizer/BUCK index fb7c1f96c61..7ee0503057e 100644 --- a/folly/experimental/symbolizer/BUCK +++ b/folly/experimental/symbolizer/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/experimental/symbolizer/detail/BUCK b/folly/experimental/symbolizer/detail/BUCK index dee34560b99..29191fe4bd2 100644 --- a/folly/experimental/symbolizer/detail/BUCK +++ b/folly/experimental/symbolizer/detail/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/functional/BUCK b/folly/functional/BUCK index d1a1fa4dd29..8ecc0e0224d 100644 --- a/folly/functional/BUCK +++ b/folly/functional/BUCK @@ -1,5 +1,5 @@ load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/functional/test/BUCK b/folly/functional/test/BUCK index ca6b7018201..2410a5fbd96 100644 --- a/folly/functional/test/BUCK +++ b/folly/functional/test/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_cxx_test") +load("../../defs.bzl", "folly_xplat_cxx_test") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/futures/BUCK b/folly/futures/BUCK index f93a2ed01c9..0f03e9af4ee 100644 --- a/folly/futures/BUCK +++ b/folly/futures/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/futures/detail/BUCK b/folly/futures/detail/BUCK index 498e255ad93..fc886e88a35 100644 --- a/folly/futures/detail/BUCK +++ b/folly/futures/detail/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/futures/test/WaitTest.cpp b/folly/futures/test/WaitTest.cpp index 7687cc85039..27fe90f0518 100644 --- a/folly/futures/test/WaitTest.cpp +++ b/folly/futures/test/WaitTest.cpp @@ -271,13 +271,17 @@ TEST(Wait, waitWithDuration) { } TEST(Wait, multipleWait) { + // Use Promise/Future to control completion deterministically, + // avoiding flakiness from wall-clock timing dependencies. folly::TestExecutor executor(1); - auto f = futures::sleep(milliseconds(100)).via(&executor); + Promise p; + auto f = p.getSemiFuture().via(&executor); for (size_t i = 0; i < 5; ++i) { EXPECT_FALSE(f.isReady()); f.wait(milliseconds(3)); } EXPECT_FALSE(f.isReady()); + p.setValue(); f.wait(); EXPECT_TRUE(f.isReady()); f.wait(); diff --git a/folly/gen/BUCK b/folly/gen/BUCK index 4de53b24bdd..a16f6f3e158 100644 --- a/folly/gen/BUCK +++ b/folly/gen/BUCK @@ -1,10 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load( - "@fbsource//xplat/folly:defs.bzl", - "DEFAULT_APPLE_SDKS", - "folly_xplat_library", -) +load("../defs.bzl", "DEFAULT_APPLE_SDKS", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/hash/BUCK b/folly/hash/BUCK index 2a07042ec2e..1d56ad7845f 100644 --- a/folly/hash/BUCK +++ b/folly/hash/BUCK @@ -1,7 +1,7 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_cxx_library", "folly_xplat_library") +load("../defs.bzl", "folly_xplat_cxx_library", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/hash/detail/BUCK b/folly/hash/detail/BUCK index faae1215961..7657d877673 100644 --- a/folly/hash/detail/BUCK +++ b/folly/hash/detail/BUCK @@ -1,9 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load( - "@fbsource//xplat/folly:defs.bzl", - "folly_xplat_library", -) +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/io/async/BUCK b/folly/io/async/BUCK index b9eb93df4bb..261d27777c0 100644 --- a/folly/io/async/BUCK +++ b/folly/io/async/BUCK @@ -657,6 +657,7 @@ non_fbcode_target( name = "liburing", raw_headers = ["Liburing.h"], exported_deps = liburing_deps, + target_compatible_with = ["ovr_config//os:linux"], ) fbcode_target( @@ -665,6 +666,7 @@ fbcode_target( name = "liburing", headers = ["Liburing.h"], exported_deps = liburing_deps, + target_compatible_with = ["ovr_config//os:linux"], ) fb_dirsync_cpp_library( @@ -678,6 +680,7 @@ fb_dirsync_cpp_library( ], use_raw_headers = True, xplat_impl = folly_xplat_cxx_library, + target_compatible_with = ["ovr_config//os:linux"], deps = [ ":io_uring_event_base_local", ":io_uring_provided_buffer_ring", @@ -714,6 +717,7 @@ fb_dirsync_cpp_library( headers = ["SimpleAsyncIO.h"], use_raw_headers = True, xplat_impl = folly_xplat_cxx_library, + target_compatible_with = ["ovr_config//os:linux"], deps = [ "//folly:string", "//folly/coro:baton", @@ -771,6 +775,7 @@ fb_dirsync_cpp_library( headers = ["EventBasePoller.h"], use_raw_headers = True, xplat_impl = folly_xplat_cxx_library, + target_compatible_with = ["ovr_config//os:linux"], deps = [ "fbsource//third-party/fmt:fmt", "//folly:file_util", @@ -841,6 +846,7 @@ fb_dirsync_cpp_library( external_deps = [ "glog", ], + target_compatible_with = ["ovr_config//os:linux"], ) fb_dirsync_cpp_library( @@ -893,6 +899,7 @@ fb_dirsync_cpp_library( "boost", "glog", ], + target_compatible_with = ["ovr_config//os:linux"], ) fb_dirsync_cpp_library( @@ -922,6 +929,7 @@ fb_dirsync_cpp_library( exported_external_deps = [ "boost", ], + target_compatible_with = ["ovr_config//os:linux"], ) fb_dirsync_cpp_library( @@ -946,6 +954,7 @@ fb_dirsync_cpp_library( ":liburing", "//folly/io:iobuf", ], + target_compatible_with = ["ovr_config//os:linux"], ) fb_dirsync_cpp_library( @@ -965,6 +974,7 @@ fb_dirsync_cpp_library( "//folly/io/async:io_uring_backend", "//folly/io/async:liburing", ], + target_compatible_with = ["ovr_config//os:linux"], ) fb_dirsync_cpp_library( @@ -987,4 +997,5 @@ fb_dirsync_cpp_library( "//folly/io/async:io_uring_backend", "//folly/io/async:liburing", ], + target_compatible_with = ["ovr_config//os:linux"], ) diff --git a/folly/io/async/test/BUCK b/folly/io/async/test/BUCK index b3ff5f80c76..92d4c76f293 100644 --- a/folly/io/async/test/BUCK +++ b/folly/io/async/test/BUCK @@ -1941,6 +1941,7 @@ fbcode_target( name = "io_benchmark", srcs = ["IOBenchmark.cpp"], headers = [], + target_compatible_with = ["ovr_config//os:linux"], deps = [ "//folly:benchmark", "//folly:file_util", diff --git a/folly/io/async/test/HHWheelTimerTest.cpp b/folly/io/async/test/HHWheelTimerTest.cpp index 8acc8dbd7b9..bc71c662e6f 100644 --- a/folly/io/async/test/HHWheelTimerTest.cpp +++ b/folly/io/async/test/HHWheelTimerTest.cpp @@ -177,20 +177,24 @@ TEST_F(HHWheelTimerTest, TestSetDefaultTimeout) { TEST_F(HHWheelTimerTest, CancelTimeout) { StackWheelTimer t(&eventBase, milliseconds(1)); - // Create several timeouts that will all fire in 5ms. - TestTimeout t5_1(&t, milliseconds(5)); - TestTimeout t5_2(&t, milliseconds(5)); - TestTimeout t5_3(&t, milliseconds(5)); - TestTimeout t5_4(&t, milliseconds(5)); - TestTimeout t5_5(&t, milliseconds(5)); + // This test verifies timeout cancellation logic, not timing precision. + // Timing checks removed to avoid flakiness on systems with coarse timer + // resolution (e.g., Windows ~15.6ms default). - // Also create a few timeouts to fire in 10ms - TestTimeout t10_1(&t, milliseconds(10)); - TestTimeout t10_2(&t, milliseconds(10)); - TestTimeout t10_3(&t, milliseconds(10)); + // Create several timeouts that will all fire together. + TestTimeout t5_1(&t, milliseconds(50)); + TestTimeout t5_2(&t, milliseconds(50)); + TestTimeout t5_3(&t, milliseconds(50)); + TestTimeout t5_4(&t, milliseconds(50)); + TestTimeout t5_5(&t, milliseconds(50)); - TestTimeout t20_1(&t, milliseconds(20)); - TestTimeout t20_2(&t, milliseconds(20)); + // Also create a few timeouts to fire later + TestTimeout t10_1(&t, milliseconds(100)); + TestTimeout t10_2(&t, milliseconds(100)); + TestTimeout t10_3(&t, milliseconds(100)); + + TestTimeout t20_1(&t, milliseconds(200)); + TestTimeout t20_2(&t, milliseconds(200)); // Have t5_1 cancel t5_2 and t5_4. // @@ -212,7 +216,7 @@ TEST_F(HHWheelTimerTest, CancelTimeout) { // Reset our function so we won't continually reschedule ourself std::function fnDtorGuard; t5_3.fn.swap(fnDtorGuard); - t.scheduleTimeout(&t5_3, milliseconds(5)); + t.scheduleTimeout(&t5_3, milliseconds(50)); // Also test cancelling timeouts in another timeset that isn't ready to // fire yet. @@ -224,31 +228,21 @@ TEST_F(HHWheelTimerTest, CancelTimeout) { t20_2.cancelTimeout(); }; - TimePoint start; eventBase.loop(); - TimePoint end; + // Verify callbacks that should have fired ASSERT_EQ(t5_1.timestamps.size(), 1); - T_CHECK_TIMEOUT(start, t5_1.timestamps[0], milliseconds(5)); - - ASSERT_EQ(t5_3.timestamps.size(), 2); - T_CHECK_TIMEOUT(start, t5_3.timestamps[0], milliseconds(5)); - T_CHECK_TIMEOUT(t5_3.timestamps[0], t5_3.timestamps[1], milliseconds(5)); - + ASSERT_EQ(t5_3.timestamps.size(), 2); // fired once, then rescheduled and fired again ASSERT_EQ(t10_1.timestamps.size(), 1); - T_CHECK_TIMEOUT(start, t10_1.timestamps[0], milliseconds(10)); ASSERT_EQ(t10_3.timestamps.size(), 1); - T_CHECK_TIMEOUT(start, t10_3.timestamps[0], milliseconds(10)); - // Cancelled timeouts + // Verify cancelled timeouts never fired ASSERT_EQ(t5_2.timestamps.size(), 0); ASSERT_EQ(t5_4.timestamps.size(), 0); ASSERT_EQ(t5_5.timestamps.size(), 0); ASSERT_EQ(t10_2.timestamps.size(), 0); ASSERT_EQ(t20_1.timestamps.size(), 0); ASSERT_EQ(t20_2.timestamps.size(), 0); - - T_CHECK_TIMEOUT(start, end, milliseconds(10)); } /* diff --git a/folly/lang/BUCK b/folly/lang/BUCK index 6d79a58be62..b9346cb2631 100644 --- a/folly/lang/BUCK +++ b/folly/lang/BUCK @@ -1,7 +1,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects") load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_cxx_library") +load("../defs.bzl", "folly_xplat_cxx_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/lang/Exception.h b/folly/lang/Exception.h index a2d83176359..67119ce905f 100644 --- a/folly/lang/Exception.h +++ b/folly/lang/Exception.h @@ -792,8 +792,14 @@ std::exception_ptr make_exception_ptr_with_( template struct make_exception_ptr_with_fn_ { F& f_; + // Throw and catch instead of using std::make_exception_ptr which copies. + // The throw expression moves from the rvalue returned by f_(). FOLLY_ERASE std::exception_ptr operator()() const { - return std::make_exception_ptr(f_()); + try { + throw f_(); + } catch (...) { + return std::current_exception(); + } } }; diff --git a/folly/logging/BUCK b/folly/logging/BUCK index 67b39a8b9d4..853b722f874 100644 --- a/folly/logging/BUCK +++ b/folly/logging/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/logging/example/BUCK b/folly/logging/example/BUCK index 1e15001b7b3..071ae6e9b42 100644 --- a/folly/logging/example/BUCK +++ b/folly/logging/example/BUCK @@ -1,7 +1,7 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/logging/test/BUCK b/folly/logging/test/BUCK index 8a1d0013990..6e5b06ef1ce 100644 --- a/folly/logging/test/BUCK +++ b/folly/logging/test/BUCK @@ -4,7 +4,7 @@ load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest") load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest") load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/portability/BUCK b/folly/portability/BUCK index 0ed27bff188..11d319d0ad0 100644 --- a/folly/portability/BUCK +++ b/folly/portability/BUCK @@ -6,12 +6,7 @@ load( "MACOSX", "WATCHOS", ) -load( - "@fbsource//xplat/folly:defs.bzl", - "WINDOWS_CLANG_CXX_FLAGS", - "folly_xplat_library", - "should_enable_gflags", -) +load("../defs.bzl", "WINDOWS_CLANG_CXX_FLAGS", "folly_xplat_library", "should_enable_gflags") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/portability/provide/BUCK b/folly/portability/provide/BUCK index bf167f1980d..16727981e71 100644 --- a/folly/portability/provide/BUCK +++ b/folly/portability/provide/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/python/BUCK b/folly/python/BUCK index 4aed877f83e..ef2e4c675ba 100644 --- a/folly/python/BUCK +++ b/folly/python/BUCK @@ -724,7 +724,6 @@ fbcode_target( "DEFAULT": None, "ovr_config//os:windows": "shared", }), - target_compatible_with = ["fbcode//opensource/macros:broken-in-oss"], deps = [ ":import", ], @@ -790,11 +789,10 @@ fbcode_target( srcs = ["iobuf.cpp"], headers = [ "iobuf.h", - # @fb-only[end= ]: ":iobuf__iobuf_api.h", + ":iobuf__iobuf_api.h", ], # TODO(T36778537): Cython-generated `*_api.h` headers aren't modular. modular_headers = False, - target_compatible_with = ["fbcode//opensource/macros:broken-in-oss"], deps = [ ":import", ], @@ -972,9 +970,7 @@ fbcode_target( "DEFAULT": [], # These make it so linking libpython is optional "ovr_config//os:macos": [ - "-Xlinker", "-undefined", - "-Xlinker", "dynamic_lookup", ], }), @@ -1001,9 +997,7 @@ non_fbcode_target( "DEFAULT": [], # These make it so linking libpython is optional "ovr_config//os:macos": [ - "-Xlinker", "-undefined", - "-Xlinker", "dynamic_lookup", ], }), diff --git a/folly/python/fiber_manager.pyx b/folly/python/fiber_manager.pyx index aae10e606ab..3d796c98c6d 100644 --- a/folly/python/fiber_manager.pyx +++ b/folly/python/fiber_manager.pyx @@ -70,7 +70,7 @@ cdef class FiberManager: self.cManager.reset() -cdef cFiberManager* get_fiber_manager_impl(const cFiberManagerOptions& opts): +cdef cFiberManager* get_fiber_manager_impl(const cFiberManagerOptions& opts) noexcept: global last_loop, last_manager loop = asyncio.get_event_loop() diff --git a/folly/python/request_context.pyx b/folly/python/request_context.pyx index 92956fd0ee4..e55cfa16638 100644 --- a/folly/python/request_context.pyx +++ b/folly/python/request_context.pyx @@ -151,7 +151,7 @@ cdef extern from "folly/python/request_context.h": ) -cdef int _watcher(PyContextEvent event, PyObject* pycontext): +cdef int _watcher(PyContextEvent event, PyObject* pycontext) noexcept: cdef shared_ptr[RequestContext] ctx if pycontext is NULL or event != PyContextEvent.Py_CONTEXT_SWITCHED: diff --git a/folly/python/test/BUCK b/folly/python/test/BUCK index ef28da5b561..30256122085 100644 --- a/folly/python/test/BUCK +++ b/folly/python/test/BUCK @@ -292,7 +292,6 @@ fbcode_target( name = "iobuf_test_utils", srcs = ["IOBufTestUtils.cpp"], headers = ["IOBufTestUtils.h"], - target_compatible_with = ["fbcode//opensource/macros:broken-in-oss"], deps = [ "//folly/executors:global_executor", "//folly/python:iobuf_ext", diff --git a/folly/rust/dynamic/BUCK b/folly/rust/dynamic/BUCK index de4607384fe..93777809991 100644 --- a/folly/rust/dynamic/BUCK +++ b/folly/rust/dynamic/BUCK @@ -13,7 +13,7 @@ fbcode_target( cxx_bridge = "dynamic.rs", deps = [ "fbsource//third-party/rust:cxx", - "//common/rust/folly/string:string", + "//folly/rust/string:string", ], ) diff --git a/folly/rust/iobuf/BUCK b/folly/rust/iobuf/BUCK index c61a733f94b..5d66928f8c8 100644 --- a/folly/rust/iobuf/BUCK +++ b/folly/rust/iobuf/BUCK @@ -1,10 +1,8 @@ load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE", "CXX", "FBCODE", "IOS", "MACOSX", "WINDOWS") load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native") -load("@fbsource//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library") load("@fbsource//tools/build_defs:fb_xplat_rust_library.bzl", "fb_xplat_rust_library") load("@fbsource//tools/build_defs:fb_xplat_suffixed_aliases.bzl", "create_forwarding_aliases") -load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode_compatible", "is_fbcode_mode_mac", "is_fbcode_mode_win", "is_xplat") -load("@fbsource//tools/build_defs:rust_bindgen_library.bzl", "rust_bindgen_library") +load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_xplat") oncall("rust_libraries") @@ -13,80 +11,15 @@ oncall("rust_libraries") # in the same build graph. create_forwarding_aliases( name = "iobuf", - actual_name = select({ - "DEFAULT": "fbsource//xplat/folly/rust/iobuf:_iobuf", - "ovr_config//os:linux": "fbcode//folly/rust/iobuf:_iobuf" if is_fbcode_compatible() else "fbsource//xplat/folly/rust/iobuf:_iobuf", - "ovr_config//os:macos": "fbcode//folly/rust/iobuf:_iobuf" if is_fbcode_mode_mac() else "fbsource//xplat/folly/rust/iobuf:_iobuf", - "ovr_config//os:windows": "fbcode//folly/rust/iobuf:_iobuf" if is_fbcode_mode_win() else "fbsource//xplat/folly/rust/iobuf:_iobuf", - }), + actual_name = get_cell_name() + "//" + package_name() + ":_iobuf", platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS), sdks = (IOS, MACOSX), visibility = ["PUBLIC"], -) if is_xplat() else None - -create_forwarding_aliases( - name = "iobuf-ffi", - actual_name = select({ - "DEFAULT": "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi", - "ovr_config//os:linux": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_compatible() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi", - "ovr_config//os:macos": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_mode_mac() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi", - "ovr_config//os:windows": "fbcode//folly/rust/iobuf:_iobuf-ffi" if is_fbcode_mode_win() else "fbsource//xplat/folly/rust/iobuf:_iobuf-ffi", - }), - platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS), - sdks = (IOS, MACOSX), - visibility = ["PUBLIC"], -) if is_xplat() else None - -rust_bindgen_library( - name = "iobuf-sys", - allowlist_funcs = [ - "facebook::rust::.*", - ], - allowlist_types = [ - "folly::IOBuf", - "facebook::rust::.*", - ], - allowlist_vars = [ - "facebook::rust::.*", - ], - blocklist_types = [ - # These seems to come from type_traits / make_signed via fbvector - "folly::fbvector.*", - "__type", - "type_", - ], - cpp_deps = [":_iobuf-ffi"], - cxx_namespaces = True, - generate = ("types", "vars", "functions"), - header = "iobuf.h", - opaque_types = [ - "std::.*", - "folly::fbstring.*", - ], - platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS), - src_includes = ["iobuf_sys.rs"], - visibility = [], -) - -fb_xplat_cxx_library( - name = "_iobuf-ffi", - srcs = ["iobuf.cpp"], - exported_headers = ["iobuf.h"], - platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS), - preferred_linkage = "static", - visibility = [ - "fbcode//folly/rust/iobuf/...", - "fbsource//xplat/folly/rust/iobuf/...", - ], - exported_deps = [ - "fbsource//xplat/folly/io:iobuf" if is_xplat() else "fbcode//folly/io:iobuf", - ], ) fb_xplat_rust_library( name = "_iobuf", srcs = glob(["src/*.rs"]), - cpp_deps = [":_iobuf-ffi"], crate = "iobuf", crate_root = "src/lib.rs", cxx_bridge = "src/lib.rs", @@ -104,9 +37,8 @@ fb_xplat_rust_library( "fbsource//third-party/rust:bytes", "fbsource//third-party/rust:cxx", "fbsource//third-party/rust:memmap2", - "fbsource//xplat/thrift/lib/rust:fbthrift", - ":iobuf-sys", - ], + get_cell_name() + "//" + package_name() + "_sys:iobuf-sys", + ] ) fb_native.alias( diff --git a/folly/rust/iobuf/Cargo.toml b/folly/rust/iobuf/Cargo.toml new file mode 100644 index 00000000000..acae192d4f6 --- /dev/null +++ b/folly/rust/iobuf/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "iobuf" +version = "0.1.0" +edition = "2024" + +[features] +minibytes = [] + +[dependencies] +bytes = { version = "1.9.0", features = ["serde"] } +cxx = "1.0" +fbthrift = { version = "0.0.1+unstable", git = "https://github.com/facebook/fbthrift.git", branch = "main" } +iobuf_sys = { version = "0.1.0", path = "../iobuf_sys" } +memmap2 = "0.9" + +[build-dependencies] +cxx-build = "1.0" +pkg-config = "0.3" diff --git a/folly/rust/iobuf/build.rs b/folly/rust/iobuf/build.rs new file mode 100644 index 00000000000..653eb802b02 --- /dev/null +++ b/folly/rust/iobuf/build.rs @@ -0,0 +1,13 @@ +fn main() { + let libfmt = pkg_config::probe_library("fmt") + .expect("Couldn’t find fmt via pkg-config"); + let libfolly = pkg_config::probe_library("libfolly") + .expect("Couldn’t find folly via pkg-config"); + + cxx_build::bridge("src/lib.rs") + .file("../iobuf_sys/iobuf.cpp") + .include("../../..") + .includes(&libfmt.include_paths) + .includes(&libfolly.include_paths) + .compile("iobuf"); +} diff --git a/folly/rust/iobuf/src/bufext.rs b/folly/rust/iobuf/src/bufext.rs new file mode 100644 index 00000000000..5d0050b12a9 --- /dev/null +++ b/folly/rust/iobuf/src/bufext.rs @@ -0,0 +1,167 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * 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. + */ + +//! Extensions to the `bytes` crate's `Buf` and `BufMut` traits. +//! +//! These traits were originally part of fbthrift but are extracted here +//! to avoid a circular dependency between folly and fbthrift. + +use std::io::Cursor; + +use bytes::Buf; +use bytes::BufMut; +use bytes::Bytes; +use bytes::BytesMut; +use bytes::buf::Chain; + +pub trait BufExt: Buf { + /// Copy `len` Bytes from this (and advance the position), or reuse them from the underlying + /// buffer if possible. + fn copy_or_reuse_bytes(&mut self, len: usize) -> Bytes { + // Default is to just copy. + self.copy_to_bytes(len) + } + + /// Whether there are enough remaining bytes to advance this buffer's + /// internal cursor by `n`. + /// + /// Disjoint buffers for which `remaining()` is not O(1) should override + /// this method with a more efficient implementation. + fn can_advance(&self, n: usize) -> bool { + n <= self.remaining() + } + + /// Number of more bytes needed in order to be able to advance by `n`. + /// + /// If `n <= remaining()`, this is 0. Otherwise `n - remaining()`. + /// + /// Disjoint buffers for which `remaining()` is not O(1) should override + /// this method with a more efficient implementation. + fn shortfall(&self, n: usize) -> usize { + n.saturating_sub(self.remaining()) + } +} + +impl BufExt for Bytes {} + +impl BufExt for Cursor { + // We can get a reference to the underlying Bytes here, and reuse that. + fn copy_or_reuse_bytes(&mut self, len: usize) -> Bytes { + let pos = self.position() as usize; + let end = pos + len; + // Panics if len is too large (same as Bytes) + let bytes = self.get_ref().slice(pos..end); + self.set_position(end as u64); + bytes + } +} + +impl + ?Sized> BufExt for Cursor<&T> {} + +impl BufExt for Chain { + fn can_advance(&self, n: usize) -> bool { + let rest = self.first_ref().shortfall(n); + self.last_ref().can_advance(rest) + } + + fn shortfall(&self, n: usize) -> usize { + let rest = self.first_ref().shortfall(n); + self.last_ref().shortfall(rest) + } +} + +pub trait BufMutExt: BufMut { + type Final: Send + 'static; + + fn finalize(self) -> Self::Final; +} + +impl BufMutExt for BytesMut { + type Final = Bytes; + + fn finalize(self) -> Self::Final { + self.freeze() + } +} + +/// Helper newtype for deserialization sources +pub struct DeserializeSource(pub B); + +impl DeserializeSource { + pub fn new(b: B) -> Self { + DeserializeSource(b) + } +} + +// These types will use a copying cursor +macro_rules! impl_deser_as_ref_u8 { + ( $($t:ty),* ) => { + $( + impl<'a> From<&'a $t> for DeserializeSource> { + fn from(from: &'a $t) -> Self { + let data: &[u8] = from.as_ref(); + Self(Cursor::new(data)) + } + } + )* + } +} + +impl_deser_as_ref_u8!([u8], Vec, String, str); + +// These types take ownership without copying +macro_rules! impl_deser_into_bytes { + ( $($t:ty),* ) => { + $( + impl From<$t> for DeserializeSource> { + fn from(from: $t) -> Self { + Self(Cursor::new(from.into())) + } + } + )* + } +} + +impl_deser_into_bytes!(Bytes, Vec, String); + +// Special case for &Bytes that is not covered in upstream crates From defs +impl From<&Bytes> for DeserializeSource> { + fn from(from: &Bytes) -> Self { + // ok to clone Bytes, it just increments ref count + Self(Cursor::new(from.clone())) + } +} + +/// Trait describing the in-memory frames the transport uses for Protocol messages. +pub trait Framing { + /// Buffer type we encode into + type EncBuf: BufMutExt + Send + 'static; + + /// Buffer type we decode from + type DecBuf: BufExt + Send + 'static; + + /// Allocate a new encoding buffer with a given capacity + fn enc_with_capacity(cap: usize) -> Self::EncBuf; +} + +impl Framing for Bytes { + type EncBuf = BytesMut; + type DecBuf = Cursor; + + fn enc_with_capacity(cap: usize) -> Self::EncBuf { + BytesMut::with_capacity(cap) + } +} diff --git a/folly/rust/iobuf/src/cursor.rs b/folly/rust/iobuf/src/cursor.rs index e5e138146d2..ec10af75f16 100644 --- a/folly/rust/iobuf/src/cursor.rs +++ b/folly/rust/iobuf/src/cursor.rs @@ -21,12 +21,13 @@ use std::slice; use bytes::Buf; use bytes::BufMut; use bytes::buf::UninitSlice; -use fbthrift::BufExt; -use fbthrift::BufMutExt; -use fbthrift::DeserializeSource; -use fbthrift::framing::Framing; use iobuf_sys::root::folly::IOBuf as IOBufSys; +use crate::bufext::BufExt; +use crate::bufext::BufMutExt; +use crate::bufext::DeserializeSource; +use crate::bufext::Framing; + use crate::iobuf::IOBufShared; use crate::iobuf::RawIOBufPtr; use crate::iobufmut::IOBufMut; diff --git a/folly/rust/iobuf/src/iobuf.rs b/folly/rust/iobuf/src/iobuf.rs index 73b625832e8..1c2002e5569 100644 --- a/folly/rust/iobuf/src/iobuf.rs +++ b/folly/rust/iobuf/src/iobuf.rs @@ -20,11 +20,11 @@ use std::slice; use bytes::Buf; use bytes::Bytes; use cxx::UniquePtr; -#[cfg(fbcode_build)] -use fbthrift::BufExt; use iobuf_sys::root::facebook::rust::*; use iobuf_sys::root::folly::IOBuf as IOBufSys; +use crate::bufext::BufExt; + use crate::IOBuf; use crate::bridge; use crate::cursor::IOBufCursor; @@ -89,10 +89,6 @@ impl IOBufShared { IOBufCursor::from(self) } - // This is internal-only to avoid external folly depending on fbthrift, - // that complicates build. A potentially long-term fix might be moving - // BufExt to a small, shared, and published crate. - #[cfg(fbcode_build)] /// Converts a `BufExt` into a potentially chained `IOBufShared`. Whether /// this conversion copies is dependent on whether /// `BufExt::copy_or_reuse_bytes` copies. diff --git a/folly/rust/iobuf/src/lib.rs b/folly/rust/iobuf/src/lib.rs index e3271035c23..ead2321201e 100644 --- a/folly/rust/iobuf/src/lib.rs +++ b/folly/rust/iobuf/src/lib.rs @@ -41,6 +41,7 @@ #[cfg(test)] mod test; +mod bufext; mod cursor; mod iobuf; mod iobufmut; @@ -52,6 +53,10 @@ use cxx::ExternType; use cxx::type_id; use iobuf_sys::root::folly::IOBuf as IOBufSys; +pub use crate::bufext::BufExt; +pub use crate::bufext::BufMutExt; +pub use crate::bufext::DeserializeSource; +pub use crate::bufext::Framing; pub use crate::cursor::IOBufCursor; pub use crate::cursor::IOBufCursorFastRemaining; pub use crate::cursor::IOBufMutCursor; @@ -125,7 +130,7 @@ pub mod bridge { #[namespace = "facebook::rust"] unsafe extern "C++" { - include!("folly/rust/iobuf/iobuf.h"); + include!("folly/rust/iobuf_sys/iobuf.h"); fn iobuf_create(cap: usize) -> UniquePtr; fn iobuf_create_combined(cap: usize) -> UniquePtr; diff --git a/folly/rust/iobuf_sys/BUCK b/folly/rust/iobuf_sys/BUCK new file mode 100644 index 00000000000..57a44e5e16a --- /dev/null +++ b/folly/rust/iobuf_sys/BUCK @@ -0,0 +1,60 @@ +load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE", "CXX", "FBCODE", "WINDOWS") +load("@fbsource//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library") +load("@fbsource//tools/build_defs:fb_xplat_suffixed_aliases.bzl", "create_forwarding_aliases") +load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode_compatible", "is_fbcode_mode_mac", "is_fbcode_mode_win", "is_xplat") +load("@fbsource//tools/build_defs:rust_bindgen_library.bzl", "rust_bindgen_library") + +oncall("rust_libraries") + +rust_bindgen_library( + name = "iobuf-sys", + allowlist_funcs = [ + "facebook::rust::.*", + ], + allowlist_types = [ + "folly::IOBuf", + "facebook::rust::.*", + ], + allowlist_vars = [ + "facebook::rust::.*", + ], + blocklist_types = [ + # These seems to come from type_traits / make_signed via fbvector + "folly::fbvector.*", + "__type", + "type_", + ], + cpp_deps = [":iobuf-ffi"], + cxx_namespaces = True, + generate = ("types", "vars", "functions"), + header = "iobuf.h", + opaque_types = [ + "std::.*", + "folly::fbstring.*", + ], + platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS), + src_includes = ["src/lib.rs"], + visibility = [], +) + +create_forwarding_aliases( + name = "iobuf-ffi", + actual_name = get_cell_name() + "//" + package_name() + ":_iobuf-ffi", + platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS), + visibility = ["PUBLIC"], +) + +fb_xplat_cxx_library( + name = "_iobuf-ffi", + srcs = ["iobuf.cpp"], + exported_headers = ["iobuf.h"], + platforms = (CXX, ANDROID, APPLE, FBCODE, WINDOWS), + preferred_linkage = "static", + visibility = [ + "fbcode//folly/rust/iobuf/...", + "fbsource//xplat/folly/rust/iobuf/...", + ], + exported_deps = [ + "//" + package_name().replace("/rust/iobuf_sys", "/io") + ":iobuf", + ], +) diff --git a/folly/rust/iobuf_sys/Cargo.toml b/folly/rust/iobuf_sys/Cargo.toml new file mode 100644 index 00000000000..b7dec02cf26 --- /dev/null +++ b/folly/rust/iobuf_sys/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "iobuf_sys" +version = "0.1.0" +edition = "2024" + +# [lib] +# Cargo automatically uses OUT_DIR/lib.rs when build.rs exists and writes to it + +[dependencies] +cxx = "1.0" + +[build-dependencies] +bindgen = "0.72" +pkg-config = "0.3" diff --git a/folly/rust/iobuf_sys/build.rs b/folly/rust/iobuf_sys/build.rs new file mode 100644 index 00000000000..55572205eaf --- /dev/null +++ b/folly/rust/iobuf_sys/build.rs @@ -0,0 +1,100 @@ +use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; +use std::collections::HashSet; +use std::env; +use std::path::PathBuf; + +// Workaround for https://github.com/rust-lang/rust-bindgen/issues/687 +const IGNORE_MACROS +// : [&str; 20] = [ +: [&str; 10] = [ + // "FE_DIVBYZERO", + // "FE_DOWNWARD", + // "FE_INEXACT", + // "FE_INVALID", + // "FE_OVERFLOW", + // "FE_TONEAREST", + // "FE_TOWARDZERO", + // "FE_UNDERFLOW", + // "FE_UPWARD", + "FP_INFINITE", + "FP_INT_DOWNWARD", + "FP_INT_TONEAREST", + "FP_INT_TONEARESTFROMZERO", + "FP_INT_TOWARDZERO", + "FP_INT_UPWARD", + "FP_NAN", + "FP_NORMAL", + "FP_SUBNORMAL", + "FP_ZERO", + // "IPPORT_RESERVED", +]; + +#[derive(Debug)] +struct IgnoreMacros(HashSet); + +impl ParseCallbacks for IgnoreMacros { + fn will_parse_macro(&self, name: &str) -> MacroParsingBehavior { + if self.0.contains(name) { + MacroParsingBehavior::Ignore + } else { + MacroParsingBehavior::Default + } + } +} + +impl IgnoreMacros { + fn new() -> Self { + Self(IGNORE_MACROS + .into_iter().map(|s| s.to_owned()).collect()) + } +} + +fn main() { + let gflags = pkg_config::probe_library("gflags") + .expect("Couldn’t find fmt via gflags"); + let libfmt = pkg_config::probe_library("fmt") + .expect("Couldn’t find fmt via pkg-config"); + let libfolly = pkg_config::probe_library("libfolly") + .expect("Couldn’t find folly via pkg-config"); + let libglog = pkg_config::probe_library("libglog") + .expect("Couldn’t find glog via pkg-config"); + + let bindings = bindgen::Builder::default() + .header("iobuf.h") + .with_codegen_config( + bindgen::CodegenConfig::TYPES | + bindgen::CodegenConfig::FUNCTIONS | + bindgen::CodegenConfig::VARS + ) + .clang_arg("-x") + .clang_arg("c++") + .clang_arg("-std=c++17") + .enable_cxx_namespaces() + + .allowlist_function("facebook::rust::.*") + .allowlist_type("folly::IOBuf") + .allowlist_type("facebook::rust::.*") + .allowlist_var("facebook::rust::.*") + .blocklist_type("folly::fbvector.*") + .blocklist_type("__type") + .blocklist_type("type_") + .opaque_type("(::)?std::.*") + .opaque_type("folly::fbstring.*") + + .clang_arg("-I../../..") + .clang_args(gflags.include_paths.iter().map(|p| format!("-I{}", p.display()))) + .clang_args(libfmt.include_paths.iter().map(|p| format!("-I{}", p.display()))) + .clang_args(libfolly.include_paths.iter().map(|p| format!("-I{}", p.display()))) + .clang_args(libglog.include_paths.iter().map(|p| format!("-I{}", p.display()))) + + .generate() + .expect("Unable to generate bindings"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let out_file = out_path.join("bindings.rs"); + std::fs::create_dir_all(&out_path) + .expect("Couldn't create output directory for bindings"); + bindings + .write_to_file(&out_file) + .expect("Couldn't write bindings!"); +} diff --git a/folly/rust/iobuf/iobuf.cpp b/folly/rust/iobuf_sys/iobuf.cpp similarity index 97% rename from folly/rust/iobuf/iobuf.cpp rename to folly/rust/iobuf_sys/iobuf.cpp index 073760d533e..24d9be2f289 100644 --- a/folly/rust/iobuf/iobuf.cpp +++ b/folly/rust/iobuf_sys/iobuf.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include namespace facebook { namespace rust { diff --git a/folly/rust/iobuf/iobuf.h b/folly/rust/iobuf_sys/iobuf.h similarity index 100% rename from folly/rust/iobuf/iobuf.h rename to folly/rust/iobuf_sys/iobuf.h diff --git a/folly/rust/iobuf/iobuf_sys.rs b/folly/rust/iobuf_sys/src/lib.rs similarity index 78% rename from folly/rust/iobuf/iobuf_sys.rs rename to folly/rust/iobuf_sys/src/lib.rs index b1da1581b82..cd197c7d9ff 100644 --- a/folly/rust/iobuf/iobuf_sys.rs +++ b/folly/rust/iobuf_sys/src/lib.rs @@ -14,8 +14,12 @@ * limitations under the License. */ -// Extra definitions for the `iobuf_sys` crate, generated via `bindgen`. +// Include bindings generated by bindgen +// For Cargo: build.rs writes to OUT_DIR/bindings.rs +// For buck2: rust_bindgen_library sets OUT_DIR="." and maps bindings.rs to src/bindings.rs +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +// Extra definitions for the `iobuf_sys` crate, generated via `bindgen`. use crate::root::folly::IOBuf; // IOBuf isn't movable but can be transferred across thread boundaries if appropriately pinned diff --git a/folly/rust/string/BUCK b/folly/rust/string/BUCK index 60bca428213..0c3a829d5fe 100644 --- a/folly/rust/string/BUCK +++ b/folly/rust/string/BUCK @@ -1,51 +1,12 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") -load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//tools/build_defs:rust_bindgen_library.bzl", "rust_bindgen_library") load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library") oncall("rust_libraries") -fbcode_target( - _kind = rust_bindgen_library, - name = "string-sys", - allowlist_funcs = [ - "facebook::rust::.*", - ], - allowlist_types = [ - "facebook::rust::.*", - "folly::(Mutable)?(StringPiece|ByteRange)", - ], - allowlist_vars = [ - "facebook::rust::.*", - ], - cpp_deps = [":string-ffi"], - # Don't use modules so that we can import std_string from here - # into other modules needing C++ folly:StringPiece. - cxx_namespaces = False, - generate = ("types", "methods", "functions", "vars"), - header = "string.h", - opaque_types = [ - "folly::(Mutable)?(StringPiece|ByteRange)", - ], - src_includes = ["string.rs"], - deps = [ - "fbsource//third-party/rust:cxx", - ], -) - -fbcode_target( - _kind = cpp_library, - name = "string-ffi", - srcs = ["string.cpp"], - headers = ["string.h"], - exported_deps = [ - "//folly:range", - ], -) fbcode_target( _kind = rust_library, name = "string", srcs = ["lib.rs"], - deps = [":string-sys"], + deps = ["//folly/rust/string_sys:string-sys"], ) diff --git a/folly/rust/string_sys/BUCK b/folly/rust/string_sys/BUCK new file mode 100644 index 00000000000..f300855a5a8 --- /dev/null +++ b/folly/rust/string_sys/BUCK @@ -0,0 +1,43 @@ +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") +load("@fbsource//tools/build_defs:rust_bindgen_library.bzl", "rust_bindgen_library") + +oncall("rust_libraries") + +fbcode_target( + _kind = rust_bindgen_library, + name = "string-sys", + allowlist_funcs = [ + "facebook::rust::.*", + ], + allowlist_types = [ + "facebook::rust::.*", + "folly::(Mutable)?(StringPiece|ByteRange)", + ], + allowlist_vars = [ + "facebook::rust::.*", + ], + cpp_deps = [":string-ffi"], + # Don't use modules so that we can import std_string from here + # into other modules needing C++ folly:StringPiece. + cxx_namespaces = False, + generate = ("types", "methods", "functions", "vars"), + header = "string.h", + opaque_types = [ + "folly::(Mutable)?(StringPiece|ByteRange)", + ], + src_includes = ["src/lib.rs"], + deps = [ + "fbsource//third-party/rust:cxx", + ], +) + +fbcode_target( + _kind = cpp_library, + name = "string-ffi", + srcs = ["string.cpp"], + headers = ["string.h"], + exported_deps = [ + "//folly:range", + ], +) diff --git a/folly/rust/string/string.rs b/folly/rust/string_sys/src/lib.rs similarity index 97% rename from folly/rust/string/string.rs rename to folly/rust/string_sys/src/lib.rs index 5758a20d942..daa6f574f9a 100644 --- a/folly/rust/string/string.rs +++ b/folly/rust/string_sys/src/lib.rs @@ -14,13 +14,14 @@ * limitations under the License. */ +// Include bindings generated by bindgen +// For Cargo: build.rs writes to OUT_DIR/bindings.rs +// For buck2: rust_bindgen_library sets OUT_DIR="src" and maps bindings.rs to src/bindings.rs +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + // This is being included in the bindgen-generated crate // to add extra methods and traits to the types it generates, and // add some additional helper types/traits. -// -// It can't be easily split into multiple files because: -// - it takes advantage of being in the same crate/module as the generated code, and -// - the current rust_bindgen_library() rule doesn't allow multiple files to be added as deps use std::fmt; use std::fmt::Debug; diff --git a/folly/rust/string/string.cpp b/folly/rust/string_sys/string.cpp similarity index 98% rename from folly/rust/string/string.cpp rename to folly/rust/string_sys/string.cpp index 90ea691ce2e..a4e1eeb5549 100644 --- a/folly/rust/string/string.cpp +++ b/folly/rust/string_sys/string.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include namespace facebook { namespace rust { diff --git a/folly/rust/string/string.h b/folly/rust/string_sys/string.h similarity index 100% rename from folly/rust/string/string.h rename to folly/rust/string_sys/string.h diff --git a/folly/rust/tdigest/BUCK b/folly/rust/tdigest/BUCK index fd4cf2a4f85..70005cd09d5 100644 --- a/folly/rust/tdigest/BUCK +++ b/folly/rust/tdigest/BUCK @@ -18,7 +18,7 @@ fbcode_target( "facebook::rust::.*", ], cpp_deps = [":tdigest-ffi"], - cxx_bridge = "tdigest.rs", + cxx_bridge = "lib.rs", cxx_namespaces = True, generate = ("types", "vars", "functions"), header = "tdigest.h", @@ -26,7 +26,7 @@ fbcode_target( "std::.*", ], rustc_flags = ["-Aunused-crate-dependencies"], # because of fbsource//third-party/rust:rand which is only used in tests and test_deps not defined in rust_bindgen_library - src_includes = ["tdigest.rs"], + src_includes = ["lib.rs"], deps = [ "fbsource//third-party/rust:cxx", "fbsource//third-party/rust:rand", diff --git a/folly/rust/tdigest/tdigest.rs b/folly/rust/tdigest/lib.rs similarity index 98% rename from folly/rust/tdigest/tdigest.rs rename to folly/rust/tdigest/lib.rs index fd632b9105d..3950a269d87 100644 --- a/folly/rust/tdigest/tdigest.rs +++ b/folly/rust/tdigest/lib.rs @@ -14,6 +14,11 @@ * limitations under the License. */ +// Include bindings generated by bindgen +// For Cargo: build.rs writes to OUT_DIR/bindings.rs +// For buck2: rust_bindgen_library sets OUT_DIR="src" and maps bindings.rs to src/bindings.rs +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + use cxx::ExternType; use cxx::type_id; pub use root::folly; diff --git a/folly/stats/BUCK b/folly/stats/BUCK index a6450405333..d42e43a9c07 100644 --- a/folly/stats/BUCK +++ b/folly/stats/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/stats/detail/BUCK b/folly/stats/detail/BUCK index d12becc2959..d24f2814d9f 100644 --- a/folly/stats/detail/BUCK +++ b/folly/stats/detail/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/synchronization/detail/BUCK b/folly/synchronization/detail/BUCK index 606571c2f93..013d678108b 100644 --- a/folly/synchronization/detail/BUCK +++ b/folly/synchronization/detail/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/synchronization/example/BUCK b/folly/synchronization/example/BUCK index ebe6969f3c6..1f3fca0b919 100644 --- a/folly/synchronization/example/BUCK +++ b/folly/synchronization/example/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/synchronization/test/HazptrBench.cpp b/folly/synchronization/test/HazptrBench.cpp index ad7928fabd5..fc553bab835 100644 --- a/folly/synchronization/test/HazptrBench.cpp +++ b/folly/synchronization/test/HazptrBench.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/folly/system/BUCK b/folly/system/BUCK index 062eef991ec..5d6406b60e1 100644 --- a/folly/system/BUCK +++ b/folly/system/BUCK @@ -1,6 +1,6 @@ load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") load("@fbsource//xplat/pfh/triage_InfrastructureSupermoduleOptou:DEFS.bzl", "triage_InfrastructureSupermoduleOptou") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/system/arch/BUCK b/folly/system/arch/BUCK index ab7ca251f07..54bac6c1ca4 100644 --- a/folly/system/arch/BUCK +++ b/folly/system/arch/BUCK @@ -1,6 +1,6 @@ load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") load("@fbsource//xplat/pfh/triage_InfrastructureSupermoduleOptou:DEFS.bzl", "triage_InfrastructureSupermoduleOptou") +load("../../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/system/test/BUCK b/folly/system/test/BUCK index d0ebf7d7528..5011518be30 100644 --- a/folly/system/test/BUCK +++ b/folly/system/test/BUCK @@ -1,6 +1,6 @@ load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_unittest.bzl", "fb_dirsync_cpp_unittest") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_cxx_test") load("@fbsource//xplat/pfh/triage_InfrastructureSupermoduleOptou:DEFS.bzl", "triage_InfrastructureSupermoduleOptou") +load("../../defs.bzl", "folly_xplat_cxx_test") oncall("fbcode_entropy_wardens_folly") diff --git a/folly/testing/BUCK b/folly/testing/BUCK index 12702873555..7b5631ee408 100644 --- a/folly/testing/BUCK +++ b/folly/testing/BUCK @@ -1,6 +1,6 @@ load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target") load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library") -load("@fbsource//xplat/folly:defs.bzl", "folly_xplat_library") +load("../defs.bzl", "folly_xplat_library") oncall("fbcode_entropy_wardens_folly")