├── .bazelci ├── config.yaml └── windows-update-certs.ps1 ├── .bazelignore ├── .bazelrc ├── .bazelversion ├── .bcr ├── config.yml ├── metadata.template.json ├── presubmit.yml └── source.template.json ├── .clang-format ├── .gitattributes ├── .github └── workflows │ ├── ci.bazelrc │ ├── docs.yaml │ ├── formatting.yaml │ ├── release.yml │ ├── release_prep.sh │ └── stale.yaml.disabled ├── .gitignore ├── .pre-commit-config.yaml ├── .shellcheckrc ├── ARCHITECTURE.md ├── AUTHORS ├── BUILD.bazel ├── CODEOWNERS ├── CONTRIBUTING.md ├── LICENSE ├── MODULE.bazel ├── NEWS.md ├── README.md ├── WORKSPACE.bazel ├── WORKSPACE.bzlmod ├── docs ├── .bazelrc ├── .bazelversion ├── .gitignore ├── BUILD.bazel ├── MODULE.bazel ├── MODULE.bazel.lock ├── README.md ├── WORKSPACE.bazel ├── book.toml ├── docs.bzl ├── publish_book.sh ├── src │ ├── SUMMARY.md │ ├── index.md │ └── rules.md ├── stardoc_deps.bzl └── stardoc_repository.bzl ├── examples ├── .bazelignore ├── .bazelrc ├── .bazelversion ├── BUILD.bazel ├── MODULE.bazel ├── README.md ├── WORKSPACE.bazel ├── WORKSPACE.bzlmod ├── cmake_android │ ├── AndroidManifest.xml │ ├── BUILD.bazel │ ├── LibraryManifest.xml │ ├── cpp │ │ └── native-lib.cpp │ ├── hello_lib-example.cpp │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── android │ │ │ └── bazel │ │ │ └── MainActivity.java │ ├── res │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ └── zlib-example.cpp ├── cmake_crosstool │ ├── .bazelrc │ ├── .bazelversion │ ├── BUILD.bazel │ ├── WORKSPACE.bazel │ ├── compilers │ │ └── BUILD.linaro_linux_gcc_5.3.1.bazel │ ├── hello.cc │ ├── static │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── hello_client.c │ │ ├── hello_client_version123.c │ │ ├── src │ │ │ ├── CMakeLists.txt │ │ │ ├── hello.c │ │ │ └── hello.h │ │ └── test_hello.sh │ └── tools │ │ └── arm_compiler │ │ ├── BUILD.bazel │ │ ├── CROSSTOOL │ │ └── linaro_linux_gcc │ │ ├── BUILD.bazel │ │ ├── arm-linux-gnueabihf-ar │ │ ├── arm-linux-gnueabihf-as │ │ ├── arm-linux-gnueabihf-gcc │ │ ├── arm-linux-gnueabihf-ld │ │ ├── arm-linux-gnueabihf-nm │ │ ├── arm-linux-gnueabihf-objcopy │ │ ├── arm-linux-gnueabihf-objdump │ │ └── arm-linux-gnueabihf-strip ├── cmake_defines │ ├── BUILD.bazel │ ├── lib_a │ │ ├── CMakeLists.txt │ │ └── lib_a.cpp │ ├── lib_b │ │ ├── CMakeLists.txt │ │ └── lib_b.cpp │ └── nocrosstool │ │ └── BUILD.bazel ├── cmake_hello_world_lib │ ├── binary │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── hello.c │ │ │ ├── hello.h │ │ │ └── main.c │ ├── shared │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── hello_client.c │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── hello.c │ │ │ └── hello.h │ └── static │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── hello_client.c │ │ ├── hello_client_version123.c │ │ ├── src │ │ ├── CMakeLists.txt │ │ ├── hello.c │ │ └── hello.h │ │ └── test_hello.sh ├── cmake_synthetic │ ├── BUILD.bazel │ ├── liba │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── liba.cpp │ │ │ └── liba.h │ ├── libb │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── libb.cpp │ │ │ └── libb.h │ ├── libc │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── libc.cpp │ │ │ └── libc.h │ └── test_libb.cpp ├── cmake_with_bazel_transitive │ ├── BUILD.bazel │ ├── libb │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── libb.cpp │ │ │ └── libb.h │ └── test_libb.cpp ├── cmake_with_data │ ├── BUILD.bazel │ ├── cmake_with_data.txt │ ├── lib_a │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── lib_a.cpp │ │ │ └── lib_a.h │ ├── lib_b │ │ ├── BUILD.bazel │ │ └── src │ │ │ ├── lib_b.cpp │ │ │ └── lib_b.h │ └── tests │ │ ├── test_cmake_with_data.cpp │ │ └── test_cmake_with_shared_lib.cpp ├── cmake_with_target │ ├── BUILD.bazel │ └── src │ │ ├── CMakeLists.txt │ │ ├── lib.cpp │ │ └── lib.h ├── cmake_working_dir │ ├── BUILD.bazel │ ├── source_root │ │ ├── .keep │ │ ├── cmake_dir │ │ │ └── CMakeLists.txt │ │ └── src │ │ │ ├── liba.cpp │ │ │ └── liba.h │ └── test_liba.cpp ├── configure_modify_input_source │ ├── BUILD.bazel │ ├── simple_lib │ │ ├── BUILD.bazel │ │ ├── Makefile.in │ │ ├── configure │ │ ├── include │ │ │ └── simple.h │ │ └── src │ │ │ └── simple.c │ └── testSimple.c ├── configure_with_bazel_transitive │ ├── BUILD.bazel │ ├── builtWithBazel.c │ ├── builtWithBazel.h │ ├── simple_lib │ │ ├── BUILD.bazel │ │ ├── Makefile.in │ │ ├── configure │ │ ├── include │ │ │ └── simple.h │ │ └── src │ │ │ └── simple.c │ └── testSimple.c ├── current_toolchains │ └── BUILD.bazel ├── deps │ ├── BUILD.bazel │ ├── apple_support.patch │ ├── deps_android.bzl │ ├── deps_jvm_external.bzl │ └── repositories.bzl ├── make_simple │ ├── BUILD.bazel │ ├── README.md │ ├── code │ │ ├── BUILD.bazel │ │ ├── Makefile │ │ ├── cxx_wrapper.sh │ │ ├── liba.cpp │ │ └── liba.h │ └── test_libb.cpp ├── meson_simple │ ├── BUILD.bazel │ ├── code │ │ ├── BUILD.bazel │ │ ├── clang_wrapper.sh │ │ ├── liba.cpp │ │ ├── liba.h │ │ └── meson.build │ ├── test_introspect.sh │ └── test_libb.cpp ├── ninja_simple │ ├── BUILD.bazel │ ├── README.md │ ├── code │ │ ├── BUILD.bazel │ │ ├── build.ninja │ │ ├── clang_wrapper.sh │ │ ├── liba.cpp │ │ └── liba.h │ └── test_libb.cpp ├── platform_mappings ├── requirements.txt ├── requirements_lock.txt ├── rust │ ├── BUILD.bazel │ ├── Cargo.Bazel.lock │ └── cargo-bazel-lock.json └── third_party │ ├── .bazelversion │ ├── .gitignore │ ├── BUILD.bazel │ ├── README.md │ ├── WORKSPACE.bazel │ ├── apr │ ├── BUILD.apr.bazel │ ├── BUILD.bazel │ ├── apr_repositories.bzl │ ├── macos_pid_t.patch │ └── windows_winnt.patch │ ├── apr_util │ ├── BUILD.apr_util.bazel │ ├── BUILD.bazel │ ├── BUILD.expat.bazel │ └── apr_util_repositories.bzl │ ├── autotools │ ├── BUILD.autoconf.bazel │ ├── BUILD.automake.bazel │ ├── BUILD.bazel │ ├── BUILD.libtool.bazel │ ├── BUILD.m4.bazel │ └── autotools_repositories.bzl │ ├── bison │ ├── BUILD.bazel │ ├── BUILD.bison.bazel │ └── bison_repositories.bzl │ ├── cares │ ├── BUILD.bazel │ ├── BUILD.cares.bazel │ ├── c-ares-test.cpp │ └── cares_repositories.bzl │ ├── curl │ ├── BUILD.bazel │ ├── BUILD.curl.bazel │ ├── curl_repositories.bzl │ └── curl_test.cc │ ├── glib │ ├── BUILD │ ├── BUILD.gettext.bazel │ ├── BUILD.gettext_win.bazel │ ├── BUILD.glib.bazel │ ├── BUILD.libffi.bazel │ └── glib_repositories.bzl │ ├── gn │ ├── BUILD.bazel │ ├── BUILD.gn.bazel │ ├── gn_repositories.bzl │ ├── gn_test.sh │ └── patch.gen_ninja.sh │ ├── gperftools │ ├── BUILD.bazel │ ├── BUILD.gperftools.bazel │ ├── gperftools_repositories.bzl │ └── malloc_test.cc │ ├── iconv │ ├── BUILD.bazel │ ├── BUILD.iconv.bazel │ ├── BUILD.iconv.macos.bazel │ └── iconv_repositories.bzl │ ├── libgit2 │ ├── BUILD.bazel │ ├── BUILD.libgit2.bazel │ └── libgit2_repositories.bzl │ ├── libjpeg_turbo │ ├── BUILD.bazel │ ├── BUILD.libjpeg_turbo.bazel │ └── libjpeg_turbo_repositories.bzl │ ├── libpng │ ├── BUILD.bazel │ ├── BUILD.libpng.bazel │ ├── bazel_icon_transparent.png │ ├── libpng_repositories.bzl │ ├── libpng_usage_example.cpp │ └── test_libpng.sh │ ├── libssh2 │ ├── BUILD.bazel │ ├── BUILD.libssh2.bazel │ └── libssh2_repositories.bzl │ ├── log4cxx │ ├── BUILD.bazel │ ├── BUILD.log4cxx.bazel │ ├── console.cpp.patch │ ├── inputstreamreader.cpp.patch │ ├── log4cxx_repositories.bzl │ ├── simpledateformat.h.patch │ └── socketoutputstream.cpp.patch │ ├── mesa │ ├── BUILD.bazel │ ├── BUILD.flex.bazel │ ├── BUILD.libdrm.bazel │ ├── BUILD.libpciaccess.bazel │ ├── BUILD.libpthread-stubs.bazel │ ├── BUILD.libx11.bazel │ ├── BUILD.libxau.bazel │ ├── BUILD.libxcb.bazel │ ├── BUILD.libxdmcp.bazel │ ├── BUILD.libxext.bazel │ ├── BUILD.libxfixes.bazel │ ├── BUILD.libxrandr.bazel │ ├── BUILD.libxrender.bazel │ ├── BUILD.libxshmfence.bazel │ ├── BUILD.mesa.bazel │ ├── BUILD.renderproto.bazel │ ├── BUILD.winflexbison.bazel │ ├── BUILD.xcb-proto.bazel │ ├── BUILD.xorgproto.bazel │ ├── BUILD.xtrans.bazel │ ├── mesa.meson.build.patch │ ├── mesa.patch │ ├── mesa.src_egl_meson.build.patch │ ├── mesa.src_gallium_frontends_dri_dri_util.c.patch │ ├── mesa.src_gallium_frontends_dri_meson.build.patch │ ├── mesa.src_gallium_targets_dri_meson.build.patch │ ├── mesa.src_gbm_meson.build.patch │ ├── mesa.src_glx_meson.build.patch │ ├── mesa.src_intel_vulkan_meson.build.patch │ ├── mesa.src_loader_meson.build.patch │ ├── mesa.src_vulkan_util_meson.build.patch │ └── mesa_repositories.bzl │ ├── openssl │ ├── BUILD.bazel │ ├── BUILD.nasm.bazel │ ├── BUILD.openssl.bazel │ ├── openssl_repositories.bzl │ ├── openssl_setup.bzl │ ├── openssl_test.cc │ └── openssl_test.sh │ ├── pcre │ ├── BUILD.bazel │ ├── BUILD.pcre.bazel │ └── pcre_repositories.bzl │ ├── python │ ├── BUILD.bazel │ ├── BUILD.python3.bazel │ └── python_repositories.bzl │ ├── repositories.bzl │ ├── setup.bzl │ ├── sqlite │ ├── BUILD.bazel │ ├── BUILD.sqlite.bazel │ └── sqlite_repositories.bzl │ ├── subversion │ ├── BUILD.bazel │ ├── BUILD.subversion.bazel │ └── subversion_repositories.bzl │ └── zlib │ ├── BUILD.bazel │ ├── BUILD.zlib.bazel │ ├── CMakeLists.txt │ ├── test_shared_zlib.sh │ ├── test_zlib.sh │ ├── zlib-example.cpp │ ├── zlib.patch │ └── zlib_repositories.bzl ├── foreign_cc ├── BUILD.bazel ├── boost_build.bzl ├── built_tools │ ├── BUILD.bazel │ ├── cmake_build.bzl │ ├── make_build.bzl │ ├── meson_build.bzl │ ├── ninja_build.bzl │ ├── pkgconfig_build.bzl │ └── private │ │ ├── BUILD.bazel │ │ └── built_tools_framework.bzl ├── cmake.bzl ├── configure.bzl ├── defs.bzl ├── extensions.bzl ├── make.bzl ├── meson.bzl ├── ninja.bzl ├── private │ ├── BUILD.bazel │ ├── cc_toolchain_util.bzl │ ├── cmake_script.bzl │ ├── configure_script.bzl │ ├── detect_root.bzl │ ├── detect_xcompile.bzl │ ├── framework.bzl │ ├── framework │ │ ├── BUILD.bazel │ │ ├── helpers.bzl │ │ ├── platform.bzl │ │ ├── toolchain.bzl │ │ └── toolchains │ │ │ ├── BUILD.bazel │ │ │ ├── access.bzl │ │ │ ├── commands.bzl │ │ │ ├── freebsd_commands.bzl │ │ │ ├── linux_commands.bzl │ │ │ ├── macos_commands.bzl │ │ │ ├── mappings.bzl │ │ │ └── windows_commands.bzl │ ├── make_env_vars.bzl │ ├── make_script.bzl │ ├── run_shell_file_utils.bzl │ ├── runnable_binary_wrapper.sh │ └── transitions.bzl ├── providers.bzl ├── repositories.bzl └── utils.bzl ├── test ├── BUILD.bazel ├── boostrap_tools │ └── BUILD.bazel ├── cmake_text_tests.bzl ├── convert_shell_script_test.bzl ├── detect_root_test │ ├── .bazelversion │ ├── BUILD.bazel │ ├── WORKSPACE.bazel │ ├── detect_root_test_rule.bzl │ ├── dir1 │ │ └── srcs │ │ │ └── input.txt │ └── expected │ │ ├── out_fg.txt │ │ ├── out_fg_srcs.txt │ │ └── out_repo.txt ├── dir1 │ └── include │ │ └── header1.h ├── dir2 │ └── include │ │ └── header2.h ├── expected │ ├── inner_fun_text.txt │ ├── inner_fun_text_freebsd.txt │ ├── inner_fun_text_macos.txt │ ├── out_symlinked_dirs.txt │ ├── out_symlinked_dirs_freebsd.txt │ └── out_symlinked_dirs_macos.txt ├── shell_script_helper_test_rule.bzl ├── standard_cxx_flags_test │ ├── .bazelrc │ ├── .bazelversion │ ├── BUILD.bazel │ ├── WORKSPACE.bazel │ └── tests.bzl ├── symlink_contents_to_dir_test_rule.bzl └── utils_test.bzl ├── toolchains ├── BUILD.bazel ├── README.md ├── built_toolchains.bzl ├── cmake_versions.bzl ├── native_tools │ ├── BUILD.bazel │ ├── native_tools_toolchain.bzl │ └── tool_access.bzl ├── patches │ ├── BUILD.bazel │ ├── README.md │ ├── cmake-c++11.patch │ ├── make-reproducible-bootstrap.patch │ ├── pkgconfig-builtin-glib-int-conversion.patch │ ├── pkgconfig-detectenv.patch │ └── pkgconfig-makefile-vc.patch ├── prebuilt_toolchains.bzl ├── prebuilt_toolchains.py ├── prebuilt_toolchains_repository.bzl ├── private │ └── BUILD.bazel └── toolchains.bzl ├── tools └── lint │ ├── BUILD.bazel │ └── linters.bzl └── version.bzl /.bazelci/windows-update-certs.ps1: -------------------------------------------------------------------------------- 1 | cd $env:USERPROFILE; 2 | Invoke-WebRequest https://curl.haxx.se/ca/cacert.pem -OutFile $env:USERPROFILE\cacert.pem; 3 | $plaintext_pw = 'PASSWORD'; 4 | $secure_pw = ConvertTo-SecureString $plaintext_pw -AsPlainText -Force; 5 | & openssl.exe pkcs12 -export -nokeys -out certs.pfx -in cacert.pem -passout pass:$plaintext_pw; 6 | Import-PfxCertificate -Password $secure_pw -CertStoreLocation Cert:\LocalMachine\Root -FilePath certs.pfx; 7 | -------------------------------------------------------------------------------- /.bazelignore: -------------------------------------------------------------------------------- 1 | docs 2 | examples 3 | test/standard_cxx_flags_test 4 | test/detect_root_test 5 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/.bazelrc -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /.bcr/config.yml: -------------------------------------------------------------------------------- 1 | fixedReleaser: 2 | login: jsharpe 3 | email: james.sharpe@zenotech.com 4 | -------------------------------------------------------------------------------- /.bcr/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazel-contrib/rules_foreign_cc", 3 | "maintainers": [ 4 | { 5 | "email": "james.sharpe@zenotech.com", 6 | "github": "jsharpe", 7 | "name": "James Sharpe" 8 | } 9 | ], 10 | "repository": ["github:bazel-contrib/rules_foreign_cc"], 11 | "versions": [], 12 | "yanked_versions": {} 13 | } 14 | -------------------------------------------------------------------------------- /.bcr/presubmit.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | platform: ["centos7", "debian10", "macos", "ubuntu2004", "windows"] 3 | bazel: ["7.x"] 4 | 5 | tasks: 6 | verify_targets: 7 | name: "Verify build targets" 8 | platform: ${{ platform }} 9 | bazel: ${{ bazel }} 10 | build_targets: 11 | - "@rules_foreign_cc//toolchains/private:make_tool" 12 | -------------------------------------------------------------------------------- /.bcr/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{VERSION}/{REPO}-{TAG}.tar.gz" 5 | } 6 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | IndentWidth: 4 4 | ... 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.bazel linguist-language=Starlark 2 | 3 | # TODO: remove once https://github.com/github-linguist/linguist/pull/7121 lands 4 | WORKSPACE.bzlmod linguist-language=Starlark 5 | 6 | # .bazelrc are mostly a collection of the CLI arguments, so highlighting them 7 | # as shell scripts looks quite alright and makes them quite readable 8 | .bazelrc linguist-language=Shell 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.bazelrc: -------------------------------------------------------------------------------- 1 | # This file contains Bazel settings to apply on release CI only. 2 | # It is referenced with a --bazelrc option in the call to bazel in ci.yaml 3 | 4 | # Don't rely on test logs being easily accessible from the test runner, 5 | # though it makes the log noisier. 6 | test --test_output=errors 7 | # Allows tests to run bazelisk-in-bazel, since this is the cache folder used 8 | test --test_env=XDG_CACHE_HOME 9 | -------------------------------------------------------------------------------- /.github/workflows/docs.yaml: -------------------------------------------------------------------------------- 1 | name: Docs-CI/CD 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | docs: 10 | name: Docs 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@master 14 | - name: Run tests 15 | run: bazel run --compilation_mode=opt --stamp //:publish_book 16 | working-directory: docs 17 | - name: Deploy to GitHub Pages 18 | uses: JamesIves/github-pages-deploy-action@4.1.7 19 | with: 20 | branch: docs # The branch the action should deploy to. 21 | folder: docs/book # The folder the action should deploy. 22 | -------------------------------------------------------------------------------- /.github/workflows/formatting.yaml: -------------------------------------------------------------------------------- 1 | name: Formatting 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | types: 9 | - opened 10 | - synchronize 11 | 12 | jobs: 13 | code-format-checks: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: DoozyX/clang-format-lint-action@v0.14 18 | with: 19 | source: '.' 20 | extensions: 'h,c,cc,cpp,proto,java' 21 | clangFormatVersion: 14 22 | - name: Set up Python 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: 3.11 26 | - name: Install dependencies 27 | run: | 28 | pip install 'black==24.10.0' 'isort==5.13.2' 29 | - name: Run black 30 | run: | 31 | python -m black --check --diff ./ 32 | - name: Run isort 33 | run: | 34 | python -m isort --profile=black --check-only ./ 35 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # Cut a release whenever a new tag is pushed to the repo. 2 | # You should use an annotated tag, like `git tag -a v1.2.3` 3 | # and put the release notes into the commit message for the tag. 4 | name: Release 5 | 6 | on: 7 | push: 8 | tags: 9 | - "*.*.*" 10 | 11 | permissions: 12 | contents: write 13 | 14 | jobs: 15 | release: 16 | uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v6 17 | with: 18 | release_files: rules_foreign_cc-*.tar.gz 19 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See CONTRIBUTING.md for instructions. 2 | # See https://pre-commit.com for more information 3 | # See https://pre-commit.com/hooks.html for more hooks 4 | exclude: >- 5 | (?x)^( 6 | bazel-.*/.* 7 | |.*\.patch 8 | |.*\.diff 9 | |test/(expected|.*/expected)/.*\.txt 10 | |examples/(?!.*CMakeLists\.txt$).*\.txt 11 | )$ 12 | 13 | repos: 14 | - repo: https://github.com/pre-commit/pre-commit-hooks 15 | rev: v5.0.0 16 | hooks: 17 | - id: check-merge-conflict 18 | - id: mixed-line-ending 19 | - id: trailing-whitespace 20 | - id: end-of-file-fixer 21 | - id: check-yaml 22 | 23 | - repo: https://github.com/keith/pre-commit-buildifier 24 | rev: 7.3.1.1 25 | hooks: 26 | - id: buildifier 27 | args: &args 28 | # Keep this argument in sync with .bazelci/config.yaml 29 | - --warnings=all 30 | - id: buildifier-lint 31 | args: *args 32 | 33 | - repo: https://github.com/mpalmer/action-validator 34 | rev: v0.6.0 35 | hooks: 36 | - id: action-validator 37 | 38 | - repo: https://github.com/rhysd/actionlint 39 | rev: v1.7.4 40 | hooks: 41 | - id: actionlint 42 | 43 | - repo: https://github.com/mrtazz/checkmake.git 44 | rev: 0.2.2 45 | hooks: 46 | - id: checkmake 47 | 48 | - repo: https://github.com/shellcheck-py/shellcheck-py 49 | rev: v0.10.0.1 50 | hooks: 51 | - id: shellcheck 52 | exclude: >- 53 | (?x)^( 54 | examples/.* 55 | )$ 56 | -------------------------------------------------------------------------------- /.shellcheckrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/.shellcheckrc -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the list of Bazel authors for copyright purposes. 2 | # 3 | # This does not necessarily list everyone who has contributed code, since in 4 | # some cases, their employer may be the copyright holder. To see the full list 5 | # of contributors, see the revision history in source control. 6 | Google Inc. 7 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") 2 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 3 | 4 | exports_files( 5 | [".shellcheckrc"], 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | gazelle( 10 | name = "gazelle", 11 | gazelle = ":gazelle_bin", 12 | ) 13 | 14 | gazelle_binary( 15 | name = "gazelle_bin", 16 | languages = DEFAULT_LANGUAGES + [ 17 | "@bazel_skylib_gazelle_plugin//bzl", 18 | ], 19 | ) 20 | 21 | bzl_library( 22 | name = "version", 23 | srcs = ["version.bzl"], 24 | visibility = ["//visibility:public"], 25 | ) 26 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | #* @irengrig 2 | #* @oquenchil 3 | -------------------------------------------------------------------------------- /WORKSPACE.bzlmod: -------------------------------------------------------------------------------- 1 | workspace(name = "rules_foreign_cc") 2 | 3 | load("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig") 4 | 5 | # Creates a default toolchain config for RBE. 6 | # Use this as is if you are using the rbe_ubuntu16_04 container, 7 | # otherwise refer to RBE docs. 8 | rbe_preconfig( 9 | name = "buildkite_config", 10 | toolchain = "ubuntu1804-bazel-java11", 11 | ) 12 | -------------------------------------------------------------------------------- /docs/.bazelrc: -------------------------------------------------------------------------------- 1 | # Bazel configuration flags for rules_foreign_cc_docs 2 | 3 | # https://github.com/bazelbuild/stardoc/issues/112 4 | common --incompatible_allow_tags_propagation 5 | -------------------------------------------------------------------------------- /docs/.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | book 2 | -------------------------------------------------------------------------------- /docs/MODULE.bazel: -------------------------------------------------------------------------------- 1 | """rules_foreign_cc docs""" 2 | 3 | module( 4 | name = "rules_foreign_cc_docs", 5 | version = "0.0.0", 6 | ) 7 | 8 | bazel_dep(name = "rules_foreign_cc", version = "0.0.0") 9 | local_path_override( 10 | module_name = "rules_foreign_cc", 11 | path = "..", 12 | ) 13 | 14 | bazel_dep( 15 | name = "rules_rust_mdbook", 16 | version = "0.56.0", 17 | ) 18 | bazel_dep( 19 | name = "bazel_skylib", 20 | version = "1.7.1", 21 | ) 22 | bazel_dep( 23 | name = "stardoc", 24 | version = "0.7.2", 25 | repo_name = "io_bazel_stardoc", 26 | ) 27 | bazel_dep( 28 | name = "rules_shell", 29 | version = "0.3.0", 30 | ) 31 | bazel_dep( 32 | name = "rules_python", 33 | version = "1.2.0", 34 | ) 35 | bazel_dep( 36 | name = "protobuf", 37 | version = "29.3", 38 | repo_name = "com_google_protobuf", 39 | ) 40 | -------------------------------------------------------------------------------- /docs/WORKSPACE.bazel: -------------------------------------------------------------------------------- 1 | workspace(name = "rules_foreign_cc_docs") 2 | -------------------------------------------------------------------------------- /docs/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | title = "Rules ForeignCc" 3 | 4 | [output.html] 5 | git-repository-url = "https://github.com/bazel-contrib/rules_foreign_cc" 6 | -------------------------------------------------------------------------------- /docs/publish_book.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | cp -r "${BOOK_DIR}" "${BUILD_WORKSPACE_DIRECTORY}/book" 6 | -------------------------------------------------------------------------------- /docs/src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | - [Rules ForeignCc](index.md) 4 | - [Rules](rules.md) 5 | - [cmake](cmake.md) 6 | - [configure_make](configure_make.md) 7 | - [make](make.md) 8 | - [meson](meson.md) 9 | - [ninja](ninja.md) 10 | -------------------------------------------------------------------------------- /docs/src/rules.md: -------------------------------------------------------------------------------- 1 | # Rules 2 | 3 | - [cmake](./cmake.md) 4 | - [configure_make](./configure_make.md) 5 | - [make](./make.md) 6 | - [meson](./meson.md) 7 | - [ninja](./ninja.md) 8 | 9 | For additional rules/macros/providers, see the [full API in one page](./flatten.md). 10 | -------------------------------------------------------------------------------- /docs/stardoc_deps.bzl: -------------------------------------------------------------------------------- 1 | """A wrapper for defining stardoc dependencies to make instantiating 2 | it in a WORKSPACE file more consistent 3 | """ 4 | 5 | load("@io_bazel_stardoc//:setup.bzl", _stardoc_repositories = "stardoc_repositories") 6 | 7 | stardoc_deps = _stardoc_repositories 8 | -------------------------------------------------------------------------------- /docs/stardoc_repository.bzl: -------------------------------------------------------------------------------- 1 | """A module for defining the stardoc repository""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def stardoc_repository(): 7 | maybe( 8 | http_archive, 9 | name = "io_bazel_stardoc", 10 | sha256 = "3fd8fec4ddec3c670bd810904e2e33170bedfe12f90adf943508184be458c8bb", 11 | urls = [ 12 | "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz", 13 | "https://github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz", 14 | ], 15 | ) 16 | -------------------------------------------------------------------------------- /examples/.bazelignore: -------------------------------------------------------------------------------- 1 | cmake_crosstool 2 | third_party 3 | -------------------------------------------------------------------------------- /examples/.bazelrc: -------------------------------------------------------------------------------- 1 | build --enable_platform_specific_config 2 | 3 | # Required by Meson on Windows 4 | build:windows --action_env=PROCESSOR_ARCHITECTURE 5 | build:windows --action_env=USERPROFILE 6 | 7 | # Required when using the built meson toolchain on windows 8 | build:windows --nobuild_python_zip 9 | 10 | # Required by Meson and built pkg-config on Windows 11 | build:windows --enable_runfiles 12 | 13 | # These are required otherwise paths are too long 14 | startup --windows_enable_symlinks 15 | build:windows --action_env=MSYS=winsymlinks:nativestrict 16 | test:windows --action_env=MSYS=winsymlinks:nativestrict 17 | 18 | # Enable CC toolchain that supports iOS from https://github.com/bazelbuild/apple_support 19 | build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain 20 | build:macos --crosstool_top=@local_config_apple_cc//:toolchain 21 | build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain 22 | -------------------------------------------------------------------------------- /examples/.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /examples/WORKSPACE.bzlmod: -------------------------------------------------------------------------------- 1 | workspace(name = "rules_foreign_cc_examples") 2 | 3 | load("//deps:repositories.bzl", "repositories") 4 | 5 | repositories() 6 | 7 | load("//deps:deps_android.bzl", "deps_android") 8 | 9 | deps_android() 10 | 11 | load("//deps:deps_jvm_external.bzl", "deps_jvm_external") 12 | 13 | deps_jvm_external() 14 | 15 | local_repository( 16 | name = "rules_foreign_cc_examples_third_party", 17 | path = "third_party", 18 | ) 19 | 20 | load("@rules_foreign_cc_examples_third_party//:repositories.bzl", examples_third_party_repositories = "repositories") 21 | 22 | examples_third_party_repositories() 23 | 24 | load("@rules_foreign_cc_examples_third_party//:setup.bzl", examples_third_party_setup = "setup") 25 | 26 | examples_third_party_setup() 27 | 28 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 29 | 30 | http_archive( 31 | name = "bazelci_rules", 32 | sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e", 33 | strip_prefix = "bazelci_rules-1.0.0", 34 | url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz", 35 | ) 36 | 37 | load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig") 38 | 39 | # Creates a default toolchain config for RBE. 40 | # Use this as is if you are using the rbe_ubuntu16_04 container, 41 | # otherwise refer to RBE docs. 42 | rbe_preconfig( 43 | name = "buildkite_config", 44 | toolchain = "ubuntu1804-bazel-java11", 45 | ) 46 | -------------------------------------------------------------------------------- /examples/cmake_android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/cmake_android/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_android//android:rules.bzl", "android_binary", "android_library") 2 | load("@rules_cc//cc:defs.bzl", "cc_library") 3 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 4 | 5 | cmake( 6 | name = "libhello", 7 | lib_source = "//cmake_hello_world_lib/static:srcs", 8 | out_include_dir = "include/version123", 9 | ) 10 | 11 | cc_library( 12 | name = "hello_lib_usage_example", 13 | srcs = ["hello_lib-example.cpp"], 14 | linkstatic = True, 15 | deps = [":libhello"], 16 | alwayslink = True, 17 | ) 18 | 19 | android_library( 20 | name = "lib", 21 | srcs = ["java/com/example/android/bazel/MainActivity.java"], 22 | custom_package = "com.example.android.bazel", 23 | manifest = "LibraryManifest.xml", 24 | resource_files = glob(["res/**/*"]), 25 | deps = [ 26 | ":hello_lib_usage_example", 27 | "@maven//:com_android_support_appcompat_v7", 28 | "@maven//:com_android_support_constraint_constraint_layout", 29 | ], 30 | ) 31 | 32 | android_binary( 33 | name = "app", 34 | custom_package = "com.example.android.bazel", 35 | manifest = "AndroidManifest.xml", 36 | deps = [":lib"], 37 | ) 38 | -------------------------------------------------------------------------------- /examples/cmake_android/LibraryManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/cmake_android/cpp/native-lib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | extern "C" JNIEXPORT jstring 6 | 7 | JNICALL 8 | Java_com_example_android_bazel_MainActivity_stringFromJNI( 9 | JNIEnv *env, jobject /* this */) { 10 | std::string hello = "Hello from C++"; 11 | return env->NewStringUTF(hello.c_str()); 12 | } 13 | -------------------------------------------------------------------------------- /examples/cmake_android/hello_lib-example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "hello.h" 4 | 5 | int main(int argc, char* argv[]) { 6 | hello_func(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /examples/cmake_android/java/com/example/android/bazel/MainActivity.java: -------------------------------------------------------------------------------- 1 | package examples.cmake_android.java.com.example.android.bazel; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | 7 | public class MainActivity extends AppCompatActivity { 8 | static { 9 | System.loadLibrary("app"); 10 | } 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | // setContentView(R.layout.activity_main); 16 | // 17 | // // Example of a call to a native method 18 | // TextView tv = (TextView) findViewById(R.id.sample_text); 19 | // tv.setText(stringFromJNI()); 20 | } 21 | 22 | /** 23 | * A native method that is implemented by the 'native-lib' native library, 24 | * which is packaged with this application. 25 | */ 26 | public native String stringFromJNI(); 27 | } 28 | -------------------------------------------------------------------------------- /examples/cmake_android/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/cmake_android/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_android/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/cmake_android/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /examples/cmake_android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Built By Bazel 3 | 4 | -------------------------------------------------------------------------------- /examples/cmake_android/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/.bazelrc: -------------------------------------------------------------------------------- 1 | build --crosstool_top=//tools/arm_compiler:toolchain --cpu=armeabi-v7a --spawn_strategy=standalone --experimental_cc_skylark_api_enabled_packages=@rules_foreign_cc//tools/build_defs,tools/build_defs,@foreign_cc_impl 2 | test --crosstool_top=//tools/arm_compiler:toolchain --cpu=armeabi-v7a --spawn_strategy=standalone --experimental_cc_skylark_api_enabled_packages=@rules_foreign_cc//tools/build_defs,tools/build_defs,@foreign_cc_impl 3 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 3 | 4 | filegroup( 5 | name = "srcs", 6 | srcs = glob(["**"]), 7 | visibility = ["//src/test/shell/bazel/testdata:__pkg__"], 8 | ) 9 | 10 | cc_library( 11 | name = "hello", 12 | srcs = ["hello.cc"], 13 | ) 14 | 15 | cmake( 16 | name = "hello_cmake", 17 | lib_source = "//static:srcs", 18 | out_include_dir = "include/version123", 19 | out_static_libs = ["libhello.a"], 20 | ) 21 | 22 | # I do not make it a test, since it is a cross-compilation example, 23 | # requires test that just checks something about output 24 | cc_binary( 25 | name = "libhello_test", 26 | # includes just hello.h, include directory: "include/version123" 27 | srcs = ["//static:hello_client.c"], 28 | deps = [":hello_cmake"], 29 | ) 30 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/WORKSPACE.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 2 | 3 | http_archive( 4 | name = "org_linaro_components_toolchain_gcc_5_3_1", 5 | build_file = Label("//:compilers/BUILD.linaro_linux_gcc_5.3.1.bazel"), 6 | strip_prefix = "gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf", 7 | url = "https://bazel-mirror.storage.googleapis.com/releases.linaro.org/components/toolchain/binaries/latest-5/arm-linux-gnueabihf/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf.tar.xz", 8 | ) 9 | 10 | local_repository( 11 | name = "rules_foreign_cc", 12 | path = "../..", 13 | ) 14 | 15 | load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") 16 | 17 | rules_foreign_cc_dependencies() 18 | 19 | load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") 20 | 21 | bazel_skylib_workspace() 22 | 23 | local_repository( 24 | name = "cmake_hello_world_lib", 25 | path = "../cmake_hello_world_lib/static", 26 | ) 27 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/hello.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Bazel Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | int main(int argc, char* argv[]) { 21 | std::cout << "Hello! sqrt(time) = " << std::sqrt(time(NULL)) << std::endl; 22 | return EXIT_SUCCESS; 23 | } 24 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/static/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 2.8.4) 5 | 6 | project(hellolib) 7 | 8 | add_subdirectory(src) 9 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/static/hello_client.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | hello_func(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/static/hello_client_version123.c: -------------------------------------------------------------------------------- 1 | #include "version123/hello.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | hello_func(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/static/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 2.8.4) 5 | 6 | set(LIBHELLO_SRC hello.c) 7 | 8 | add_library(hello_static STATIC ${LIBHELLO_SRC}) 9 | 10 | set_target_properties(hello_static PROPERTIES OUTPUT_NAME "hello") 11 | 12 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 13 | 14 | install(TARGETS hello_static ARCHIVE DESTINATION lib) 15 | 16 | install(FILES hello.h DESTINATION include/version123) 17 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/static/src/hello.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | void hello_func(void) { 4 | printf("Hello World!\n"); 5 | 6 | return; 7 | } 8 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/static/src/hello.h: -------------------------------------------------------------------------------- 1 | #ifndef HELLO_H_ 2 | #define HELLO_H_ (1) 3 | 4 | #include 5 | 6 | void hello_func(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/static/test_hello.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | $(rlocation rules_foreign_cc/examples/cmake_hello_world_lib/$1) 4 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ar: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | if [[ -z "${EXT_BUILD_ROOT}" ]]; then 4 | MY_PREFIX="" 5 | else 6 | MY_PREFIX="${EXT_BUILD_ROOT}/" 7 | fi 8 | 9 | exec -a arm-linux-gnueabihf-ar \ 10 | ${MY_PREFIX}external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-ar \ 11 | "$@" 12 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-as: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-as \ 4 | external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-as \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | if [[ -z "${EXT_BUILD_ROOT}" ]]; then 4 | MY_PREFIX="" 5 | else 6 | MY_PREFIX="${EXT_BUILD_ROOT}/" 7 | fi 8 | 9 | PATH="${MY_PREFIX}external/org_linaro_components_toolchain_gcc_5_3_1/libexec/gcc/arm-linux-gnueabihf/4.9.3:$PATH" \ 10 | exec \ 11 | ${MY_PREFIX}external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-gcc \ 12 | "$@" 13 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ld: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-ld \ 4 | external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-ld \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-nm: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-nm \ 4 | external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-nm \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objcopy: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-objcopy \ 4 | external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-objcopy \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objdump: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-objdump \ 4 | external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-objdump \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-strip: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-strip \ 4 | external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-strip \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /examples/cmake_defines/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | cmake( 4 | name = "lib_a", 5 | lib_source = ":lib_a_sources", 6 | out_static_libs = select({ 7 | "//:windows": ["lib_a.lib"], 8 | "//conditions:default": ["liblib_a.a"], 9 | }), 10 | deps = [":lib_b"], 11 | ) 12 | 13 | cmake( 14 | name = "lib_b", 15 | defines = ["FOO"], 16 | lib_source = ":lib_b_sources", 17 | out_static_libs = select({ 18 | "//:windows": ["lib_b.lib"], 19 | "//conditions:default": ["liblib_b.a"], 20 | }), 21 | ) 22 | 23 | filegroup( 24 | name = "lib_a_sources", 25 | srcs = ["lib_a/{}".format(s) for s in [ 26 | "CMakeLists.txt", 27 | "lib_a.cpp", 28 | ]], 29 | visibility = ["//cmake_defines:__subpackages__"], 30 | ) 31 | 32 | filegroup( 33 | name = "lib_b_sources", 34 | srcs = ["lib_b/{}".format(s) for s in [ 35 | "CMakeLists.txt", 36 | "lib_b.cpp", 37 | ]], 38 | visibility = ["//cmake_defines:__subpackages__"], 39 | ) 40 | -------------------------------------------------------------------------------- /examples/cmake_defines/lib_a/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(cmake_defines) 2 | 3 | add_library(lib_a lib_a.cpp) 4 | install(TARGETS lib_a ARCHIVE DESTINATION lib) 5 | -------------------------------------------------------------------------------- /examples/cmake_defines/lib_a/lib_a.cpp: -------------------------------------------------------------------------------- 1 | #ifndef FOO 2 | #error FOO is not defined 3 | #endif 4 | 5 | #define XSTR(x) STR(x) 6 | #define STR(x) #x 7 | #pragma message "The value of __TIME__: " XSTR(__TIME__) 8 | 9 | #define STATIC_ASSERT(condition, name) \ 10 | typedef char assert_failed_##name[(condition) ? 1 : -1]; 11 | 12 | void foo() { STATIC_ASSERT(__TIME__ == "redacted", time_must_be_redacted); } 13 | 14 | // Should return "redacted" 15 | const char *getBuildTime(void) { return __TIME__; } 16 | -------------------------------------------------------------------------------- /examples/cmake_defines/lib_b/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(cmake_defines) 2 | 3 | add_library(lib_b lib_b.cpp) 4 | install(TARGETS lib_b ARCHIVE DESTINATION lib) 5 | -------------------------------------------------------------------------------- /examples/cmake_defines/lib_b/lib_b.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/cmake_defines/lib_b/lib_b.cpp -------------------------------------------------------------------------------- /examples/cmake_defines/nocrosstool/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | cmake( 4 | name = "lib_a", 5 | generate_crosstool_file = False, 6 | lib_source = "//cmake_defines:lib_a_sources", 7 | out_static_libs = select({ 8 | "//:windows": ["lib_a.lib"], 9 | "//conditions:default": ["liblib_a.a"], 10 | }), 11 | deps = [":lib_b"], 12 | ) 13 | 14 | cmake( 15 | name = "lib_b", 16 | defines = ["FOO"], 17 | generate_crosstool_file = False, 18 | lib_source = "//cmake_defines:lib_b_sources", 19 | out_static_libs = select({ 20 | "//:windows": ["lib_b.lib"], 21 | "//conditions:default": ["liblib_b.a"], 22 | }), 23 | ) 24 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/binary/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | load("@bazel_tools//tools/build_rules:test_rules.bzl", "file_test") 4 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 5 | 6 | filegroup( 7 | name = "srcs", 8 | srcs = glob(["**"]), 9 | visibility = ["//visibility:public"], 10 | ) 11 | 12 | cmake( 13 | name = "libhello", 14 | # Probably this variable should be set by default. 15 | # Apparently, it needs to be set for shared libraries on Mac OS 16 | cache_entries = { 17 | "CMAKE_MACOSX_RPATH": "True", 18 | }, 19 | lib_source = ":srcs", 20 | out_binaries = select({ 21 | "//:windows": ["hello.exe"], 22 | "//conditions:default": ["hello"], 23 | }), 24 | ) 25 | 26 | filegroup( 27 | name = "binary", 28 | srcs = [":libhello"], 29 | output_group = select({ 30 | "//:windows": "hello.exe", 31 | "//conditions:default": "hello", 32 | }), 33 | ) 34 | 35 | genrule( 36 | name = "call_hello", 37 | srcs = [], 38 | outs = ["out.txt"], 39 | cmd = "./$(location :binary) me > $(location out.txt)", 40 | tools = [":binary"], 41 | ) 42 | 43 | file_test( 44 | name = "test_binary", 45 | content = "Hello, me!", 46 | file = ":call_hello", 47 | ) 48 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/binary/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 2.8.4) 5 | 6 | project(hellolib LANGUAGES C) 7 | 8 | add_subdirectory(src) 9 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/binary/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 2.8.4) 5 | 6 | add_library(hello_lib STATIC hello.c hello.h) 7 | 8 | IF (WIN32) 9 | set(LIB_NAME "libhello") 10 | ELSE() 11 | set(LIB_NAME "hello") 12 | ENDIF() 13 | 14 | set_target_properties(hello_lib PROPERTIES 15 | OUTPUT_NAME ${LIB_NAME} 16 | ) 17 | 18 | add_executable(myapp main.c) 19 | target_link_libraries(myapp hello_lib) 20 | target_include_directories(myapp PUBLIC 21 | $ 22 | ) 23 | set_target_properties(myapp PROPERTIES 24 | OUTPUT_NAME hello 25 | ) 26 | 27 | install( 28 | TARGETS 29 | hello_lib 30 | ARCHIVE DESTINATION lib 31 | ) 32 | 33 | install( 34 | TARGETS myapp DESTINATION bin 35 | ) 36 | 37 | install(FILES hello.h DESTINATION include) 38 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/binary/src/hello.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | void hello_func(char* name) { printf("Hello, %s!", name); } 4 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/binary/src/hello.h: -------------------------------------------------------------------------------- 1 | #ifndef HELLO_H_ 2 | #define HELLO_H_ (1) 3 | 4 | #include 5 | 6 | void hello_func(char*); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/binary/src/main.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | hello_func(argv[1]); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/shared/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | load("@rules_cc//cc:defs.bzl", "cc_test") 5 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 6 | 7 | filegroup( 8 | name = "srcs", 9 | srcs = glob(["**"]), 10 | visibility = ["//visibility:public"], 11 | ) 12 | 13 | cmake( 14 | name = "libhello", 15 | # Probably this variable should be set by default. 16 | # Apparently, it needs to be set for shared libraries on Mac OS 17 | cache_entries = { 18 | "CMAKE_MACOSX_RPATH": "True", 19 | }, 20 | lib_source = ":srcs", 21 | out_interface_libs = select({ 22 | "//:windows": ["libhello.lib"], 23 | "//conditions:default": [], 24 | }), 25 | out_shared_libs = select({ 26 | "//:macos": ["libhello.dylib"], 27 | "//:windows": ["libhello.dll"], 28 | "//conditions:default": ["libhello.so"], 29 | }), 30 | ) 31 | 32 | cc_test( 33 | name = "test_libhello", 34 | srcs = ["hello_client.c"], 35 | deps = [":libhello"], 36 | ) 37 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/shared/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 2.8.4) 5 | 6 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 7 | 8 | project(hellolib LANGUAGES C) 9 | 10 | add_subdirectory(src) 11 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/shared/hello_client.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | hello_func(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/shared/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 2.8.4) 5 | 6 | add_library(hello_shared SHARED hello.c hello.h) 7 | 8 | IF (WIN32) 9 | set(LIB_NAME "libhello") 10 | ELSE() 11 | set(LIB_NAME "hello") 12 | ENDIF() 13 | 14 | set_target_properties(hello_shared PROPERTIES 15 | OUTPUT_NAME ${LIB_NAME} 16 | ) 17 | 18 | install( 19 | TARGETS 20 | hello_shared 21 | LIBRARY DESTINATION lib 22 | ) 23 | 24 | install(FILES hello.h DESTINATION include) 25 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/shared/src/hello.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | void hello_func(void) { 4 | printf("Hello World!\n"); 5 | 6 | return; 7 | } 8 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/shared/src/hello.h: -------------------------------------------------------------------------------- 1 | #ifndef HELLO_H_ 2 | #define HELLO_H_ (1) 3 | 4 | #include 5 | 6 | void hello_func(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/static/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 2.8.4) 5 | 6 | project(hellolib) 7 | 8 | add_subdirectory(src) 9 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/static/hello_client.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | hello_func(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/static/hello_client_version123.c: -------------------------------------------------------------------------------- 1 | #include "version123/hello.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | hello_func(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/static/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib 2 | # for test only 3 | 4 | cmake_minimum_required(VERSION 3.5.0) 5 | 6 | set(LIBHELLO_SRC hello.c) 7 | 8 | add_library(hello_static STATIC ${LIBHELLO_SRC}) 9 | 10 | if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") 11 | set_target_properties(hello_static PROPERTIES OUTPUT_NAME "libhello") 12 | else() 13 | set_target_properties(hello_static PROPERTIES OUTPUT_NAME "hello") 14 | endif() 15 | 16 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 17 | 18 | install(TARGETS hello_static ARCHIVE DESTINATION lib) 19 | 20 | install(FILES hello.h DESTINATION include/version123) 21 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/static/src/hello.c: -------------------------------------------------------------------------------- 1 | #include "hello.h" 2 | 3 | void hello_func(void) { 4 | printf("Hello World!\n"); 5 | 6 | return; 7 | } 8 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/static/src/hello.h: -------------------------------------------------------------------------------- 1 | #ifndef HELLO_H_ 2 | #define HELLO_H_ (1) 3 | 4 | #include 5 | 6 | void hello_func(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /examples/cmake_hello_world_lib/static/test_hello.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # --- begin runfiles.bash initialization --- 4 | # The runfiles library itself defines rlocation which you would need to look 5 | # up the library's runtime location, thus we have a chicken-and-egg problem. 6 | # 7 | # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). 8 | set -euo pipefail 9 | if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 10 | if [[ -f "$0.runfiles_manifest" ]]; then 11 | export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" 12 | elif [[ -f "$0.runfiles/MANIFEST" ]]; then 13 | export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" 14 | elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 15 | export RUNFILES_DIR="$0.runfiles" 16 | fi 17 | fi 18 | if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 19 | source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" 20 | elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 21 | source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ 22 | "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" 23 | else 24 | echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" 25 | exit 1 26 | fi 27 | # --- end runfiles.bash initialization --- 28 | 29 | $(rlocation $TEST_WORKSPACE/$1) 30 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | load("@rules_cc//cc:defs.bzl", "cc_test") 3 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 4 | 5 | cmake( 6 | name = "liba", 7 | generate_args = ["-GNinja"], 8 | # Demonstrate non-alphanumeric name 9 | lib_name = "liba++", 10 | lib_source = "//cmake_synthetic/liba:a_srcs", 11 | postfix_script = "cp -p $$INSTALLDIR/lib/liba.a $$INSTALLDIR/lib/liba++.a", 12 | ) 13 | 14 | cmake( 15 | name = "libb", 16 | generate_args = ["-GNinja"], 17 | lib_source = "//cmake_synthetic/libb:b_srcs", 18 | deps = [":liba"], 19 | ) 20 | 21 | cmake( 22 | name = "lib_with_duplicate_transitive_bazel_deps", 23 | cache_entries = { 24 | "LIBA_DIR": "$$EXT_BUILD_DEPS", 25 | "LIBB_DIR": "$$EXT_BUILD_DEPS", 26 | }, 27 | generate_args = ["-GNinja"], 28 | lib_name = "libc", 29 | lib_source = "//cmake_synthetic/libc:c_srcs", 30 | deps = [ 31 | "//cmake_synthetic/liba:lib_a_bazel", 32 | "//cmake_synthetic/libb:lib_b_bazel", 33 | ], 34 | ) 35 | 36 | build_test( 37 | name = "test_bazel_transitive_deps", 38 | targets = [":lib_with_duplicate_transitive_bazel_deps"], 39 | ) 40 | 41 | cc_test( 42 | name = "test_libs", 43 | srcs = [ 44 | "test_libb.cpp", 45 | ], 46 | deps = [ 47 | # liba should come from transitive dependencies 48 | ":libb", 49 | ], 50 | ) 51 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/liba/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_library") 2 | 3 | filegroup( 4 | name = "a_srcs", 5 | srcs = glob(["**"]), 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | cc_library( 10 | name = "lib_a_bazel", 11 | srcs = ["src/liba.cpp"], 12 | hdrs = ["src/liba.h"], 13 | includes = ["src"], 14 | visibility = ["//visibility:public"], 15 | ) 16 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/liba/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | project(liba) 4 | 5 | add_subdirectory(src) 6 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/liba/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | set(LIBA_SRC liba.cpp liba.h) 4 | 5 | add_library(liba_static STATIC ${LIBA_SRC}) 6 | 7 | set_target_properties(liba_static PROPERTIES OUTPUT_NAME "liba") 8 | IF (WIN32) 9 | set_target_properties(liba_static PROPERTIES ARCHIVE_OUTPUT_NAME "liba") 10 | ELSE() 11 | set_target_properties(liba_static PROPERTIES ARCHIVE_OUTPUT_NAME "a") 12 | ENDIF() 13 | set_target_properties(liba_static PROPERTIES PUBLIC_HEADER "liba.h") 14 | 15 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 16 | 17 | install(FILES liba.h DESTINATION include) 18 | 19 | install(TARGETS liba_static 20 | EXPORT liba_targets 21 | ARCHIVE DESTINATION lib 22 | INCLUDES DESTINATION include 23 | PUBLIC_HEADER DESTINATION include 24 | ) 25 | target_include_directories(liba_static INTERFACE 26 | $ 27 | ) 28 | 29 | install(EXPORT liba_targets 30 | DESTINATION lib/cmake/liba 31 | FILE liba-config.cmake) 32 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/liba/src/liba.cpp: -------------------------------------------------------------------------------- 1 | #include "liba.h" 2 | 3 | std::string hello_liba(void) { return "Hello from LIBA!"; } 4 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/liba/src/liba.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBA_H_ 2 | #define LIBA_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | std::string hello_liba(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libb/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_library") 2 | 3 | filegroup( 4 | name = "b_srcs", 5 | srcs = glob(["**"]), 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | cc_library( 10 | name = "lib_b_bazel", 11 | srcs = ["src/libb.cpp"], 12 | hdrs = ["src/libb.h"], 13 | includes = ["src"], 14 | visibility = ["//visibility:public"], 15 | deps = ["//cmake_synthetic/liba:lib_a_bazel"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | project(libb) 4 | 5 | add_subdirectory(src) 6 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libb/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | set(LIBB_SRC libb.cpp libb.h) 4 | 5 | add_library(libb_static STATIC ${LIBB_SRC}) 6 | set_target_properties(libb_static PROPERTIES OUTPUT_NAME "libb") 7 | IF (WIN32) 8 | set_target_properties(libb_static PROPERTIES ARCHIVE_OUTPUT_NAME "libb") 9 | ELSE() 10 | set_target_properties(libb_static PROPERTIES ARCHIVE_OUTPUT_NAME "b") 11 | ENDIF() 12 | 13 | find_package(LIBA REQUIRED NAMES alib liba libliba) 14 | 15 | # LIBA_INCLUDE_DIRS is not set, so giving the path relative to liba_config.cmake 16 | # would be happy to improve that 17 | target_link_libraries(libb_static PUBLIC ${LIBA_DIR}/../../../lib/liba.a) 18 | target_include_directories(libb_static PUBLIC ${LIBA_DIR}/../../../include) 19 | 20 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 21 | 22 | install(TARGETS libb_static ARCHIVE DESTINATION lib) 23 | 24 | install(FILES libb.h DESTINATION include) 25 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libb/src/libb.cpp: -------------------------------------------------------------------------------- 1 | #include "libb.h" 2 | 3 | std::string hello_libb(void) { return hello_liba() + " Hello from LIBB!"; } 4 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libb/src/libb.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBB_H_ 2 | #define LIBB_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "liba.h" 9 | 10 | std::string hello_libb(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libc/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "c_srcs", 3 | srcs = glob(["**"]), 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | project(libc) 4 | 5 | add_subdirectory(src) 6 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libc/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | set(libc_SRC libc.cpp libc.h) 4 | 5 | add_library(libc_static STATIC ${libc_SRC}) 6 | set_target_properties(libc_static PROPERTIES OUTPUT_NAME "libc") 7 | IF (WIN32) 8 | set_target_properties(libc_static PROPERTIES ARCHIVE_OUTPUT_NAME "libc") 9 | ELSE() 10 | set_target_properties(libc_static PROPERTIES ARCHIVE_OUTPUT_NAME "c") 11 | ENDIF() 12 | 13 | #find_package(LIBA NAMES alib liba libliba liba++) 14 | #find_package(LIBB NAMES blib libb liblibb) 15 | 16 | # LIBA_INCLUDE_DIRS is not set, so giving the path relative to liba_config.cmake 17 | # would be happy to improve that 18 | target_link_libraries(libc_static PUBLIC ${LIBA_DIR}/lib/liblib_a_bazel.a) 19 | target_include_directories(libc_static PUBLIC ${LIBA_DIR}/include) 20 | 21 | target_link_libraries(libc_static PUBLIC ${LIBB_DIR}/lib/liblib_b_bazel.a) 22 | target_include_directories(libc_static PUBLIC ${LIBB_DIR}/include) 23 | 24 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 25 | 26 | install(TARGETS libc_static ARCHIVE DESTINATION lib) 27 | 28 | install(FILES libc.h DESTINATION include) 29 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libc/src/libc.cpp: -------------------------------------------------------------------------------- 1 | #include "libc.h" 2 | 3 | std::string hello_libc(void) { 4 | return hello_liba() + " " + hello_libb() + " Hello from LIBC!"; 5 | } 6 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/libc/src/libc.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBC_H_ 2 | #define LIBC_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "liba.h" 9 | #include "libb.h" 10 | 11 | std::string hello_libc(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /examples/cmake_synthetic/test_libb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "libb.h" 6 | 7 | int main(int argc, char* argv[]) { 8 | std::string result = hello_libb(); 9 | if (result != "Hello from LIBA! Hello from LIBB!") { 10 | throw std::runtime_error("Wrong result: " + result); 11 | } 12 | std::cout << "Everything's fine!"; 13 | } 14 | -------------------------------------------------------------------------------- /examples/cmake_with_bazel_transitive/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_test") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 3 | 4 | # Example of the cmake_external target built with Bazel-built dependency 5 | cmake( 6 | name = "cmake_libb", 7 | cache_entries = { 8 | # CMake's find_package wants to find cmake config for liba, 9 | # which we do not have -> disable search 10 | "CMAKE_DISABLE_FIND_PACKAGE_LIBA": "True", 11 | # as currently we copy all libraries, built with Bazel, into $EXT_BUILD_DEPS/lib 12 | # and the headers into $EXT_BUILD_DEPS/include 13 | "LIBA_DIR": "$$EXT_BUILD_DEPS", 14 | }, 15 | generate_args = ["-GNinja"], 16 | lib_source = "//cmake_with_bazel_transitive/libb:b_srcs", 17 | out_static_libs = select({ 18 | "//:windows": ["libb.lib"], 19 | "//conditions:default": ["libb.a"], 20 | }), 21 | # This library is with public visibility, we can reuse it here. 22 | deps = ["//cmake_synthetic/liba:lib_a_bazel"], 23 | ) 24 | 25 | # And cc_test built with cmake_external dependency and transitive Bazel dependency 26 | cc_test( 27 | name = "test", 28 | srcs = [ 29 | "test_libb.cpp", 30 | ], 31 | deps = [ 32 | # liba should come from transitive dependencies 33 | ":cmake_libb", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /examples/cmake_with_bazel_transitive/libb/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "b_srcs", 3 | srcs = glob(["**"]), 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /examples/cmake_with_bazel_transitive/libb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | project(libb) 4 | 5 | add_subdirectory(src) 6 | -------------------------------------------------------------------------------- /examples/cmake_with_bazel_transitive/libb/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | set(LIBB_SRC libb.cpp libb.h) 4 | 5 | add_library(libb_static STATIC ${LIBB_SRC}) 6 | set_target_properties(libb_static PROPERTIES OUTPUT_NAME "libb") 7 | IF (WIN32) 8 | set_target_properties(libb_static PROPERTIES ARCHIVE_OUTPUT_NAME "libb") 9 | ELSE() 10 | set_target_properties(libb_static PROPERTIES ARCHIVE_OUTPUT_NAME "b") 11 | ENDIF() 12 | 13 | find_package(LIBA NAMES alib liba libliba) 14 | 15 | # LIBA_INCLUDE_DIRS is not set, so giving the path relative to liba_config.cmake 16 | # would be happy to improve that 17 | target_link_libraries(libb_static PUBLIC ${LIBA_DIR}/lib/liba.a) 18 | target_include_directories(libb_static PUBLIC ${LIBA_DIR}/include) 19 | 20 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 21 | 22 | install(TARGETS libb_static ARCHIVE DESTINATION lib) 23 | 24 | install(FILES libb.h DESTINATION include) 25 | -------------------------------------------------------------------------------- /examples/cmake_with_bazel_transitive/libb/src/libb.cpp: -------------------------------------------------------------------------------- 1 | #include "libb.h" 2 | 3 | std::string hello_libb(void) { return hello_liba() + " Hello from LIBB!"; } 4 | -------------------------------------------------------------------------------- /examples/cmake_with_bazel_transitive/libb/src/libb.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBB_H_ 2 | #define LIBB_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "liba.h" 9 | 10 | std::string hello_libb(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /examples/cmake_with_bazel_transitive/test_libb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "libb.h" 6 | 7 | int main(int argc, char* argv[]) { 8 | std::string result = hello_libb(); 9 | if (result != "Hello from LIBA! Hello from LIBB!") { 10 | throw std::runtime_error("Wrong result: " + result); 11 | } 12 | std::cout << "Everything's fine!"; 13 | } 14 | -------------------------------------------------------------------------------- /examples/cmake_with_data/cmake_with_data.txt: -------------------------------------------------------------------------------- 1 | Hallo welt! -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_a/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "srcs", 3 | srcs = glob(["**"]), 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_a/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5.1) 2 | 3 | project(cmake_with_data_example) 4 | 5 | add_subdirectory(src) 6 | -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_a/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIB_SRC lib_a.cpp lib_a.h) 2 | 3 | add_library(lib_a_static STATIC ${LIB_SRC}) 4 | 5 | set_target_properties(lib_a_static PROPERTIES OUTPUT_NAME "lib_a") 6 | set_target_properties(lib_a_static PROPERTIES ARCHIVE_OUTPUT_NAME "lib_a") 7 | set_target_properties(lib_a_static PROPERTIES PREFIX "") 8 | 9 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 10 | 11 | install(TARGETS lib_a_static ARCHIVE DESTINATION lib) 12 | install(FILES lib_a.h DESTINATION include) 13 | -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_a/src/lib_a.cpp: -------------------------------------------------------------------------------- 1 | #include "lib_a.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | std::string hello_data(std::string path) { 9 | // Open the file 10 | std::ifstream data_file(path.c_str()); 11 | if (!data_file.good()) { 12 | throw std::runtime_error("Could not open: " + path); 13 | } 14 | 15 | // Read it's contents to a string 16 | std::string data_str((std::istreambuf_iterator(data_file)), 17 | (std::istreambuf_iterator())); 18 | 19 | // Close the file 20 | data_file.close(); 21 | 22 | return data_str; 23 | } 24 | -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_a/src/lib_a.h: -------------------------------------------------------------------------------- 1 | #ifndef LIB_H_ 2 | #define LIB_H_ 3 | 4 | #include 5 | 6 | std::string hello_data(std::string path); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_b/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_binary") 2 | 3 | cc_binary( 4 | name = "lib_b", 5 | srcs = [ 6 | "src/lib_b.cpp", 7 | "src/lib_b.h", 8 | ], 9 | linkshared = True, 10 | visibility = ["//cmake_with_data:__pkg__"], 11 | ) 12 | -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_b/src/lib_b.cpp: -------------------------------------------------------------------------------- 1 | #include "lib_b.h" 2 | 3 | std::string hello_data(std::string path) { return std::string("Hello world!"); } 4 | -------------------------------------------------------------------------------- /examples/cmake_with_data/lib_b/src/lib_b.h: -------------------------------------------------------------------------------- 1 | #ifndef LIB_B_H_ 2 | #define LIB_B_H_ 3 | 4 | #include 5 | 6 | std::string hello_world(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /examples/cmake_with_data/tests/test_cmake_with_data.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "lib_a.h" 6 | 7 | int main(int argc, char* argv[]) { 8 | #ifdef _WIN32 9 | std::string result = hello_data(".\\cmake_with_data\\cmake_with_data.txt"); 10 | #else 11 | std::string result = hello_data("./cmake_with_data/cmake_with_data.txt"); 12 | #endif 13 | if (result != "Hallo welt!") { 14 | throw std::runtime_error("Wrong result: " + result); 15 | } 16 | std::cout << "Everything's fine!"; 17 | } 18 | -------------------------------------------------------------------------------- /examples/cmake_with_data/tests/test_cmake_with_shared_lib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void test_opening_file(std::string path) { 7 | std::ifstream data_file(path); 8 | if (!data_file.good()) { 9 | throw std::runtime_error("Could not open file: " + path); 10 | } 11 | 12 | data_file.close(); 13 | } 14 | 15 | int main(int argc, char* argv[]) { 16 | // Make sure the expectd shared library is available 17 | #ifdef _WIN32 18 | test_opening_file(".\\cmake_with_data\\lib_b\\lib_b.dll"); 19 | #else 20 | // Shared libraries used to have the .so file extension on macOS. 21 | // See https://github.com/bazelbuild/bazel/pull/14369. 22 | try { 23 | test_opening_file("./cmake_with_data/lib_b/liblib_b.so"); 24 | } catch (std::runtime_error& e) { 25 | test_opening_file("./cmake_with_data/lib_b/liblib_b.dylib"); 26 | } 27 | #endif 28 | std::cout << "Everything's fine!"; 29 | } 30 | -------------------------------------------------------------------------------- /examples/cmake_with_target/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | filegroup( 4 | name = "srcs", 5 | srcs = glob(["src/**"]), 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | # Building all targets with the `srcs` CMake project will fail. 10 | # this example demonstrates how users can avoid unnecessary targets 11 | cmake( 12 | name = "cmake_with_target", 13 | build_args = [ 14 | "--verbose", 15 | "--", # <- Pass remaining options to the native tool. 16 | "-j 1", 17 | ], 18 | install_args = ["--component working"], 19 | lib_source = ":srcs", 20 | out_static_libs = select({ 21 | "@platforms//os:windows": [ 22 | "working_a.lib", 23 | "working_b.lib", 24 | ], 25 | "//conditions:default": [ 26 | "libworking_a.a", 27 | "libworking_b.a", 28 | ], 29 | }), 30 | targets = [ 31 | "working_a", 32 | "working_b", 33 | ], 34 | ) 35 | -------------------------------------------------------------------------------- /examples/cmake_with_target/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18.1) 2 | 3 | project(cmake_with_target_example) 4 | 5 | set(LIB_SRC lib.cpp lib.h) 6 | 7 | add_library(working_a STATIC ${LIB_SRC}) 8 | target_compile_definitions(working_a PRIVATE TRIGGER_ERROR=0) 9 | 10 | add_library(working_b STATIC ${LIB_SRC}) 11 | target_compile_definitions(working_b PRIVATE TRIGGER_ERROR=0) 12 | 13 | add_library(broken STATIC ${LIB_SRC}) 14 | target_compile_definitions(broken PRIVATE TRIGGER_ERROR=1) 15 | 16 | install(TARGETS working_a working_b COMPONENT working ARCHIVE DESTINATION lib) 17 | install(TARGETS broken COMPONENT broken ARCHIVE DESTINATION lib) 18 | install(FILES lib.h DESTINATION include) 19 | -------------------------------------------------------------------------------- /examples/cmake_with_target/src/lib.cpp: -------------------------------------------------------------------------------- 1 | #include "lib.h" 2 | 3 | #include 4 | 5 | #ifndef TRIGGER_ERROR 6 | #error This value must be defined 7 | #endif 8 | 9 | #if TRIGGER_ERROR 10 | #error This error intentionally prevents this library from compiling 11 | #endif 12 | 13 | void hello_world() { std::cout << "Hello world!" << std::endl; } 14 | -------------------------------------------------------------------------------- /examples/cmake_with_target/src/lib.h: -------------------------------------------------------------------------------- 1 | #ifndef LIB_H_ 2 | #define LIB_H_ 3 | 4 | void hello_world(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /examples/cmake_working_dir/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_test") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 3 | 4 | filegroup( 5 | name = "sources", 6 | srcs = glob(["source_root/**"]), 7 | ) 8 | 9 | cmake( 10 | name = "liba", 11 | lib_source = ":sources", 12 | # This demonstrates the usage of the working directory: 13 | # the directory where the "main" CMakeLists.txt file resides. 14 | working_directory = "cmake_dir", 15 | ) 16 | 17 | cc_test( 18 | name = "test_lib", 19 | srcs = [ 20 | "test_liba.cpp", 21 | ], 22 | deps = [ 23 | ":liba", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /examples/cmake_working_dir/source_root/.keep: -------------------------------------------------------------------------------- 1 | # This file must exist so Bazel will detect that `source_root` is the highest level 2 | # directory for `cmake_working_dir`, thus enabling the `working_directory` to take 3 | # effect and use `cmake_dir` as the working directory. 4 | -------------------------------------------------------------------------------- /examples/cmake_working_dir/source_root/cmake_dir/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | 3 | project(liba) 4 | 5 | set(LIBA_SRC ../src/liba.cpp ../src/liba.h) 6 | 7 | add_library(liba_static STATIC ${LIBA_SRC}) 8 | 9 | set_target_properties(liba_static PROPERTIES OUTPUT_NAME "liba") 10 | IF (WIN32) 11 | set_target_properties(liba_static PROPERTIES ARCHIVE_OUTPUT_NAME "liba") 12 | ELSE() 13 | set_target_properties(liba_static PROPERTIES ARCHIVE_OUTPUT_NAME "a") 14 | ENDIF() 15 | set_target_properties(liba_static PROPERTIES PUBLIC_HEADER "../src/liba.h") 16 | 17 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 18 | 19 | install(FILES ../src/liba.h DESTINATION include) 20 | 21 | install(TARGETS liba_static 22 | EXPORT liba_targets 23 | ARCHIVE DESTINATION lib 24 | INCLUDES DESTINATION include 25 | PUBLIC_HEADER DESTINATION include 26 | ) 27 | target_include_directories(liba_static INTERFACE 28 | $ 29 | ) 30 | 31 | install(EXPORT liba_targets 32 | DESTINATION lib/cmake/liba 33 | FILE liba-config.cmake) 34 | -------------------------------------------------------------------------------- /examples/cmake_working_dir/source_root/src/liba.cpp: -------------------------------------------------------------------------------- 1 | #include "liba.h" 2 | 3 | std::string hello_liba(void) { return "Hello from LIBA!"; } 4 | -------------------------------------------------------------------------------- /examples/cmake_working_dir/source_root/src/liba.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBA_H_ 2 | #define LIBA_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | std::string hello_liba(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /examples/cmake_working_dir/test_liba.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "liba.h" 6 | 7 | int main(int argc, char* argv[]) { 8 | std::string result = hello_liba(); 9 | if (result != "Hello from LIBA!") { 10 | throw std::runtime_error("Wrong result: " + result); 11 | } 12 | std::cout << "Everything's fine!"; 13 | } 14 | -------------------------------------------------------------------------------- /examples/configure_modify_input_source/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_test") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 3 | 4 | configure_make( 5 | name = "simple", 6 | configure_in_place = True, 7 | lib_source = "//configure_modify_input_source/simple_lib:simple_srcs", 8 | targets = [ 9 | "simple", 10 | "install", 11 | ], 12 | ) 13 | 14 | cc_test( 15 | name = "test", 16 | srcs = ["testSimple.c"], 17 | deps = [":simple"], 18 | ) 19 | -------------------------------------------------------------------------------- /examples/configure_modify_input_source/simple_lib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "simple_srcs", 3 | srcs = glob(["**"]), 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /examples/configure_modify_input_source/simple_lib/Makefile.in: -------------------------------------------------------------------------------- 1 | all: simple 2 | 3 | .PHONY: all 4 | 5 | simple: $(OUTPUT) 6 | 7 | .PHONY: simple 8 | 9 | $(OUTPUT): ./src/simple.c 10 | $(CC) $(CPPFLAGS) -o $(OBJECT) -c ./src/simple.c -I./include -I. 11 | $(AR) $(LDFLAGS) 12 | 13 | install: $(OUTPUT) 14 | mkdir -p simple 15 | mkdir -p simple/lib 16 | cp $(OUTPUT) ./simple/lib/$(OUTPUT) 17 | cp -r ./include ./simple 18 | 19 | .PHONY: clean test 20 | -------------------------------------------------------------------------------- /examples/configure_modify_input_source/simple_lib/configure: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # (Using perl here for replacement to avoid difference in in-place 6 | # arguments on macOS sed) 7 | 8 | perl -i -pe 's/42/0/' src/simple.c 9 | 10 | echo "CC = $CC" > Makefile 11 | echo "LDFLAGS = $LDFLAGS" >> Makefile 12 | if [[ "$(uname)" == *"NT"* ]]; then 13 | echo "AR = ${AR}" >> Makefile 14 | echo "OBJECT = simple.obj" >> Makefile 15 | echo "OUTPUT = simple.lib" >> Makefile 16 | 17 | ESCAPED_CPPFLAGS="$(echo ${CFLAGS} | sed 's@\\@/@g')" 18 | ESCAPED_LDFLAGS="$(echo ${LDFLAGS} | sed 's@\\@/@g')" 19 | echo "CPPFLAGS = /c ${ESCAPED_CPPFLAGS}" >> Makefile 20 | echo "LDFLAGS = \$(OBJECT) ${ESCAPED_LDFLAGS} /OUT:\$(OUTPUT)" >> Makefile 21 | else 22 | echo "AR = \"ar\"" >> Makefile 23 | echo "OBJECT = simple.o" >> Makefile 24 | echo "OUTPUT = simple.a" >> Makefile 25 | echo "CPPFLAGS = ${CFLAGS}" >> Makefile 26 | echo "LDFLAGS = rcs \$(OUTPUT) \$(OBJECT)" >> Makefile 27 | fi 28 | cat Makefile.in >> Makefile 29 | -------------------------------------------------------------------------------- /examples/configure_modify_input_source/simple_lib/include/simple.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMPLE_H_ 2 | #define SIMPLE_H_ (1) 3 | 4 | int simpleFun(void); 5 | 6 | #endif // SIMPLE_H_ 7 | -------------------------------------------------------------------------------- /examples/configure_modify_input_source/simple_lib/src/simple.c: -------------------------------------------------------------------------------- 1 | #include "simple.h" 2 | 3 | int simpleFun(void) { return 42; } 4 | -------------------------------------------------------------------------------- /examples/configure_modify_input_source/testSimple.c: -------------------------------------------------------------------------------- 1 | #include "simple.h" 2 | 3 | int main(int argc, char **argv) { return simpleFun(); } 4 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 3 | 4 | cc_library( 5 | name = "built_with_bazel", 6 | srcs = ["builtWithBazel.c"], 7 | hdrs = ["builtWithBazel.h"], 8 | includes = ["."], 9 | ) 10 | 11 | configure_make( 12 | name = "simple", 13 | configure_in_place = True, 14 | lib_source = "//configure_with_bazel_transitive/simple_lib:simple_srcs", 15 | targets = [ 16 | "simple", 17 | "install", 18 | ], 19 | deps = [":built_with_bazel"], 20 | ) 21 | 22 | cc_test( 23 | name = "test", 24 | srcs = ["testSimple.c"], 25 | deps = [":simple"], 26 | ) 27 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/builtWithBazel.c: -------------------------------------------------------------------------------- 1 | #include "builtWithBazel.h" 2 | 3 | char* bazelSays(void) { return "It's me, Bazel!"; } 4 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/builtWithBazel.h: -------------------------------------------------------------------------------- 1 | #ifndef BUILT_WITH_BAZEL_H_ 2 | #define BUILT_WITH_BAZEL_H_ (1) 3 | 4 | char* bazelSays(void); 5 | 6 | #endif // BUILT_WITH_BAZEL_H_ 7 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/simple_lib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "simple_srcs", 3 | srcs = glob(["**"]), 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/simple_lib/Makefile.in: -------------------------------------------------------------------------------- 1 | all: simple 2 | 3 | .PHONY: all 4 | 5 | simple: $(OUTPUT) 6 | 7 | .PHONY: simple 8 | 9 | $(OUTPUT): ./src/simple.c 10 | $(CC) $(CPPFLAGS) -o $(OBJECT) -c ./src/simple.c -I./include -I. 11 | $(AR) $(LDFLAGS) 12 | 13 | install: 14 | mkdir -p simple 15 | mkdir -p simple/lib 16 | cp -p $(OUTPUT) ./simple/lib/$(OUTPUT) 17 | cp -rp ./include ./simple 18 | 19 | .PHONY: clean test 20 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/simple_lib/configure: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "# simple" > Makefile 3 | 4 | echo "CC = ${CC}" > Makefile 5 | 6 | 7 | if [[ "$(uname)" == *"NT"* ]]; then 8 | echo "AR = ${AR}" >> Makefile 9 | echo "OBJECT = simple.obj" >> Makefile 10 | echo "OUTPUT = simple.lib" >> Makefile 11 | echo "BUILT_WITH_BAZEL = $EXT_BUILD_DEPS/lib/built_with_bazel.lib" >> Makefile 12 | 13 | ESCAPED_CPPFLAGS="$(echo ${CPPFLAGS} | sed 's@\\@/@g')" 14 | ESCAPED_LDFLAGS="$(echo ${LDFLAGS} | sed 's@\\@/@g')" 15 | echo "CPPFLAGS = /c ${ESCAPED_CPPFLAGS}" >> Makefile 16 | echo "LDFLAGS = \$(OBJECT) ${ESCAPED_LDFLAGS} /OUT:\$(OUTPUT)" >> Makefile 17 | else 18 | echo "AR = \"ar\"" >> Makefile 19 | echo "OBJECT = simple.o" >> Makefile 20 | echo "OUTPUT = simple.a" >> Makefile 21 | echo "BUILT_WITH_BAZEL = $EXT_BUILD_DEPS/lib/libbuilt_with_bazel.a" >> Makefile 22 | echo "CPPFLAGS = ${CPPFLAGS}" >> Makefile 23 | echo "LDFLAGS = rcs \$(OUTPUT) \$(OBJECT)" >> Makefile 24 | fi 25 | 26 | echo "" >> Makefile 27 | cat Makefile.in >> Makefile 28 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/simple_lib/include/simple.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMPLE_H_ 2 | #define SIMPLE_H_ (1) 3 | 4 | void simpleFun(void); 5 | 6 | #endif // SIMPLE_H_ 7 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/simple_lib/src/simple.c: -------------------------------------------------------------------------------- 1 | #include "simple.h" 2 | 3 | #include 4 | 5 | #include "builtWithBazel.h" 6 | 7 | void simpleFun(void) { printf("simpleFun: %s", bazelSays()); } 8 | -------------------------------------------------------------------------------- /examples/configure_with_bazel_transitive/testSimple.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "builtWithBazel.h" 4 | #include "simple.h" 5 | 6 | int main(int argc, char **argv) { 7 | printf("Call bazelSays() directly: %s\n", bazelSays()); 8 | simpleFun(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /examples/current_toolchains/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | genrule( 4 | name = "current_make_toolchain_test", 5 | outs = ["out.txt"], 6 | cmd = "$(MAKE) --version > $@", 7 | toolchains = ["@rules_foreign_cc//toolchains:current_make_toolchain"], 8 | ) 9 | 10 | build_test( 11 | name = "current_toolchain_tests", 12 | targets = [":current_make_toolchain_test"], 13 | ) 14 | -------------------------------------------------------------------------------- /examples/deps/BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/deps/BUILD.bazel -------------------------------------------------------------------------------- /examples/deps/apple_support.patch: -------------------------------------------------------------------------------- 1 | --- crosstool/setup.bzl 2 | +++ crosstool/setup.bzl 3 | @@ -66,5 +66,3 @@ def apple_cc_configure(): 4 | def _apple_cc_configure_extension_impl(_): 5 | _apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") 6 | _apple_cc_autoconf(name = "local_config_apple_cc") 7 | - 8 | -apple_cc_configure_extension = module_extension(implementation = _apple_cc_configure_extension_impl) 9 | -------------------------------------------------------------------------------- /examples/deps/deps_android.bzl: -------------------------------------------------------------------------------- 1 | """A module for bringing in transitive dependencies of rules_android""" 2 | 3 | load("@rules_android//android:rules.bzl", "android_ndk_repository", "android_sdk_repository") 4 | 5 | def deps_android(): 6 | android_sdk_repository( 7 | name = "androidsdk", 8 | ) 9 | 10 | android_ndk_repository( 11 | name = "androidndk", 12 | ) 13 | -------------------------------------------------------------------------------- /examples/deps/deps_jvm_external.bzl: -------------------------------------------------------------------------------- 1 | """A module for bringing in transitive dependencies of rules_jvm_external""" 2 | 3 | load("@rules_jvm_external//:defs.bzl", "maven_install") 4 | 5 | def deps_jvm_external(): 6 | maven_install( 7 | artifacts = [ 8 | "com.android.support.constraint:constraint-layout:aar:1.1.2", 9 | "com.android.support:appcompat-v7:aar:26.1.0", 10 | ], 11 | repositories = [ 12 | "https://jcenter.bintray.com/", 13 | "https://maven.google.com", 14 | "https://repo1.maven.org/maven2", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/deps/repositories.bzl: -------------------------------------------------------------------------------- 1 | # buildifier: disable=module-docstring 2 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 4 | 5 | def repositories(): 6 | """Load all repositories needed for the targets of rules_foreign_cc_examples""" 7 | 8 | maybe( 9 | http_archive, 10 | name = "rules_android", 11 | urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"], 12 | sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", 13 | strip_prefix = "rules_android-0.1.1", 14 | ) 15 | 16 | RULES_JVM_EXTERNAL_TAG = "4.5" 17 | RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6" 18 | 19 | maybe( 20 | http_archive, 21 | name = "rules_jvm_external", 22 | strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, 23 | sha256 = RULES_JVM_EXTERNAL_SHA, 24 | url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, 25 | ) 26 | -------------------------------------------------------------------------------- /examples/make_simple/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_test") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "make") 3 | 4 | make( 5 | name = "make_lib", 6 | build_data = [ 7 | "//make_simple/code:cxx_wrapper.sh", 8 | "README.md", 9 | ], 10 | copts = [ 11 | "-DREQUIRED_DEFINE", 12 | ], 13 | env = { 14 | "CXX_WRAPPER": "$(execpath //make_simple/code:cxx_wrapper.sh)", 15 | "README_DIR": "$$(dirname $(execpath README.md))", 16 | }, 17 | lib_source = "//make_simple/code:srcs", 18 | out_data_dirs = ["share"], 19 | out_static_libs = ["liba.a"], 20 | ) 21 | 22 | cc_test( 23 | name = "test_lib", 24 | srcs = [ 25 | "test_libb.cpp", 26 | ], 27 | copts = [ 28 | "-std=c++11", 29 | ], 30 | tags = ["windows"], 31 | deps = [ 32 | ":make_lib", 33 | ], 34 | ) 35 | -------------------------------------------------------------------------------- /examples/make_simple/README.md: -------------------------------------------------------------------------------- 1 | # Simple Make Example 2 | 3 | ## Dependencies 4 | 5 | - clang 6 | - bazel 7 | 8 | ## Executing the Example 9 | 10 | To execute the example, run 11 | 12 | ```bash 13 | bazel test ... 14 | ``` 15 | 16 | ## Troubleshooting 17 | 18 | If you receive an error of the form: 19 | 20 | ```text 21 | ccache: FATAL: Failed to create /home/$USER/.ccache/2/f: Read-only file system 22 | ``` 23 | 24 | This is likely because you're have ccache set as your compiler. You can either 25 | disable ccache, or allow the sandbox to write to ~/.ccache: 26 | 27 | ```bash 28 | bazel test --sandbox_writable_path ~/.ccache ... 29 | ``` 30 | -------------------------------------------------------------------------------- /examples/make_simple/code/BUILD.bazel: -------------------------------------------------------------------------------- 1 | exports_files(["cxx_wrapper.sh"]) 2 | 3 | filegroup( 4 | name = "srcs", 5 | srcs = [ 6 | "Makefile", 7 | "liba.cpp", 8 | "liba.h", 9 | ], 10 | visibility = ["//make_simple:__subpackages__"], 11 | ) 12 | -------------------------------------------------------------------------------- /examples/make_simple/code/Makefile: -------------------------------------------------------------------------------- 1 | BUILD_DIR := build-out 2 | 3 | UNAME := $(shell uname) 4 | 5 | ifneq (,$(findstring NT, $(UNAME))) 6 | # If Windows 7 | CXXFLAGS := $(CXXFLAGS) /MD 8 | else 9 | CXXFLAGS := $(CXXFLAGS) -fPIC 10 | endif 11 | 12 | default all $(BUILD_DIR)/lib/liba.a: liba.cpp liba.h 13 | rm -rf $(BUILD_DIR)/lib 14 | mkdir -p $(BUILD_DIR)/lib 15 | $(CXX_WRAPPER) $(CXXFLAGS) -o $(BUILD_DIR)/lib/liba.o -c liba.cpp 16 | ar rcs $(BUILD_DIR)/lib/liba.a $(BUILD_DIR)/lib/liba.o 17 | 18 | .PHONY: all 19 | 20 | install: $(BUILD_DIR)/lib/liba.a 21 | mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/share 22 | cp -rpv $(BUILD_DIR)/lib $(PREFIX) 23 | cp -p liba.h $(PREFIX)/include 24 | cp $(README_DIR)/README.md $(PREFIX)/share/ 25 | 26 | .PHONY: clean test 27 | -------------------------------------------------------------------------------- /examples/make_simple/code/cxx_wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | 6 | if [[ $(uname) == *"NT"* ]]; then 7 | # If Windows 8 | exec clang-cl "$@" 9 | else 10 | exec "$CXX" "$@" 11 | fi 12 | -------------------------------------------------------------------------------- /examples/make_simple/code/liba.cpp: -------------------------------------------------------------------------------- 1 | #include "liba.h" 2 | 3 | #include 4 | 5 | #ifndef REQUIRED_DEFINE 6 | // '-DREQUIRED_DEFINE' is set via the copts attribute of the make rule. 7 | #error "REQUIRED_DEFINE is not defined" 8 | #endif 9 | 10 | std::string hello_liba(void) { return "Hello from LIBA!"; } 11 | 12 | double hello_math(double a) { 13 | // On Unix, this call requires linking to libm.so. The Bazel toolchain adds 14 | // the required `-lm` linkopt automatically and rules_foreign_cc forwards 15 | // this option to make invocation via the CXXFLAGS variable. 16 | return acos(a); 17 | } 18 | -------------------------------------------------------------------------------- /examples/make_simple/code/liba.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBA_H_ 2 | #define LIBA_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | std::string hello_liba(void); 9 | double hello_math(double); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /examples/make_simple/test_libb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "liba.h" 6 | 7 | int main(int argc, char* argv[]) { 8 | std::string result = hello_liba(); 9 | if (result != "Hello from LIBA!") { 10 | throw std::runtime_error("Wrong result: " + result); 11 | } 12 | double math_result = hello_math(0.5); 13 | if (math_result < 1.047 || math_result > 1.048) { 14 | throw std::runtime_error("Wrong math_result: " + 15 | std::to_string(math_result)); 16 | } 17 | std::cout << "Everything's fine!"; 18 | } 19 | -------------------------------------------------------------------------------- /examples/meson_simple/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_test") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson") 3 | load("@rules_shell//shell:sh_test.bzl", "sh_test") 4 | 5 | meson( 6 | name = "meson_lib", 7 | build_data = ["//meson_simple/code:clang_wrapper.sh"], 8 | env = select({ 9 | "//:windows": { 10 | "CLANG_WRAPPER": "$(execpath //meson_simple/code:clang_wrapper.sh)", 11 | "CXX_FLAGS": "/MD", 12 | }, 13 | "//conditions:default": { 14 | "CLANG_WRAPPER": "$(execpath //meson_simple/code:clang_wrapper.sh)", 15 | "CXX_FLAGS": "-fPIC", 16 | }, 17 | }), 18 | lib_source = "//meson_simple/code:srcs", 19 | out_static_libs = ["liba.a"], 20 | ) 21 | 22 | cc_test( 23 | name = "test_lib", 24 | srcs = [ 25 | "test_libb.cpp", 26 | ], 27 | deps = [ 28 | ":meson_lib", 29 | ], 30 | ) 31 | 32 | meson( 33 | name = "meson_lib-introspect", 34 | lib_source = "//meson_simple/code:srcs", 35 | out_data_files = ["introspect.json"], 36 | out_include_dir = "", 37 | targets = ["introspect"], 38 | ) 39 | 40 | sh_test( 41 | name = "test_introspect", 42 | srcs = ["test_introspect.sh"], 43 | args = ["$(location meson_lib-introspect)"], 44 | data = [":meson_lib-introspect"], 45 | deps = ["@bazel_tools//tools/bash/runfiles"], 46 | ) 47 | -------------------------------------------------------------------------------- /examples/meson_simple/code/BUILD.bazel: -------------------------------------------------------------------------------- 1 | exports_files(["clang_wrapper.sh"]) 2 | 3 | filegroup( 4 | name = "srcs", 5 | srcs = [ 6 | "liba.cpp", 7 | "liba.h", 8 | "meson.build", 9 | ], 10 | visibility = ["//meson_simple:__subpackages__"], 11 | ) 12 | -------------------------------------------------------------------------------- /examples/meson_simple/code/clang_wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | 6 | if [[ $(uname) == *"NT"* ]]; then 7 | # If Windows 8 | exec clang-cl "$@" 9 | else 10 | exec clang "$@" 11 | fi 12 | -------------------------------------------------------------------------------- /examples/meson_simple/code/liba.cpp: -------------------------------------------------------------------------------- 1 | #include "liba.h" 2 | 3 | std::string hello_liba(void) { return "Hello from LIBA!"; } 4 | -------------------------------------------------------------------------------- /examples/meson_simple/code/liba.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBA_H_ 2 | #define LIBA_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | std::string hello_liba(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /examples/meson_simple/code/meson.build: -------------------------------------------------------------------------------- 1 | project('liba', 'cpp') 2 | 3 | builddir = 'rules_foreign_cc_build' 4 | 5 | cxx = meson.get_compiler('cpp') 6 | 7 | liba = static_library( 8 | 'a', 9 | 'liba.cpp', 10 | cpp_args: cxx.get_supported_arguments(), 11 | include_directories: include_directories('.'), 12 | install: true, 13 | install_dir: join_paths(get_option('prefix'), 'lib'), 14 | ) 15 | 16 | install_headers('liba.h', subdir: 'include') 17 | -------------------------------------------------------------------------------- /examples/meson_simple/test_introspect.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # --- begin runfiles.bash initialization --- 4 | # The runfiles library itself defines rlocation which you would need to look 5 | # up the library's runtime location, thus we have a chicken-and-egg problem. 6 | # 7 | # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). 8 | set -euo pipefail 9 | if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 10 | if [[ -f "$0.runfiles_manifest" ]]; then 11 | export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" 12 | elif [[ -f "$0.runfiles/MANIFEST" ]]; then 13 | export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" 14 | elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 15 | export RUNFILES_DIR="$0.runfiles" 16 | fi 17 | fi 18 | if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then 19 | source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" 20 | elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then 21 | source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ 22 | "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" 23 | else 24 | echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" 25 | exit 1 26 | fi 27 | # --- end runfiles.bash initialization --- 28 | 29 | [[ -f $(rlocation $TEST_WORKSPACE/$1) ]] && exit 0 30 | exit 1 31 | -------------------------------------------------------------------------------- /examples/meson_simple/test_libb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "include/liba.h" 6 | 7 | int main(int argc, char* argv[]) { 8 | std::string result = hello_liba(); 9 | if (result != "Hello from LIBA!") { 10 | throw std::runtime_error("Wrong result: " + result); 11 | } 12 | std::cout << "Everything's fine!"; 13 | } 14 | -------------------------------------------------------------------------------- /examples/ninja_simple/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_test") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "ninja") 3 | 4 | ninja( 5 | name = "ninja_lib", 6 | build_data = ["//ninja_simple/code:clang_wrapper.sh"], 7 | env = select({ 8 | "//:windows": { 9 | "CLANG_WRAPPER": "$(execpath //ninja_simple/code:clang_wrapper.sh)", 10 | "CXX_FLAGS": "/MD", 11 | }, 12 | "//conditions:default": { 13 | "CLANG_WRAPPER": "$(execpath //ninja_simple/code:clang_wrapper.sh)", 14 | "CXX_FLAGS": "-fPIC", 15 | }, 16 | }), 17 | lib_source = "//ninja_simple/code:srcs", 18 | out_static_libs = ["liba.a"], 19 | targets = [ 20 | "", 21 | "install", 22 | ], 23 | ) 24 | 25 | cc_test( 26 | name = "test_lib", 27 | srcs = [ 28 | "test_libb.cpp", 29 | ], 30 | deps = [ 31 | ":ninja_lib", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /examples/ninja_simple/README.md: -------------------------------------------------------------------------------- 1 | # Simple Ninja Example 2 | 3 | ## Dependencies 4 | 5 | - clang 6 | - bazel 7 | 8 | ## Executing the Example 9 | 10 | To execute the example, run 11 | 12 | ```bash 13 | bazel test ... 14 | ``` 15 | 16 | ## Troubleshooting 17 | 18 | If you receive an error of the form: 19 | 20 | ```text 21 | ccache: FATAL: Failed to create /home/$USER/.ccache/2/f: Read-only file system 22 | ``` 23 | 24 | This is likely because you're have ccache set as your compiler. You can either 25 | disable ccache, or allow the sandbox to write to ~/.ccache: 26 | 27 | ```bash 28 | bazel test --sandbox_writable_path ~/.ccache ... 29 | ``` 30 | -------------------------------------------------------------------------------- /examples/ninja_simple/code/BUILD.bazel: -------------------------------------------------------------------------------- 1 | exports_files(["clang_wrapper.sh"]) 2 | 3 | filegroup( 4 | name = "srcs", 5 | srcs = [ 6 | "build.ninja", 7 | "liba.cpp", 8 | "liba.h", 9 | ], 10 | visibility = ["//ninja_simple:__subpackages__"], 11 | ) 12 | -------------------------------------------------------------------------------- /examples/ninja_simple/code/build.ninja: -------------------------------------------------------------------------------- 1 | # build.ninja 2 | 3 | ninja_required_version = 1.3 4 | 5 | # Variables 6 | 7 | builddir = rules_foreign_cc_build 8 | rm = rm -fr 9 | cxx = $$CLANG_WRAPPER 10 | ar = ar 11 | lib = $builddir/liba.a 12 | cxx_flags = $$CXX_FLAGS 13 | 14 | # Rules 15 | 16 | rule compile 17 | command = $cxx -c $in $cxx_flags -o $out 18 | description = Building C file $in 19 | 20 | rule ar 21 | command = $rm $out && $ar crs $out $in 22 | description = Creating archive $out 23 | 24 | rule clean 25 | command = $rm $builddir 26 | description = Cleaning directory $builddir 27 | 28 | rule install 29 | command = mkdir -p $$INSTALLDIR/lib $$INSTALLDIR/include && cp -rpv $builddir/*.a $$INSTALLDIR/lib/ && cp -p liba.h $$INSTALLDIR/include/ 30 | description = Installing compiled lib 31 | 32 | # Builds 33 | 34 | build clean: clean 35 | 36 | build $builddir/liba.o: compile liba.cpp 37 | 38 | build $lib: ar $builddir/liba.o 39 | 40 | build install: install 41 | 42 | # Entrypoint 43 | 44 | default $lib 45 | -------------------------------------------------------------------------------- /examples/ninja_simple/code/clang_wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | 6 | if [[ $(uname) == *"NT"* ]]; then 7 | # If Windows 8 | exec clang-cl "$@" 9 | else 10 | exec clang "$@" 11 | fi 12 | -------------------------------------------------------------------------------- /examples/ninja_simple/code/liba.cpp: -------------------------------------------------------------------------------- 1 | #include "liba.h" 2 | 3 | std::string hello_liba(void) { return "Hello from LIBA!"; } 4 | -------------------------------------------------------------------------------- /examples/ninja_simple/code/liba.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBA_H_ 2 | #define LIBA_H_ (1) 3 | 4 | #include 5 | 6 | #include 7 | 8 | std::string hello_liba(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /examples/ninja_simple/test_libb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "liba.h" 6 | 7 | int main(int argc, char* argv[]) { 8 | std::string result = hello_liba(); 9 | if (result != "Hello from LIBA!") { 10 | throw std::runtime_error("Wrong result: " + result); 11 | } 12 | std::cout << "Everything's fine!"; 13 | } 14 | -------------------------------------------------------------------------------- /examples/requirements.txt: -------------------------------------------------------------------------------- 1 | mako==1.2.2 2 | -------------------------------------------------------------------------------- /examples/rust/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | build_test( 4 | name = "build_test", 5 | targets = [ 6 | "@rust_example//:libz-ng-sys", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /examples/rust/Cargo.Bazel.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "cc" 7 | version = "1.0.95" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" 10 | 11 | [[package]] 12 | name = "cmake" 13 | version = "0.1.50" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" 16 | dependencies = [ 17 | "cc", 18 | ] 19 | 20 | [[package]] 21 | name = "direct-cargo-bazel-deps" 22 | version = "0.0.1" 23 | dependencies = [ 24 | "libz-ng-sys", 25 | ] 26 | 27 | [[package]] 28 | name = "libc" 29 | version = "0.2.154" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" 32 | 33 | [[package]] 34 | name = "libz-ng-sys" 35 | version = "1.1.20" 36 | source = "registry+https://github.com/rust-lang/crates.io-index" 37 | checksum = "8f0f7295a34685977acb2e8cc8b08ee4a8dffd6cf278eeccddbe1ed55ba815d5" 38 | dependencies = [ 39 | "cmake", 40 | "libc", 41 | ] 42 | -------------------------------------------------------------------------------- /examples/third_party/.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /examples/third_party/.gitignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | -------------------------------------------------------------------------------- /examples/third_party/README.md: -------------------------------------------------------------------------------- 1 | # Rules Foreign CC Third Party Examples 2 | 3 | This package contains examples of `rules_foreign_cc` building common/popular third-party source code. 4 | 5 | For more details on how the examples here should be structured. Please see the documentation in [@rules_foreign_cc_examples//:README.md](../README.md#third-party). 6 | -------------------------------------------------------------------------------- /examples/third_party/WORKSPACE.bazel: -------------------------------------------------------------------------------- 1 | workspace(name = "rules_foreign_cc_examples_third_party") 2 | 3 | local_repository( 4 | name = "rules_foreign_cc", 5 | path = "../..", 6 | ) 7 | 8 | load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") 9 | 10 | rules_foreign_cc_dependencies(register_built_pkgconfig_toolchain = True) 11 | 12 | local_repository( 13 | name = "rules_foreign_cc_examples", 14 | path = "..", 15 | ) 16 | 17 | load("//:repositories.bzl", "repositories") 18 | 19 | repositories() 20 | 21 | load("//:setup.bzl", "setup") 22 | 23 | setup() 24 | -------------------------------------------------------------------------------- /examples/third_party/apr/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.apr.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "apr_build_test", 12 | targets = [ 13 | "@apr//:apr", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/apr/apr_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency apr""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def apr_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "apr", 10 | build_file = Label("//apr:BUILD.apr.bazel"), 11 | patches = [ 12 | # https://bz.apache.org/bugzilla/show_bug.cgi?id=64753 13 | Label("//apr:macos_pid_t.patch"), 14 | # https://apachelounge.com/viewtopic.php?t=8260 15 | Label("//apr:windows_winnt.patch"), 16 | ], 17 | sha256 = "", 18 | strip_prefix = "apr-1.7.6", 19 | urls = [ 20 | "https://mirror.bazel.build/www-eu.apache.org/dist/apr/apr-1.7.6.tar.gz", 21 | "https://dlcdn.apache.org/apr/apr-1.7.6.tar.gz", 22 | "https://www-eu.apache.org/dist/apr/apr-1.7.6.tar.gz", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /examples/third_party/apr/macos_pid_t.patch: -------------------------------------------------------------------------------- 1 | diff -ruN configure configure 2 | --- configure 2019-04-01 19:56:23.000000000 +0200 3 | +++ configure 2019-04-01 19:56:23.000000000 +0200 4 | @@ -24517,7 +24518,7 @@ 5 | elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_long_long"; then 6 | pid_t_fmt='#define APR_PID_T_FMT APR_INT64_T_FMT' 7 | else 8 | - pid_t_fmt='#error Can not determine the proper size for pid_t' 9 | + pid_t_fmt='#define APR_PID_T_FMT "d"' 10 | fi 11 | 12 | # Basically, we have tried to figure out the correct format strings -------------------------------------------------------------------------------- /examples/third_party/apr/windows_winnt.patch: -------------------------------------------------------------------------------- 1 | --- include/apr.hw 2019-03-21 00:41:37.000000000 +0100 2 | +++ include/apr.hw 2019-03-21 00:41:37.000000000 +0100 3 | @@ -86,7 +86,7 @@ 4 | 5 | /* Restrict the server to a subset of Windows XP header files by default 6 | */ 7 | -#define _WIN32_WINNT 0x0501 8 | +#define _WIN32_WINNT 0x0600 9 | #endif 10 | #ifndef NOUSER 11 | #define NOUSER 12 | -------------------------------------------------------------------------------- /examples/third_party/apr_util/BUILD.apr_util.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | filegroup( 4 | name = "all_srcs", 5 | srcs = glob( 6 | include = ["**"], 7 | exclude = ["*.bazel"], 8 | ), 9 | ) 10 | 11 | configure_make( 12 | name = "apr_util", 13 | configure_in_place = True, 14 | configure_options = [ 15 | "--with-apr=$$EXT_BUILD_DEPS/apr", 16 | "--with-expat=$$EXT_BUILD_DEPS/expat", 17 | ], 18 | env = select({ 19 | "@platforms//os:macos": {"AR": ""}, 20 | "//conditions:default": {}, 21 | }), 22 | lib_source = ":all_srcs", 23 | out_static_libs = ["libaprutil-1.a"], 24 | visibility = ["//visibility:public"], 25 | deps = [ 26 | "@apr", 27 | "@expat", 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /examples/third_party/apr_util/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.apr_util.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "apr_util_build_test", 12 | targets = [ 13 | "@apr_util//:apr_util", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/apr_util/BUILD.expat.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "configure_make") 2 | 3 | filegroup( 4 | name = "all_srcs", 5 | srcs = glob( 6 | include = ["**"], 7 | exclude = ["*.bazel"], 8 | ), 9 | ) 10 | 11 | LIB_NAME = "expat" 12 | 13 | alias( 14 | name = "expat", 15 | actual = select({ 16 | "@apr//:msvc_compiler": "expat_msvc", 17 | "//conditions:default": "expat_default", 18 | }), 19 | visibility = ["//visibility:public"], 20 | ) 21 | 22 | cmake( 23 | name = "expat_msvc", 24 | cache_entries = { 25 | "CMAKE_BUILD_TYPE": "Release", 26 | "EXPAT_MSVC_STATIC_CRT": "ON", 27 | "EXPAT_SHARED_LIBS": "OFF", 28 | }, 29 | generate_args = ["-G\"NMake Makefiles\""], 30 | lib_name = LIB_NAME, 31 | lib_source = ":all_srcs", 32 | out_static_libs = ["libexpatMT.lib"], 33 | ) 34 | 35 | configure_make( 36 | name = "expat_default", 37 | configure_options = [ 38 | "--disable-shared", 39 | "--without-docbook", 40 | "--without-examples", 41 | "--without-tests", 42 | "CFLAGS='-fPIC'", 43 | ], 44 | env = select({ 45 | "@platforms//os:macos": {"AR": ""}, 46 | "//conditions:default": {}, 47 | }), 48 | lib_name = LIB_NAME, 49 | lib_source = ":all_srcs", 50 | out_static_libs = ["libexpat.a"], 51 | ) 52 | -------------------------------------------------------------------------------- /examples/third_party/apr_util/apr_util_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency apr""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def apr_util_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "apr_util", 10 | build_file = Label("//apr_util:BUILD.apr_util.bazel"), 11 | integrity = "sha256-K3TYkycDgmhiyjBbCU7vKYPCeznVyUFEQumXaprPGYM=", 12 | strip_prefix = "apr-util-1.6.3", 13 | urls = [ 14 | "https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz", 15 | ], 16 | ) 17 | 18 | maybe( 19 | http_archive, 20 | name = "expat", 21 | build_file = Label("//apr_util:BUILD.expat.bazel"), 22 | sha256 = "a00ae8a6b96b63a3910ddc1100b1a7ef50dc26dceb65ced18ded31ab392f132b", 23 | strip_prefix = "expat-2.4.1", 24 | urls = [ 25 | "https://mirror.bazel.build/github.com/libexpat/libexpat/releases/download/R_2_4_1/expat-2.4.1.tar.gz", 26 | "https://github.com/libexpat/libexpat/releases/download/R_2_4_1/expat-2.4.1.tar.gz", 27 | ], 28 | ) 29 | -------------------------------------------------------------------------------- /examples/third_party/autotools/BUILD.autoconf.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "autoconf", 15 | build_data = [ 16 | "@m4", 17 | ], 18 | env = select({ 19 | "@platforms//os:macos": { 20 | "AR": "", 21 | "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", 22 | }, 23 | "//conditions:default": { 24 | "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", 25 | }, 26 | }), 27 | lib_source = ":all_srcs", 28 | out_binaries = [ 29 | "autoconf", 30 | "autoheader", 31 | "autom4te", 32 | "autoreconf", 33 | "autoscan", 34 | "autoupdate", 35 | "ifnames", 36 | ], 37 | out_data_dirs = ["share"], 38 | ) 39 | -------------------------------------------------------------------------------- /examples/third_party/autotools/BUILD.automake.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "automake", 15 | build_data = [ 16 | "@autoconf", 17 | "@m4", 18 | ], 19 | env = { 20 | "AC_MACRODIR": "$$EXT_BUILD_DEPS$$/bin/autoconf/share/autoconf", 21 | "AUTOM4TE": "$$EXT_BUILD_DEPS$$/bin/autoconf/bin/autom4te", 22 | "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", 23 | "PERL": "$$EXT_BUILD_ROOT$$/$(PERL)", 24 | "autom4te_perllibdir": "$$EXT_BUILD_DEPS$$/bin/autoconf/share/autoconf", 25 | }, 26 | lib_source = ":all_srcs", 27 | out_binaries = [ 28 | "automake", 29 | ], 30 | toolchains = ["@rules_perl//:current_toolchain"], 31 | ) 32 | -------------------------------------------------------------------------------- /examples/third_party/autotools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | build_test( 4 | name = "m4_build_test", 5 | tags = ["manual"], 6 | targets = ["@m4//:m4"], 7 | visibility = ["//:__pkg__"], 8 | ) 9 | 10 | build_test( 11 | name = "autoconf_build_test", 12 | tags = ["manual"], 13 | targets = ["@autoconf//:autoconf"], 14 | visibility = ["//:__pkg__"], 15 | ) 16 | 17 | build_test( 18 | name = "automake_build_test", 19 | tags = ["manual"], 20 | targets = ["@automake//:automake"], 21 | visibility = ["//:__pkg__"], 22 | ) 23 | 24 | build_test( 25 | name = "libtool_build_test", 26 | tags = ["manual"], 27 | targets = ["@libtool//:libtool"], 28 | visibility = ["//:__pkg__"], 29 | ) 30 | -------------------------------------------------------------------------------- /examples/third_party/autotools/BUILD.libtool.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libtool", 15 | build_data = [ 16 | "@m4", 17 | ], 18 | env = select({ 19 | "@platforms//os:macos": { 20 | "AR": "", 21 | "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", 22 | }, 23 | "//conditions:default": {"M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4"}, 24 | }), 25 | install_prefix = "install", 26 | lib_source = ":all_srcs", 27 | out_binaries = [ 28 | "libtool", 29 | ], 30 | out_data_dirs = ["share"], 31 | ) 32 | -------------------------------------------------------------------------------- /examples/third_party/autotools/BUILD.m4.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "m4", 15 | env = select({ 16 | "@platforms//os:macos": {"AR": ""}, 17 | "//conditions:default": {}, 18 | }), 19 | lib_source = ":all_srcs", 20 | out_binaries = [ 21 | "m4", 22 | ], 23 | ) 24 | 25 | filegroup( 26 | name = "m4_exe", 27 | srcs = [":m4"], 28 | output_group = "m4", 29 | visibility = ["//visibility:public"], 30 | ) 31 | -------------------------------------------------------------------------------- /examples/third_party/bison/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | build_test( 4 | name = "bison_build_test", 5 | tags = ["manual"], # Linux Only 6 | targets = ["@bison//:bison"], 7 | visibility = ["//:__pkg__"], 8 | ) 9 | -------------------------------------------------------------------------------- /examples/third_party/bison/BUILD.bison.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | # I tested and this builds for me on macOS and Linux, did not check Windows 14 | configure_make( 15 | name = "bison", 16 | build_data = [ 17 | "@m4", 18 | ], 19 | env = select({ 20 | "@platforms//os:linux": { 21 | "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", 22 | }, 23 | "@platforms//os:macos": { 24 | "AR": "", 25 | "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", 26 | }, 27 | "//conditions:default": {}, 28 | }), 29 | lib_source = ":all_srcs", 30 | out_binaries = [ 31 | "bison", 32 | "yacc", 33 | ], 34 | # Bison depends on m4sugar.m4 in the "share" directory at runtime 35 | out_data_dirs = ["share"], 36 | out_static_libs = ["liby.a"], 37 | ) 38 | 39 | filegroup( 40 | name = "gen_dir", 41 | srcs = [":bison"], 42 | output_group = "gen_dir", 43 | visibility = ["//visibility:public"], 44 | ) 45 | -------------------------------------------------------------------------------- /examples/third_party/bison/bison_repositories.bzl: -------------------------------------------------------------------------------- 1 | # buildifier: disable=module-docstring 2 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 4 | 5 | def bison_repositories(): 6 | """Load all repositories needed for bison""" 7 | 8 | maybe( 9 | http_archive, 10 | name = "bison", 11 | build_file = Label("//bison:BUILD.bison.bazel"), 12 | strip_prefix = "bison-3.8.2", 13 | urls = [ 14 | "https://mirror.bazel.build/ftp.gnu.org/gnu/bison/bison-3.8.2.tar.gz", 15 | "https://ftp.gnu.org/gnu/bison/bison-3.8.2.tar.gz", 16 | ], 17 | sha256 = "", 18 | ) 19 | -------------------------------------------------------------------------------- /examples/third_party/cares/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | load("@build_bazel_rules_apple//apple:apple_binary.bzl", "apple_binary") 3 | load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") 4 | 5 | cc_test( 6 | name = "test_c_ares", 7 | srcs = ["c-ares-test.cpp"], 8 | visibility = ["//:__pkg__"], 9 | deps = ["@cares"], 10 | ) 11 | 12 | cc_library( 13 | name = "ios_lib", 14 | srcs = ["c-ares-test.cpp"], 15 | tags = ["manual"], 16 | deps = ["@cares"], 17 | ) 18 | 19 | apple_binary( 20 | name = "ios_binary", 21 | minimum_os_version = "12.0", 22 | platform_type = "ios", 23 | deps = [":ios_lib"], 24 | ) 25 | 26 | build_test( 27 | name = "test_c_ares_ios", 28 | tags = ["manual"], 29 | target_compatible_with = ["@platforms//os:macos"], 30 | targets = ["ios_binary"], 31 | visibility = ["//:__pkg__"], 32 | ) 33 | -------------------------------------------------------------------------------- /examples/third_party/cares/BUILD.cares.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | cmake( 14 | name = "cares", 15 | cache_entries = { 16 | "CARES_BUILD_TOOLS": "off", 17 | "CARES_SHARED": "off", 18 | "CARES_STATIC": "on", 19 | }, 20 | generate_args = ["-GNinja"], 21 | lib_source = ":all_srcs", 22 | out_static_libs = select({ 23 | "@platforms//os:windows": ["cares.lib"], 24 | "//conditions:default": ["libcares.a"], 25 | }), 26 | ) 27 | -------------------------------------------------------------------------------- /examples/third_party/cares/c-ares-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include "ares.h" 7 | 8 | int main(int argc, char* argv[]) { 9 | int version = 0; 10 | const char* strVersion = ares_version(&version); 11 | if (strcmp(strVersion, "1.14.0") != 0) { 12 | throw std::runtime_error("Wrong version: " + std::string(strVersion)); 13 | } 14 | std::cout << "C-ares version: " << strVersion; 15 | } 16 | -------------------------------------------------------------------------------- /examples/third_party/cares/cares_repositories.bzl: -------------------------------------------------------------------------------- 1 | # buildifier: disable=module-docstring 2 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 4 | 5 | def cares_repositories(): 6 | """Load all repositories needed for cares""" 7 | maybe( 8 | http_archive, 9 | name = "cares", 10 | build_file = Label("//cares:BUILD.cares.bazel"), 11 | sha256 = "62dd12f0557918f89ad6f5b759f0bf4727174ae9979499f5452c02be38d9d3e8", 12 | strip_prefix = "c-ares-cares-1_14_0", 13 | urls = [ 14 | "https://mirror.bazel.build/github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz", 15 | "https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/curl/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | load("@rules_cc//cc:defs.bzl", "cc_test") 3 | 4 | exports_files( 5 | [ 6 | "BUILD.curl.bazel", 7 | ], 8 | visibility = ["//visibility:public"], 9 | ) 10 | 11 | cc_test( 12 | name = "curl_test", 13 | srcs = ["curl_test.cc"], 14 | defines = select({ 15 | "@openssl//:msvc_compiler": ["CURL_STATICLIB"], 16 | "//conditions:default": [], 17 | }), 18 | linkopts = select({ 19 | "@openssl//:msvc_compiler": [ 20 | "crypt32.lib", 21 | "ws2_32.lib", 22 | "advapi32.lib", 23 | "user32.lib", 24 | ], 25 | "@platforms//os:linux": ["-ldl"], 26 | "//conditions:default": [], 27 | }), 28 | deps = [ 29 | "@curl", 30 | "@openssl", 31 | ], 32 | ) 33 | 34 | build_test( 35 | name = "build_test", 36 | targets = [ 37 | "@curl//:curl", 38 | ], 39 | visibility = ["//:__pkg__"], 40 | ) 41 | 42 | test_suite( 43 | name = "curl_test_suite", 44 | tests = [ 45 | ":build_test", 46 | ":curl_test", 47 | ], 48 | visibility = ["//:__pkg__"], 49 | ) 50 | -------------------------------------------------------------------------------- /examples/third_party/curl/curl_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency curl""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def curl_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "curl", 10 | urls = [ 11 | "https://mirror.bazel.build/curl.se/download/curl-7.74.0.tar.gz", 12 | "https://curl.se/download/curl-7.74.0.tar.gz", 13 | "https://github.com/curl/curl/releases/download/curl-7_74_0/curl-7.74.0.tar.gz", 14 | ], 15 | type = "tar.gz", 16 | sha256 = "e56b3921eeb7a2951959c02db0912b5fcd5fdba5aca071da819e1accf338bbd7", 17 | strip_prefix = "curl-7.74.0", 18 | build_file = Label("//curl:BUILD.curl.bazel"), 19 | ) 20 | -------------------------------------------------------------------------------- /examples/third_party/curl/curl_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | // Use (void) to silent unused warnings. 7 | #define assertm(exp, msg) assert(((void)msg, exp)) 8 | 9 | int main(int argc, char* argv[]) { 10 | curl_version_info_data* data = curl_version_info(CURLVERSION_NOW); 11 | 12 | assertm(std::string(data->version) == std::string("7.74.0"), 13 | "The version of curl does not match the expected version"); 14 | assertm(std::string(data->ssl_version) == std::string("OpenSSL/1.1.1w"), 15 | "The version of openssl does not match the expected version"); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /examples/third_party/glib/BUILD: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.glib.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "glib_build_test", 12 | targets = [ 13 | "@glib//:glib", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/glib/BUILD.gettext.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "gettext", 15 | env = select({ 16 | "@platforms//os:macos": { 17 | "AR": "", 18 | }, 19 | "//conditions:default": {}, 20 | }), 21 | lib_source = ":all_srcs", 22 | out_shared_libs = select({ 23 | "@platforms//os:macos": [ 24 | "libgettextlib.dylib", 25 | "libgettextpo.0.dylib", 26 | "libasprintf.dylib", 27 | "libgettextlib-0.21.1.dylib", 28 | "libintl.dylib", 29 | "libtextstyle.0.dylib", 30 | "libintl.8.dylib", 31 | "libasprintf.0.dylib", 32 | "libgettextsrc.dylib", 33 | "libtextstyle.dylib", 34 | "libgettextsrc-0.21.1.dylib", 35 | "libgettextpo.dylib", 36 | ], 37 | "//conditions:default": [], 38 | }), 39 | out_static_libs = select({ 40 | "@platforms//os:macos": [ 41 | "libasprintf.a", 42 | "libgettextpo.a", 43 | "libintl.a", 44 | "libtextstyle.a", 45 | ], 46 | "//conditions:default": [], 47 | }), 48 | ) 49 | -------------------------------------------------------------------------------- /examples/third_party/glib/BUILD.gettext_win.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:copy_file.bzl", "copy_file") 2 | load("@rules_cc//cc:defs.bzl", "cc_import") 3 | 4 | package(default_visibility = ["//visibility:public"]) 5 | 6 | copy_file( 7 | name = "libint_dll", 8 | src = "lib/libintl.dll.a", 9 | out = "libintl.dll", 10 | ) 11 | 12 | cc_import( 13 | name = "gettext", 14 | hdrs = glob(["include/**"]), 15 | interface_library = "lib/intl.lib", 16 | shared_library = ":libint_dll", 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/glib/BUILD.libffi.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob(["**"]), 8 | ) 9 | 10 | meson( 11 | name = "libffi", 12 | lib_source = ":all_srcs", 13 | out_interface_libs = select({ 14 | "@platforms//os:windows": ["ffi.lib"], 15 | "//conditions:default": [], 16 | }), 17 | out_lib_dir = select({ 18 | "@platforms//os:linux": "lib/x86_64-linux-gnu", 19 | "//conditions:default": "lib", 20 | }), 21 | out_shared_libs = select({ 22 | "@platforms//os:linux": ["libffi.so.7.1.0"], 23 | "@platforms//os:macos": ["libffi.dylib"], 24 | "@platforms//os:windows": ["ffi-7.dll"], 25 | }), 26 | ) 27 | -------------------------------------------------------------------------------- /examples/third_party/gn/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_shell//shell:sh_test.bzl", "sh_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.curl.bazel", 6 | "patch.gen_ninja.sh", 7 | ], 8 | visibility = ["//visibility:public"], 9 | ) 10 | 11 | sh_test( 12 | name = "gn_launch_test", 13 | srcs = ["gn_test.sh"], 14 | data = ["@gn//:gn_bin"], 15 | env = { 16 | "GN": "$(rootpath @gn//:gn_bin)", 17 | }, 18 | ) 19 | -------------------------------------------------------------------------------- /examples/third_party/gn/BUILD.gn.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "ninja") 2 | 3 | filegroup( 4 | name = "srcs", 5 | srcs = glob( 6 | ["**"], 7 | exclude = ["out/**"], 8 | ) + [ 9 | "out/build.ninja", 10 | "out/build.ninja.d", 11 | "out/last_commit_position.h", 12 | ], 13 | ) 14 | 15 | config_setting( 16 | name = "windows", 17 | constraint_values = ["@platforms//os:windows"], 18 | ) 19 | 20 | ninja( 21 | name = "gn", 22 | directory = "out", 23 | lib_source = "//:srcs", 24 | out_binaries = select({ 25 | ":windows": ["gn.exe"], 26 | "//conditions:default": ["gn"], 27 | }), 28 | out_static_libs = select({ 29 | ":windows": ["gn_lib.lib"], 30 | "//conditions:default": ["gn_lib.a"], 31 | }), 32 | # gn has no install step, manually grab the artifacts 33 | postfix_script = select({ 34 | ":windows": " && ".join([ 35 | "cp -a out/gn_lib.lib $$INSTALLDIR/lib", 36 | "cp -a out/gn.exe $$INSTALLDIR/bin", 37 | ]), 38 | "//conditions:default": " && ".join([ 39 | "cp -a out/gn_lib.a $$INSTALLDIR/lib", 40 | "cp -a out/gn $$INSTALLDIR/bin", 41 | ]), 42 | }), 43 | ) 44 | 45 | filegroup( 46 | name = "gn_bin", 47 | srcs = [":gn"], 48 | output_group = select({ 49 | ":windows": "gn.exe", 50 | "//conditions:default": "gn", 51 | }), 52 | visibility = ["//visibility:public"], 53 | ) 54 | -------------------------------------------------------------------------------- /examples/third_party/gn/gn_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency gn""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def gn_repositories(): 7 | maybe( 8 | new_git_repository, 9 | name = "gn", 10 | build_file = Label("//gn:BUILD.gn.bazel"), 11 | commit = "dfcbc6fed0a8352696f92d67ccad54048ad182b3", 12 | patch_args = [], 13 | patch_tool = "bash", 14 | patches = [Label("//gn:patch.gen_ninja.sh")], 15 | remote = "https://gn.googlesource.com/gn", 16 | shallow_since = "1612864120 +0000", 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/gn/gn_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -e "$GN" ]]; then 4 | echo "gn does not exist" 5 | exit 1 6 | fi 7 | 8 | exec $GN --help 9 | -------------------------------------------------------------------------------- /examples/third_party/gn/patch.gen_ninja.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ "$OSTYPE" == "win32" ]]; then 4 | python.exe build/gen.py --no-last-commit-position 5 | else 6 | python build/gen.py --no-last-commit-position 7 | fi 8 | 9 | # Create `out/last_commit_position.h` only using shell built-in commands 10 | echo "// Generated by @rules_foreign_cc_examples_third_party//gn:generate_ninja.sh" >> out/last_commit_position.h 11 | echo "" >> out/last_commit_position.h 12 | echo "#ifndef OUT_LAST_COMMIT_POSITION_H_" >> out/last_commit_position.h 13 | echo "#define OUT_LAST_COMMIT_POSITION_H_" >> out/last_commit_position.h 14 | echo "" >> out/last_commit_position.h 15 | echo "#define LAST_COMMIT_POSITION_NUM 1891" >> out/last_commit_position.h 16 | echo "#define LAST_COMMIT_POSITION \"1891 (dfcbc6fe)\"" >> out/last_commit_position.h 17 | echo "" >> out/last_commit_position.h 18 | echo "#endif // OUT_LAST_COMMIT_POSITION_H_" >> out/last_commit_position.h 19 | echo "" >> out/last_commit_position.h 20 | -------------------------------------------------------------------------------- /examples/third_party/gperftools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | # load("@rules_cc//cc:defs.bzl", "cc_test") 3 | 4 | exports_files( 5 | [ 6 | "BUILD.gperftools.bazel", 7 | ], 8 | visibility = ["//visibility:public"], 9 | ) 10 | 11 | # TODO(rules_foreign_cc#227) This currently gives an error: 12 | # "ERROR: <...>/use_malloc/BUILD:17:14: in malloc attribute of cc_test rule //:test: 13 | # configure_make rule '@gperftools//:gperftools_build' is misplaced here (expected cc_library)" 14 | # cc_test( 15 | # name = "malloc_test", 16 | # srcs = ["malloc_test.cpp"], 17 | # malloc = "@gperftools//:gperftools_build", 18 | # ) 19 | 20 | build_test( 21 | name = "build_test", 22 | targets = [ 23 | "@gperftools//:gperftools_build", 24 | ], 25 | ) 26 | 27 | test_suite( 28 | name = "test", 29 | tests = [ 30 | ":build_test", 31 | # ":malloc_test", 32 | ], 33 | visibility = ["//:__pkg__"], 34 | ) 35 | -------------------------------------------------------------------------------- /examples/third_party/gperftools/BUILD.gperftools.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | filegroup( 4 | name = "all_srcs", 5 | srcs = glob( 6 | include = ["**"], 7 | exclude = ["*.bazel"], 8 | ), 9 | ) 10 | 11 | configure_make( 12 | name = "gperftools_build", 13 | configure_options = [ 14 | "--enable-shared=no", 15 | "--enable-frame-pointers", 16 | "--disable-libunwind", 17 | ], 18 | env = select({ 19 | "@platforms//os:macos": {"AR": ""}, 20 | "//conditions:default": {}, 21 | }), 22 | lib_source = ":all_srcs", 23 | out_static_libs = ["libtcmalloc_and_profiler.a"], 24 | visibility = ["//visibility:public"], 25 | ) 26 | -------------------------------------------------------------------------------- /examples/third_party/gperftools/gperftools_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency gperftools""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def gperftools_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "gperftools", 10 | build_file = Label("//gperftools:BUILD.gperftools.bazel"), 11 | sha256 = "1ee8c8699a0eff6b6a203e59b43330536b22bbcbe6448f54c7091e5efb0763c9", 12 | strip_prefix = "gperftools-2.7", 13 | urls = ["https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz"], 14 | ) 15 | -------------------------------------------------------------------------------- /examples/third_party/gperftools/malloc_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char* argv[]) { std::cout << "Hi there!"; } 4 | -------------------------------------------------------------------------------- /examples/third_party/iconv/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.iconv.bazel", 6 | "BUILD.iconv.macos.bazel", 7 | ], 8 | visibility = ["//visibility:public"], 9 | ) 10 | 11 | build_test( 12 | name = "iconv_linux_build_test", 13 | target_compatible_with = [ 14 | "@platforms//os:linux", 15 | ], 16 | targets = [ 17 | "@iconv//:iconv", 18 | ], 19 | visibility = ["//:__pkg__"], 20 | ) 21 | 22 | build_test( 23 | name = "iconv_macos_build_test", 24 | target_compatible_with = [ 25 | "@platforms//os:macos", 26 | ], 27 | targets = [ 28 | "@iconv_macos//:iconv", 29 | ], 30 | visibility = ["//:__pkg__"], 31 | ) 32 | -------------------------------------------------------------------------------- /examples/third_party/iconv/BUILD.iconv.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | filegroup( 4 | name = "all", 5 | srcs = glob(["**"]), 6 | ) 7 | 8 | configure_make( 9 | name = "iconv", 10 | configure_in_place = True, 11 | configure_options = [ 12 | "--enable-relocatable", 13 | "--enable-shared=no", 14 | "--enable-static=yes", 15 | ], 16 | lib_source = "@iconv//:all", 17 | out_static_libs = [ 18 | "libiconv.a", 19 | ], 20 | targets = ["install-lib"], 21 | visibility = ["//visibility:public"], 22 | ) 23 | -------------------------------------------------------------------------------- /examples/third_party/iconv/BUILD.iconv.macos.bazel: -------------------------------------------------------------------------------- 1 | """libiconv is only expected to be used on MacOS systems""" 2 | 3 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 4 | 5 | filegroup( 6 | name = "all", 7 | srcs = glob(["**"]), 8 | ) 9 | 10 | configure_make( 11 | name = "iconv", 12 | configure_in_place = True, 13 | configure_options = [ 14 | "--enable-relocatable", 15 | "--enable-shared=no", 16 | "--enable-static=yes", 17 | ], 18 | env = {"AR": ""}, 19 | lib_source = "@iconv_macos//:all", 20 | out_static_libs = [ 21 | "libiconv.a", 22 | ], 23 | targets = ["install-lib"], 24 | visibility = ["//visibility:public"], 25 | ) 26 | -------------------------------------------------------------------------------- /examples/third_party/iconv/iconv_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency iconv""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def iconv_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "iconv", 10 | urls = [ 11 | "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz", 12 | ], 13 | type = "tar.gz", 14 | sha256 = "e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04", 15 | strip_prefix = "libiconv-1.16", 16 | build_file = Label("//iconv:BUILD.iconv.bazel"), 17 | ) 18 | 19 | maybe( 20 | http_archive, 21 | name = "iconv_macos", 22 | urls = [ 23 | "https://opensource.apple.com/tarballs/libiconv/libiconv-59.tar.gz", 24 | ], 25 | type = "tar.gz", 26 | sha256 = "975f31be8eb193d5099b5fc4fc343b95c0eb83d59ffa6e5bde9454def2228a53", 27 | strip_prefix = "libiconv-libiconv-59/libiconv", 28 | build_file = Label("//iconv:BUILD.iconv.macos.bazel"), 29 | ) 30 | -------------------------------------------------------------------------------- /examples/third_party/libgit2/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.curl.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "libgit2_build_test", 12 | targets = [ 13 | "@libgit2//:libgit2", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/libgit2/BUILD.libgit2.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | filegroup( 4 | name = "all_srcs", 5 | srcs = glob( 6 | ["**"], 7 | exclude = ["tests/**"], 8 | ), 9 | ) 10 | 11 | _CACHE_ENTRIES = { 12 | "BUILD_CLAR": "off", 13 | "BUILD_EXAMPLES": "off", 14 | "BUILD_FUZZERS": "off", 15 | "BUILD_SHARED_LIBS": "off", 16 | #"EMBED_SSH_PATH": "$(location @libssh2//:libssh2)", 17 | "USE_HTTPS": "on", 18 | } 19 | 20 | _LINUX_CACHE_ENTRIES = dict(_CACHE_ENTRIES.items() + { 21 | "CMAKE_C_FLAGS": "$${CMAKE_C_FLAGS:-} -fPIC", 22 | "REGEX_BACKEND": "pcre2", 23 | }.items()) 24 | 25 | cmake( 26 | name = "libgit2", 27 | cache_entries = select({ 28 | "@platforms//os:linux": _LINUX_CACHE_ENTRIES, 29 | "//conditions:default": _CACHE_ENTRIES, 30 | }), 31 | lib_source = ":all_srcs", 32 | out_static_libs = select({ 33 | # TODO: I'm guessing at this name. Needs to be checked on windows. 34 | "@platforms//os:windows": ["git2.lib"], 35 | "//conditions:default": ["libgit2.a"], 36 | }), 37 | visibility = ["//visibility:public"], 38 | deps = [ 39 | "@libssh2", 40 | "@openssl", 41 | "@zlib", 42 | ] + select({ 43 | "@platforms//os:linux": ["@pcre"], 44 | "@platforms//os:macos": ["@iconv_macos//:iconv"], 45 | "//conditions:default": [], 46 | }), 47 | ) 48 | -------------------------------------------------------------------------------- /examples/third_party/libgit2/libgit2_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency libgit2""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def libgit2_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "libgit2", 10 | build_file = Label("//libgit2:BUILD.libgit2.bazel"), 11 | sha256 = "192eeff84596ff09efb6b01835a066f2df7cd7985e0991c79595688e6b36444e", 12 | strip_prefix = "libgit2-1.3.0", 13 | urls = [ 14 | "https://mirror.bazel.build/github.com/libgit2/libgit2/archive/refs/tags/v1.3.0.tar.gz", 15 | "https://github.com/libgit2/libgit2/archive/refs/tags/v1.3.0.tar.gz", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/libjpeg_turbo/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.libjpeg_turbo.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "libjpeg_turbo_build_test", 12 | targets = [ 13 | "@libjpeg_turbo//:libjpeg_turbo", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/libjpeg_turbo/BUILD.libjpeg_turbo.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | filegroup( 4 | name = "all_files", 5 | srcs = glob(["**"]), 6 | ) 7 | 8 | cmake( 9 | name = "libjpeg_turbo", 10 | cache_entries = { 11 | "CMAKE_BUILD_TYPE": "Release", 12 | "WITH_JAVA": "0", 13 | }, 14 | lib_source = ":all_files", 15 | out_shared_libs = select({ 16 | "@platforms//os:linux": [ 17 | "libjpeg.so", 18 | "libturbojpeg.so", 19 | ], 20 | "@platforms//os:macos": [ 21 | "libjpeg.dylib", 22 | "libturbojpeg.dylib", 23 | ], 24 | "@platforms//os:windows": [ 25 | "libjpeg.dll", 26 | "libturbojpeg.dll", 27 | ], 28 | }), 29 | visibility = ["//visibility:public"], 30 | ) 31 | -------------------------------------------------------------------------------- /examples/third_party/libjpeg_turbo/libjpeg_turbo_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency libjpeg_turbo""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def libjpeg_turbo_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "libjpeg_turbo", 10 | sha256 = "6a965adb02ad898b2ae48214244618fe342baea79db97157fdc70d8844ac6f09", 11 | strip_prefix = "libjpeg-turbo-2.0.90", 12 | urls = [ 13 | "https://mirror.bazel.build/github.com/libjpeg-turbo/libjpeg-turbo/archive/2.0.90.tar.gz", 14 | "https://github.com/libjpeg-turbo/libjpeg-turbo/archive/2.0.90.tar.gz", 15 | ], 16 | build_file = Label("//libjpeg_turbo:BUILD.libjpeg_turbo.bazel"), 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/libpng/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_binary") 2 | load("@rules_shell//shell:sh_test.bzl", "sh_test") 3 | 4 | cc_binary( 5 | name = "libpng_usage_example", 6 | srcs = ["libpng_usage_example.cpp"], 7 | deps = [ 8 | "@libpng", 9 | "@zlib", 10 | ], 11 | ) 12 | 13 | sh_test( 14 | name = "test_libpng", 15 | srcs = ["test_libpng.sh"], 16 | args = [ 17 | "$(location :libpng_usage_example)", 18 | "$(location bazel_icon_transparent.png)", 19 | "out.png", 20 | ], 21 | data = [ 22 | "bazel_icon_transparent.png", 23 | ":libpng_usage_example", 24 | ], 25 | visibility = ["//:__pkg__"], 26 | ) 27 | -------------------------------------------------------------------------------- /examples/third_party/libpng/BUILD.libpng.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | cmake( 14 | name = "libpng", 15 | cache_entries = { 16 | "CMAKE_BUILD_TYPE": "RELEASE", 17 | "CMAKE_POLICY_DEFAULT_CMP0074": "NEW", 18 | "ZLIB_ROOT": "$$EXT_BUILD_DEPS/zlib", 19 | }, 20 | lib_source = "//:all_srcs", 21 | out_include_dir = "include/libpng16", 22 | out_static_libs = ["libpng16.a"], 23 | deps = ["@zlib"], 24 | ) 25 | -------------------------------------------------------------------------------- /examples/third_party/libpng/bazel_icon_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/examples/third_party/libpng/bazel_icon_transparent.png -------------------------------------------------------------------------------- /examples/third_party/libpng/libpng_repositories.bzl: -------------------------------------------------------------------------------- 1 | # buildifier: disable=module-docstring 2 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 4 | 5 | def libpng_repositories(): 6 | """Load all repositories needed for libpng""" 7 | maybe( 8 | http_archive, 9 | name = "libpng", 10 | build_file = Label("//libpng:BUILD.libpng.bazel"), 11 | sha256 = "", 12 | strip_prefix = "libpng-1.6.43", 13 | urls = [ 14 | "https://downloads.sourceforge.net/project/libpng/libpng16/1.6.43/libpng-1.6.43.tar.xz", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/libpng/test_libpng.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | $1 $2 $3 6 | -------------------------------------------------------------------------------- /examples/third_party/libssh2/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.libssh2.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "libssh2_build_test", 12 | targets = [ 13 | "@libssh2//:libssh2", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/libssh2/BUILD.libssh2.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 2 | 3 | filegroup( 4 | name = "all_srcs", 5 | srcs = glob( 6 | include = ["**"], 7 | exclude = ["*.bazel"], 8 | ), 9 | ) 10 | 11 | _CACHE_ENTRIES = { 12 | "BUILD_EXAMPLES": "off", 13 | "BUILD_SHARED_LIBS": "off", 14 | "BUILD_TESTING": "off", 15 | "CMAKE_FIND_DEBUG_MODE": "on", 16 | } 17 | 18 | _LINUX_CACHE_ENTRIES = dict(_CACHE_ENTRIES.items() + { 19 | "CMAKE_C_FLAGS": "$${CMAKE_C_FLAGS:-} -fPIC", 20 | }.items()) 21 | 22 | cmake( 23 | name = "libssh2", 24 | cache_entries = select({ 25 | "@platforms//os:linux": _LINUX_CACHE_ENTRIES, 26 | "//conditions:default": _CACHE_ENTRIES, 27 | }), 28 | lib_source = ":all_srcs", 29 | out_static_libs = select({ 30 | # TODO: I'm guessing at this name. Needs to be checked on windows. 31 | "@platforms//os:windows": ["ssh2.lib"], 32 | "//conditions:default": ["libssh2.a"], 33 | }), 34 | visibility = ["//visibility:public"], 35 | deps = ["@openssl"], 36 | ) 37 | -------------------------------------------------------------------------------- /examples/third_party/libssh2/libssh2_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency libssh2""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def libssh2_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "libssh2", 10 | urls = [ 11 | "https://mirror.bazel.build/github.com/libssh2/libssh2/releases/download/libssh2-1.9.0/libssh2-1.9.0.tar.gz", 12 | "https://github.com/libssh2/libssh2/releases/download/libssh2-1.9.0/libssh2-1.9.0.tar.gz", 13 | ], 14 | type = "tar.gz", 15 | sha256 = "d5fb8bd563305fd1074dda90bd053fb2d29fc4bce048d182f96eaa466dfadafd", 16 | strip_prefix = "libssh2-1.9.0", 17 | build_file = Label("//libssh2:BUILD.libssh2.bazel"), 18 | ) 19 | -------------------------------------------------------------------------------- /examples/third_party/log4cxx/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.log4cxx.bazel", 6 | "consoloe.cpp.patch", 7 | "inputstreamreader.cpp.patch", 8 | "simpledateformat.h.patch", 9 | "socketoutputstream.cpp.patch", 10 | ], 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | build_test( 15 | name = "log4cxx_build_test", 16 | targets = [ 17 | "@log4cxx//:log4cxx", 18 | ], 19 | visibility = ["//:__pkg__"], 20 | ) 21 | -------------------------------------------------------------------------------- /examples/third_party/log4cxx/BUILD.log4cxx.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | filegroup( 4 | name = "all_srcs", 5 | srcs = glob( 6 | include = ["**"], 7 | exclude = ["*.bazel"], 8 | ), 9 | ) 10 | 11 | configure_make( 12 | name = "log4cxx", 13 | configure_options = [ 14 | "--disable-shared", 15 | "--with-apr=$$EXT_BUILD_DEPS/apr", 16 | "--with-apr-util=$$EXT_BUILD_DEPS/apr_util", 17 | ], 18 | env = select({ 19 | "@platforms//os:macos": { 20 | "AR": "", 21 | "CXXFLAGS": "-Wno-c++11-narrowing", 22 | }, 23 | "//conditions:default": { 24 | "CXXFLAGS": "-Wno-narrowing", 25 | }, 26 | }), 27 | lib_source = ":all_srcs", 28 | out_static_libs = ["liblog4cxx.a"], 29 | visibility = ["//visibility:public"], 30 | deps = [ 31 | "@apr", 32 | "@apr_util", 33 | ], 34 | ) 35 | -------------------------------------------------------------------------------- /examples/third_party/log4cxx/console.cpp.patch: -------------------------------------------------------------------------------- 1 | --- src/examples/cpp/console.cpp 2008-03-31 23:34:09.000000000 +0100 2 | +++ src/examples/cpp/console.cpp 2008-03-31 23:34:09.000000000 +0100 3 | @@ -22,6 +22,7 @@ 4 | #include 5 | #include 6 | #include 7 | +#include 8 | 9 | using namespace log4cxx; 10 | using namespace log4cxx::helpers; -------------------------------------------------------------------------------- /examples/third_party/log4cxx/inputstreamreader.cpp.patch: -------------------------------------------------------------------------------- 1 | --- src/main/cpp/inputstreamreader.cpp 2008-03-31 23:34:09.000000000 +0100 2 | +++ src/main/cpp/inputstreamreader.cpp 2008-03-31 23:34:09.000000000 +0100 3 | @@ -20,6 +20,8 @@ 4 | #include 5 | #include 6 | #include 7 | +#include 8 | +#include 9 | 10 | using namespace log4cxx; 11 | using namespace log4cxx::helpers; -------------------------------------------------------------------------------- /examples/third_party/log4cxx/log4cxx_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency apr""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def log4cxx_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "log4cxx", 10 | build_file = Label("//log4cxx:BUILD.log4cxx.bazel"), 11 | sha256 = "0de0396220a9566a580166e66b39674cb40efd2176f52ad2c65486c99c920c8c", 12 | strip_prefix = "apache-log4cxx-0.10.0", 13 | patches = [ 14 | # See https://issues.apache.org/jira/browse/LOGCXX-360 15 | Label("//log4cxx:console.cpp.patch"), 16 | Label("//log4cxx:inputstreamreader.cpp.patch"), 17 | Label("//log4cxx:socketoutputstream.cpp.patch"), 18 | 19 | # Required for building on MacOS 20 | Label("//log4cxx:simpledateformat.h.patch"), 21 | ], 22 | urls = [ 23 | "https://mirror.bazel.build/archive.apache.org/dist/logging/log4cxx/0.10.0/apache-log4cxx-0.10.0.tar.gz", 24 | "https://archive.apache.org/dist/logging/log4cxx/0.10.0/apache-log4cxx-0.10.0.tar.gz", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /examples/third_party/log4cxx/simpledateformat.h.patch: -------------------------------------------------------------------------------- 1 | --- src/main/include/log4cxx/helpers/simpledateformat.h 2008-03-31 23:34:26.000000000 +0100 2 | +++ src/main/include/log4cxx/helpers/simpledateformat.h 2008-03-31 23:34:26.000000000 +0100 3 | @@ -27,10 +27,9 @@ 4 | 5 | #include 6 | #include 7 | +#include 8 | #include 9 | 10 | -namespace std { class locale; } 11 | - 12 | namespace log4cxx 13 | { 14 | namespace helpers -------------------------------------------------------------------------------- /examples/third_party/log4cxx/socketoutputstream.cpp.patch: -------------------------------------------------------------------------------- 1 | --- src/main/cpp/socketoutputstream.cpp 2008-03-31 23:34:09.000000000 +0100 2 | +++ src/main/cpp/socketoutputstream.cpp 2008-03-31 23:34:09.000000000 +0100 3 | @@ -19,6 +19,7 @@ 4 | #include 5 | #include 6 | #include 7 | +#include 8 | 9 | using namespace log4cxx; 10 | using namespace log4cxx::helpers; -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.mesa.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "mesa_build_test", 12 | targets = [ 13 | "@mesa//:mesa", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.flex.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "flex", 15 | build_data = select({ 16 | "@platforms//os:windows": [], 17 | "//conditions:default": ["@m4//:m4_exe"], 18 | }), 19 | configure_options = select({ 20 | # See https://github.com/westes/flex/issues/428#issuecomment-539277966 21 | "@platforms//os:linux": ["CFLAGS='-D_GNU_SOURCE'"], 22 | "//conditions:default": [], 23 | }), 24 | env = select({ 25 | "@platforms//os:linux": { 26 | "PATH": "$$(dirname $$EXT_BUILD_ROOT$$/$(location @m4//:m4_exe)):$$PATH", 27 | }, 28 | "@platforms//os:macos": { 29 | "AR": "", 30 | "PATH": "$$(dirname $$EXT_BUILD_ROOT$$/$(location @m4//:m4_exe)):$$PATH", 31 | }, 32 | "//conditions:default": {}, 33 | }), 34 | lib_source = ":all_srcs", 35 | out_binaries = ["flex"], 36 | ) 37 | 38 | filegroup( 39 | name = "flex_exe", 40 | srcs = [":flex"], 41 | output_group = "flex", 42 | ) 43 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libdrm.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob(["**"]), 8 | ) 9 | 10 | meson( 11 | name = "libdrm", 12 | lib_source = ":all_srcs", 13 | out_lib_dir = "lib/x86_64-linux-gnu", 14 | out_shared_libs = [ 15 | "libdrm_amdgpu.so.1.0.0", 16 | "libdrm_intel.so.1.0.0", 17 | "libdrm_nouveau.so.2.0.0", 18 | "libdrm_nouveau.so", 19 | "libdrm_nouveau.so.2", 20 | "libdrm_radeon.so.1.0.1", 21 | "libdrm.so.2.4.0", 22 | "libdrm.so", 23 | "libdrm.so.2", 24 | ], 25 | deps = ["@libpciaccess"], 26 | ) 27 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libpciaccess.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libpciaccess", 15 | lib_source = ":all_srcs", 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libpthread-stubs.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libpthread-stubs", 15 | lib_source = ":all_srcs", 16 | out_headers_only = True, 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libx11.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libx11", 15 | env = select({ 16 | "@platforms//os:macos": { 17 | "AR": "", 18 | }, 19 | "//conditions:default": {}, 20 | }), 21 | lib_source = ":all_srcs", 22 | out_headers_only = True, 23 | deps = [ 24 | "@libxau", 25 | "@libxcb", 26 | "@xorgproto", 27 | "@xtrans", 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxau.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libxau", 15 | env = select({ 16 | "@platforms//os:macos": { 17 | "AR": "", 18 | }, 19 | "//conditions:default": {}, 20 | }), 21 | lib_source = ":all_srcs", 22 | out_headers_only = True, 23 | deps = [ 24 | "@xorgproto", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxcb.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | DEPS = [ 14 | "@libxau", 15 | "@xcb-proto", 16 | ] 17 | 18 | configure_make( 19 | name = "libxcb", 20 | env = select({ 21 | "@platforms//os:macos": { 22 | "AR": "", 23 | }, 24 | "//conditions:default": {}, 25 | }), 26 | lib_source = ":all_srcs", 27 | deps = select({ 28 | "@platforms//os:macos": DEPS + ["@libpthread-stubs"], 29 | "//conditions:default": DEPS, 30 | }), 31 | ) 32 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxdmcp.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libxdmcp", 15 | lib_source = ":all_srcs", 16 | out_headers_only = True, 17 | deps = [ 18 | "@xorgproto", 19 | ], 20 | ) 21 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxext.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libxext", 15 | env = select({ 16 | "@platforms//os:macos": { 17 | "AR": "", 18 | }, 19 | "//conditions:default": {}, 20 | }), 21 | lib_source = ":all_srcs", 22 | out_headers_only = True, 23 | deps = [ 24 | "@libx11", 25 | "@xorgproto", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxfixes.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libxfixes", 15 | env = select({ 16 | "@platforms//os:macos": { 17 | "AR": "", 18 | }, 19 | "//conditions:default": {}, 20 | }), 21 | lib_source = ":all_srcs", 22 | out_static_libs = [ 23 | "libXfixes.a", 24 | ], 25 | deps = [ 26 | "@libx11", 27 | "@xorgproto", 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxrandr.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libxrandr", 15 | lib_source = ":all_srcs", 16 | out_headers_only = True, 17 | deps = [ 18 | "@libx11", 19 | "@libxext", 20 | "@libxrender", 21 | "@renderproto", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxrender.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libxrender", 15 | lib_source = ":all_srcs", 16 | out_headers_only = True, 17 | deps = [ 18 | "@libx11", 19 | "@renderproto", 20 | ], 21 | ) 22 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.libxshmfence.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "libxshmfence", 15 | lib_source = ":all_srcs", 16 | deps = [ 17 | "@xorgproto", 18 | ], 19 | ) 20 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.renderproto.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "renderproto", 15 | lib_source = ":all_srcs", 16 | out_headers_only = True, 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.winflexbison.bazel: -------------------------------------------------------------------------------- 1 | #load("@bazel_skylib//rules:native_binary.bzl", "native_binary") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 3 | 4 | filegroup( 5 | name = "all_srcs", 6 | # The winflexbison build outputs to the source tree, ignore the generated folder otherwise winflexbison will be rebuilt on every bazel invocation 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["bin/**"], 10 | ), 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | cmake( 15 | name = "winflexbison", 16 | generate_args = select({ 17 | "@platforms//os:windows": ["-GNinja"], 18 | "//conditions:default": [], 19 | }), 20 | lib_source = ":all_srcs", 21 | out_bin_dir = "", 22 | out_binaries = [ 23 | "win_flex.exe", 24 | "win_bison.exe", 25 | ], 26 | visibility = ["//visibility:public"], 27 | ) 28 | 29 | filegroup( 30 | name = "gen_dir", 31 | srcs = [":winflexbison"], 32 | output_group = "gen_dir", 33 | visibility = ["//visibility:public"], 34 | ) 35 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.xcb-proto.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "xcb-proto", 15 | lib_source = ":all_srcs", 16 | # Dependents of xcb-proto require this lib dir to be present in the bazel sandbox 17 | out_data_dirs = ["lib"], 18 | out_headers_only = True, 19 | ) 20 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.xorgproto.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "xorgproto", 15 | lib_source = ":all_srcs", 16 | out_headers_only = True, 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/mesa/BUILD.xtrans.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "xtrans", 15 | lib_source = ":all_srcs", 16 | out_headers_only = True, 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.meson.build.patch: -------------------------------------------------------------------------------- 1 | --- meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ meson.build 2022-11-30 17:26:50.607789896 +0000 3 | @@ -1002,7 +1002,7 @@ 4 | ] 5 | endif 6 | 7 | -prog_python = import('python').find_installation('python3') 8 | +prog_python = import('python').find_installation() 9 | has_mako = run_command( 10 | prog_python, '-c', 11 | ''' 12 | @@ -2033,6 +2033,7 @@ 13 | endif 14 | 15 | if with_platform_x11 16 | + dep_x11 = dependency('x11') 17 | if with_glx == 'xlib' or with_glx == 'gallium-xlib' 18 | dep_x11 = dependency('x11') 19 | dep_xext = dependency('xext') -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_egl_meson.build.patch: -------------------------------------------------------------------------------- 1 | --- src/egl/meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/egl/meson.build 2022-12-05 14:21:05.700235372 +0000 3 | @@ -106,7 +106,7 @@ 4 | files_egl += files('drivers/dri2/platform_x11_dri3.c') 5 | link_for_egl += libloader_dri3_helper 6 | endif 7 | - deps_for_egl += [dep_x11_xcb, dep_xcb_dri2, dep_xcb_xfixes] 8 | + deps_for_egl += [dep_x11_xcb, dep_xcb_dri2, dep_xcb_xfixes, dep_xlib_xrandr] 9 | endif 10 | if with_gbm and not with_platform_android 11 | files_egl += files('drivers/dri2/platform_drm.c') 12 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_gallium_frontends_dri_dri_util.c.patch: -------------------------------------------------------------------------------- 1 | --- src/gallium/frontends/dri/dri_util.c 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/gallium/frontends/dri/dri_util.c 2022-12-12 12:58:00.161799118 +0000 3 | @@ -171,6 +171,8 @@ 4 | return psp; 5 | } 6 | 7 | +#if defined(HAVE_LIBDRM) 8 | + 9 | static __DRIscreen * 10 | dri2CreateNewScreen(int scrn, int fd, 11 | const __DRIextension **extensions, 12 | @@ -191,6 +193,8 @@ 13 | driver_configs, data); 14 | } 15 | 16 | +#endif 17 | + 18 | /** swrast driver createNewScreen entrypoint. */ 19 | static __DRIscreen * 20 | driSWRastCreateNewScreen(int scrn, const __DRIextension **extensions, 21 | @@ -808,6 +812,8 @@ 22 | .unbindContext = driUnbindContext 23 | }; 24 | 25 | +#if defined(HAVE_LIBDRM) 26 | + 27 | /** DRI2 interface */ 28 | const __DRIdri2Extension driDRI2Extension = { 29 | .base = { __DRI_DRI2, 4 }, 30 | @@ -837,6 +843,8 @@ 31 | .createNewScreen2 = driCreateNewScreen2, 32 | }; 33 | 34 | +#endif 35 | + 36 | const __DRIswrastExtension driSWRastExtension = { 37 | .base = { __DRI_SWRAST, 4 }, 38 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_gallium_frontends_dri_meson.build.patch: -------------------------------------------------------------------------------- 1 | --- src/gallium/frontends/dri/meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/gallium/frontends/dri/meson.build 2022-12-05 13:22:50.210313339 +0000 3 | @@ -71,6 +71,9 @@ 4 | dependencies : [ 5 | dep_libdrm, 6 | idep_mesautil, 7 | + dep_xcb, 8 | + dep_x11, 9 | + dep_xlib_xrandr 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_gallium_targets_dri_meson.build.patch: -------------------------------------------------------------------------------- 1 | --- src/gallium/targets/dri/meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/gallium/targets/dri/meson.build 2022-12-05 14:02:15.710260576 +0000 3 | @@ -58,7 +58,7 @@ 4 | driver_kmsro, driver_v3d, driver_vc4, driver_freedreno, driver_etnaviv, 5 | driver_tegra, driver_i915, driver_svga, driver_virgl, 6 | driver_panfrost, driver_iris, driver_lima, driver_zink, driver_d3d12, 7 | - driver_asahi, driver_crocus 8 | + driver_asahi, driver_crocus, dep_xcb, dep_x11, dep_xlib_xrandr 9 | ], 10 | # Will be deleted during installation, see install_megadrivers.py 11 | install : true, 12 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_gbm_meson.build.patch: -------------------------------------------------------------------------------- 1 | 2 | --- src/gbm/meson.build 2022-07-15 18:42:47.000000000 +0100 3 | +++ src/gbm/meson.build 2022-12-05 13:01:49.660341456 +0000 4 | @@ -44,6 +44,9 @@ 5 | deps_gbm += dep_wayland_server 6 | incs_gbm += inc_wayland_drm 7 | endif 8 | +if with_platform_x11 9 | + deps_gbm += [dep_xcb, dep_x11, dep_xlib_xrandr] 10 | +endif 11 | 12 | libgbm = shared_library( 13 | 'gbm', 14 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_glx_meson.build.patch: -------------------------------------------------------------------------------- 1 | --- src/glx/meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/glx/meson.build 2022-12-12 09:36:07.300346991 +0000 3 | @@ -136,7 +136,7 @@ 4 | ], 5 | dependencies : [ 6 | idep_mesautil, idep_xmlconfig, 7 | - dep_libdrm, dep_dri2proto, dep_glproto, dep_x11, dep_glvnd, 8 | + dep_libdrm, dep_dri2proto, dep_glproto, dep_x11, dep_glvnd, dep_xext, 9 | ], 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_intel_vulkan_meson.build.patch: -------------------------------------------------------------------------------- 1 | --- src/intel/vulkan/meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/intel/vulkan/meson.build 2022-11-30 18:21:07.247725902 +0000 3 | @@ -95,7 +95,7 @@ 4 | dependencies : [ 5 | dep_libdrm, dep_valgrind, idep_nir_headers, idep_genxml, 6 | idep_vulkan_util_headers, idep_vulkan_wsi_headers, 7 | - idep_vulkan_runtime_headers, idep_intel_driver_ds_headers, 8 | + idep_vulkan_runtime_headers, idep_intel_driver_ds_headers, dep_x11, 9 | ], 10 | ) 11 | endforeach 12 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_loader_meson.build.patch: -------------------------------------------------------------------------------- 1 | --- src/loader/meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/loader/meson.build 2022-11-30 17:26:20.047790496 +0000 3 | @@ -28,7 +28,7 @@ 4 | include_directories : [inc_include, inc_src], 5 | dependencies : [ 6 | dep_libdrm, dep_xcb_dri3, dep_xcb_present, dep_xcb_sync, dep_xshmfence, 7 | - dep_xcb_xfixes, 8 | + dep_xcb_xfixes, dep_x11_xcb 9 | ], 10 | build_by_default : false, 11 | ) 12 | -------------------------------------------------------------------------------- /examples/third_party/mesa/mesa.src_vulkan_util_meson.build.patch: -------------------------------------------------------------------------------- 1 | --- src/vulkan/util/meson.build 2022-07-15 18:42:47.000000000 +0100 2 | +++ src/vulkan/util/meson.build 2022-11-30 17:35:23.627779815 +0000 3 | @@ -105,7 +105,8 @@ 4 | 5 | idep_vulkan_util_headers = declare_dependency( 6 | sources : [vk_dispatch_table[1], vk_enum_to_str[1], vk_extensions[1]], 7 | - include_directories : include_directories('.') 8 | + include_directories : include_directories('.'), 9 | + dependencies : [dep_xcb, dep_x11, dep_xlib_xrandr] 10 | ) 11 | 12 | idep_vulkan_util = declare_dependency( 13 | -------------------------------------------------------------------------------- /examples/third_party/openssl/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | load("@rules_cc//cc:defs.bzl", "cc_test") 3 | load("@rules_shell//shell:sh_test.bzl", "sh_test") 4 | 5 | exports_files( 6 | [ 7 | "BUILD.openssl.bazel", 8 | ], 9 | visibility = ["//visibility:public"], 10 | ) 11 | 12 | cc_test( 13 | name = "openssl_test", 14 | srcs = ["openssl_test.cc"], 15 | linkopts = select({ 16 | "@openssl//:msvc_compiler": [ 17 | "advapi32.lib", 18 | "user32.lib", 19 | ], 20 | "//conditions:default": [], 21 | }), 22 | deps = ["@openssl"], 23 | ) 24 | 25 | build_test( 26 | name = "build_test", 27 | targets = [ 28 | "@openssl//:openssl", 29 | "@openssl//:runnable_openssl", 30 | ], 31 | visibility = ["//:__pkg__"], 32 | ) 33 | 34 | sh_test( 35 | name = "openssl_launch_test", 36 | srcs = ["openssl_test.sh"], 37 | data = ["@openssl//:runnable_openssl"], 38 | env = { 39 | "OPENSSL": "$(rootpath @openssl//:runnable_openssl)", 40 | }, 41 | ) 42 | 43 | test_suite( 44 | name = "openssl_test_suite", 45 | tests = [ 46 | ":build_test", 47 | ":openssl_launch_test", 48 | ":openssl_test", 49 | ], 50 | visibility = ["//:__pkg__"], 51 | ) 52 | -------------------------------------------------------------------------------- /examples/third_party/openssl/BUILD.nasm.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:select_file.bzl", "select_file") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | select_file( 14 | name = "nasm", 15 | srcs = ":all_srcs", 16 | subpath = "nasm.exe", 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/openssl/openssl_setup.bzl: -------------------------------------------------------------------------------- 1 | """A module initialising the third party dependencies OpenSSL""" 2 | 3 | load("@rules_perl//perl:deps.bzl", "perl_register_toolchains", "perl_rules_dependencies") 4 | 5 | def openssl_setup(): 6 | perl_rules_dependencies() 7 | perl_register_toolchains() 8 | -------------------------------------------------------------------------------- /examples/third_party/openssl/openssl_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -e "$OPENSSL" ]]; then 4 | echo "openssl does not exist" 5 | exit 1 6 | fi 7 | 8 | exec $OPENSSL help 9 | -------------------------------------------------------------------------------- /examples/third_party/pcre/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.pcre.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "pcre_build_test", 12 | tags = ["manual"], # Linux Only 13 | targets = [ 14 | "@pcre//:pcre", 15 | ], 16 | visibility = ["//:__pkg__"], 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/pcre/BUILD.pcre.bazel: -------------------------------------------------------------------------------- 1 | """pcre is only expected to be used on Linux systems""" 2 | 3 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 4 | 5 | package(default_visibility = ["//visibility:public"]) 6 | 7 | filegroup( 8 | name = "all_srcs", 9 | srcs = glob( 10 | include = ["**"], 11 | exclude = ["*.bazel"], 12 | ), 13 | ) 14 | 15 | cmake( 16 | name = "pcre", 17 | cache_entries = { 18 | "CMAKE_C_FLAGS": "$${CMAKE_C_FLAGS:-} -fPIC", 19 | }, 20 | lib_source = ":all_srcs", 21 | out_static_libs = select({ 22 | "@platforms//os:windows": ["pcre2-8.lib"], 23 | "//conditions:default": ["libpcre2-8.a"], 24 | }), 25 | ) 26 | 27 | filegroup( 28 | name = "pcre_dir", 29 | srcs = [ 30 | ":pcre", 31 | ], 32 | output_group = "gen_dir", 33 | ) 34 | -------------------------------------------------------------------------------- /examples/third_party/pcre/pcre_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency PCRE""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def pcre_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "pcre", 10 | build_file = Label("//pcre:BUILD.pcre.bazel"), 11 | strip_prefix = "pcre2-10.37", 12 | sha256 = "04e214c0c40a97b8a5c2b4ae88a3aa8a93e6f2e45c6b3534ddac351f26548577", 13 | urls = [ 14 | "https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.37/pcre2-10.37.tar.gz", 15 | ], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/python/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.python3.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "build_test", 12 | targets = [ 13 | "@python3//:python3", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | 18 | test_suite( 19 | name = "python_tests", 20 | tests = [ 21 | ":build_test", 22 | ], 23 | visibility = ["//:__pkg__"], 24 | ) 25 | -------------------------------------------------------------------------------- /examples/third_party/python/BUILD.python3.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | package(default_visibility = ["//visibility:public"]) 4 | 5 | filegroup( 6 | name = "all_srcs", 7 | srcs = glob( 8 | include = ["**"], 9 | exclude = ["*.bazel"], 10 | ), 11 | ) 12 | 13 | configure_make( 14 | name = "python3", 15 | configure_options = [ 16 | "CFLAGS='-Dredacted=\"redacted\"'", 17 | "--with-openssl=$$EXT_BUILD_DEPS/openssl", 18 | "--with-zlib=$$EXT_BUILD_DEPS/zlib", 19 | "--enable-optimizations", 20 | ], 21 | env = select({ 22 | "@platforms//os:macos": {"AR": ""}, 23 | "//conditions:default": {}, 24 | }), 25 | features = select({ 26 | "@platforms//os:macos": ["-headerpad"], 27 | "//conditions:default": {}, 28 | }), 29 | # rules_foreign_cc defaults the install_prefix to "python". This conflicts with the "python" executable that is generated. 30 | install_prefix = "py_install", 31 | lib_source = ":all_srcs", 32 | out_binaries = [ 33 | "python3.10", 34 | ], 35 | out_data_dirs = ["lib"], 36 | deps = [ 37 | "@openssl", 38 | "@zlib", 39 | ], 40 | ) 41 | -------------------------------------------------------------------------------- /examples/third_party/python/python_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency Python""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | # buildifier: disable=unnamed-macro 7 | def python_repositories(): 8 | maybe( 9 | http_archive, 10 | name = "python3", 11 | build_file = Label("//python:BUILD.python3.bazel"), 12 | strip_prefix = "Python-3.10.1", 13 | urls = [ 14 | "https://www.python.org/ftp/python/3.10.1/Python-3.10.1.tgz", 15 | ], 16 | sha256 = "b76117670e7c5064344b9c138e141a377e686b9063f3a8a620ff674fa8ec90d3", 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/setup.bzl: -------------------------------------------------------------------------------- 1 | """A centralized module initializing repositories required for third party examples of rules_foreign_cc which require loading from repositories which themselves were loaded in repositories.bzl.""" 2 | 3 | load("//openssl:openssl_setup.bzl", "openssl_setup") 4 | 5 | def setup(): 6 | openssl_setup() 7 | -------------------------------------------------------------------------------- /examples/third_party/sqlite/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.sqlite.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "sqlite_build_test", 12 | targets = [ 13 | "@sqlite//:sqlite", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/sqlite/BUILD.sqlite.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 2 | 3 | filegroup( 4 | name = "all_srcs", 5 | srcs = glob( 6 | include = ["**"], 7 | exclude = ["*.bazel"], 8 | ), 9 | ) 10 | 11 | configure_make( 12 | name = "sqlite", 13 | env = select({ 14 | "@platforms//os:macos": {"AR": ""}, 15 | "//conditions:default": {}, 16 | }), 17 | lib_source = ":all_srcs", 18 | out_static_libs = ["libsqlite3.a"], 19 | visibility = ["//visibility:public"], 20 | ) 21 | -------------------------------------------------------------------------------- /examples/third_party/sqlite/sqlite_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency sqlite""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def sqlite_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "sqlite", 10 | build_file = Label("//sqlite:BUILD.sqlite.bazel"), 11 | sha256 = "f52b72a5c319c3e516ed7a92e123139a6e87af08a2dc43d7757724f6132e6db0", 12 | strip_prefix = "sqlite-autoconf-3350500", 13 | urls = [ 14 | "https://mirror.bazel.build/www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz", 15 | "https://www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/subversion/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | exports_files( 4 | [ 5 | "BUILD.subversion.bazel", 6 | ], 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | build_test( 11 | name = "subversion_build_test", 12 | targets = [ 13 | "@subversion//:subversion", 14 | ], 15 | visibility = ["//:__pkg__"], 16 | ) 17 | -------------------------------------------------------------------------------- /examples/third_party/subversion/BUILD.subversion.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//lib:dicts.bzl", "dicts") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") 3 | 4 | filegroup( 5 | name = "all_srcs", 6 | srcs = glob( 7 | include = ["**"], 8 | exclude = ["*.bazel"], 9 | ), 10 | ) 11 | 12 | CONFIGURE_ENV_VARS = { 13 | "CFLAGS": "-Dredacted='\\\"redacted\\\"'", 14 | "CXXFLAGS": "-Dredacted='\\\"redacted\\\"'", 15 | } 16 | 17 | configure_make( 18 | name = "subversion", 19 | configure_options = [ 20 | "--enable-all-static", 21 | "--without-boost", 22 | "--with-apr=$$EXT_BUILD_DEPS/apr", 23 | "--with-apr-util=$$EXT_BUILD_DEPS/apr_util", 24 | "--with-zlib=$$EXT_BUILD_DEPS/zlib", 25 | "--with-lz4=internal", 26 | "--with-utf8proc=internal", 27 | "--enable-optimize", 28 | "--disable-nls", 29 | ], 30 | env = select({ 31 | "@platforms//os:macos": dicts.add( 32 | {"AR": ""}, 33 | CONFIGURE_ENV_VARS, 34 | ), 35 | "//conditions:default": CONFIGURE_ENV_VARS, 36 | }), 37 | lib_source = ":all_srcs", 38 | out_binaries = [ 39 | "svn", 40 | "svnversion", 41 | ], 42 | targets = [ 43 | "bin", 44 | "install", 45 | ], 46 | visibility = ["//visibility:public"], 47 | deps = [ 48 | "@apr", 49 | "@apr_util", 50 | "@sqlite", 51 | "@zlib", 52 | ], 53 | ) 54 | -------------------------------------------------------------------------------- /examples/third_party/subversion/subversion_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency subversion""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def subversion_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "subversion", 10 | build_file = Label("//subversion:BUILD.subversion.bazel"), 11 | sha256 = "dee2796abaa1f5351e6cc2a60b1917beb8238af548b20d3e1ec22760ab2f0cad", 12 | strip_prefix = "subversion-1.14.1", 13 | urls = [ 14 | "https://mirror.bazel.build/downloads.apache.org/subversion/subversion-1.14.1.tar.gz", 15 | "https://downloads.apache.org/subversion/subversion-1.14.1.tar.gz", 16 | ], 17 | ) 18 | -------------------------------------------------------------------------------- /examples/third_party/zlib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_cc//cc:defs.bzl", "cc_binary") 2 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "runnable_binary") 3 | load("@rules_shell//shell:sh_test.bzl", "sh_test") 4 | 5 | exports_files( 6 | [ 7 | "BUILD.zlib.bazel", 8 | ], 9 | visibility = ["//visibility:public"], 10 | ) 11 | 12 | filegroup( 13 | name = "shared_usage_srcs", 14 | srcs = [ 15 | "CMakeLists.txt", 16 | "zlib-example.cpp", 17 | ], 18 | visibility = ["//visibility:public"], 19 | ) 20 | 21 | cc_binary( 22 | name = "zlib_usage_example", 23 | srcs = ["zlib-example.cpp"], 24 | deps = ["@zlib"], 25 | ) 26 | 27 | sh_test( 28 | name = "test_zlib", 29 | srcs = ["test_zlib.sh"], 30 | data = [":zlib_usage_example"], 31 | visibility = ["//:__pkg__"], 32 | ) 33 | 34 | cmake( 35 | name = "zlib_shared_usage_example", 36 | dynamic_deps = ["@zlib//:zlib_shared"], 37 | lib_source = "shared_usage_srcs", 38 | out_binaries = ["zlib-example"], 39 | deps = ["@zlib//:zlib_static"], 40 | ) 41 | 42 | runnable_binary( 43 | name = "run-zlib-example", 44 | binary = "zlib-example", 45 | foreign_cc_target = ":zlib_shared_usage_example", 46 | ) 47 | 48 | sh_test( 49 | name = "test_shared_zlib", 50 | srcs = ["test_shared_zlib.sh"], 51 | data = [":run-zlib-example"], 52 | visibility = ["//:__pkg__"], 53 | ) 54 | -------------------------------------------------------------------------------- /examples/third_party/zlib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(zlib-example) 4 | 5 | find_package(ZLIB REQUIRED) 6 | 7 | set(SRCS zlib-example.cpp) 8 | 9 | add_executable(${PROJECT_NAME} ${SRCS}) 10 | 11 | target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB) 12 | 13 | install(TARGETS ${PROJECT_NAME} DESTINATION bin) 14 | -------------------------------------------------------------------------------- /examples/third_party/zlib/test_shared_zlib.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | $(rlocation rules_foreign_cc/examples/cmake/zlib_shared_usage_example) 4 | -------------------------------------------------------------------------------- /examples/third_party/zlib/test_zlib.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | $(rlocation rules_foreign_cc/examples/cmake/zlib_usage_example) 4 | -------------------------------------------------------------------------------- /examples/third_party/zlib/zlib_repositories.bzl: -------------------------------------------------------------------------------- 1 | """A module defining the third party dependency zlib""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 5 | 6 | def zlib_repositories(): 7 | maybe( 8 | http_archive, 9 | name = "zlib", 10 | build_file = Label("//zlib:BUILD.zlib.bazel"), 11 | sha256 = "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23", 12 | strip_prefix = "zlib-1.3.1", 13 | patches = [ 14 | # This patch modifies zlib so that on windows the generated lib matches that stated in the generated pkgconfig pc file for consumption by dependent rules 15 | # Similar patches are used in vcpkg and conan to resolve the same issue 16 | Label("//zlib:zlib.patch"), 17 | ], 18 | urls = [ 19 | "https://zlib.net/zlib-1.3.1.tar.gz", 20 | "https://zlib.net/archive/zlib-1.3.1.tar.gz", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /foreign_cc/built_tools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | bzl_library( 4 | name = "cmake_build", 5 | srcs = ["cmake_build.bzl"], 6 | visibility = ["//visibility:public"], 7 | deps = ["//foreign_cc:defs"], 8 | ) 9 | 10 | bzl_library( 11 | name = "make_build", 12 | srcs = ["make_build.bzl"], 13 | visibility = ["//visibility:public"], 14 | deps = [ 15 | "//foreign_cc/built_tools/private:built_tools_framework", 16 | "//foreign_cc/private:cc_toolchain_util", 17 | "//foreign_cc/private/framework:platform", 18 | "@bazel_tools//tools/cpp:toolchain_utils.bzl", 19 | ], 20 | ) 21 | 22 | bzl_library( 23 | name = "meson_build", 24 | srcs = ["meson_build.bzl"], 25 | visibility = ["//visibility:public"], 26 | deps = ["@rules_python//python:defs_bzl"], 27 | ) 28 | 29 | bzl_library( 30 | name = "ninja_build", 31 | srcs = ["ninja_build.bzl"], 32 | visibility = ["//visibility:public"], 33 | deps = [ 34 | "//foreign_cc/built_tools/private:built_tools_framework", 35 | "//foreign_cc/private/framework:platform", 36 | ], 37 | ) 38 | 39 | bzl_library( 40 | name = "pkgconfig_build", 41 | srcs = ["pkgconfig_build.bzl"], 42 | visibility = ["//visibility:public"], 43 | deps = [ 44 | "//foreign_cc:defs", 45 | "//foreign_cc/built_tools/private:built_tools_framework", 46 | "//toolchains/native_tools:tool_access", 47 | ], 48 | ) 49 | -------------------------------------------------------------------------------- /foreign_cc/built_tools/meson_build.bzl: -------------------------------------------------------------------------------- 1 | """ Rule for building meson from source. """ 2 | 3 | load("@rules_python//python:defs.bzl", "py_binary") 4 | load("@rules_python//python:features.bzl", "features") 5 | 6 | def meson_tool(name, main, data, requirements = [], **kwargs): 7 | kwargs.pop("precompile", None) 8 | if not features.uses_builtin_rules: 9 | kwargs["precompile"] = "disabled" 10 | py_binary( 11 | name = name, 12 | srcs = [main], 13 | data = data, 14 | deps = requirements, 15 | python_version = "PY3", 16 | main = main, 17 | **kwargs 18 | ) 19 | -------------------------------------------------------------------------------- /foreign_cc/built_tools/private/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | bzl_library( 4 | name = "built_tools_framework", 5 | srcs = ["built_tools_framework.bzl"], 6 | visibility = ["//foreign_cc/built_tools:__subpackages__"], 7 | deps = [ 8 | "//foreign_cc/private:cc_toolchain_util", 9 | "//foreign_cc/private:detect_root", 10 | "//foreign_cc/private:framework", 11 | "//foreign_cc/private/framework:helpers", 12 | "@bazel_tools//tools/cpp:toolchain_utils.bzl", 13 | ], 14 | ) 15 | -------------------------------------------------------------------------------- /foreign_cc/defs.bzl: -------------------------------------------------------------------------------- 1 | """Public entry point to all Foreign CC rules and supported APIs.""" 2 | 3 | load(":boost_build.bzl", _boost_build = "boost_build") 4 | load(":cmake.bzl", _cmake = "cmake", _cmake_variant = "cmake_variant") 5 | load(":configure.bzl", _configure_make = "configure_make", _configure_make_variant = "configure_make_variant") 6 | load(":make.bzl", _make = "make", _make_variant = "make_variant") 7 | load(":meson.bzl", _meson = "meson", _meson_with_requirements = "meson_with_requirements") 8 | load(":ninja.bzl", _ninja = "ninja") 9 | load(":utils.bzl", _runnable_binary = "runnable_binary") 10 | 11 | boost_build = _boost_build 12 | cmake = _cmake 13 | cmake_variant = _cmake_variant 14 | configure_make = _configure_make 15 | configure_make_variant = _configure_make_variant 16 | make_variant = _make_variant 17 | make = _make 18 | meson = _meson 19 | ninja = _ninja 20 | meson_with_requirements = _meson_with_requirements 21 | runnable_binary = _runnable_binary 22 | -------------------------------------------------------------------------------- /foreign_cc/private/framework/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | load(":platform.bzl", "framework_platform_info") 3 | 4 | toolchain_type( 5 | name = "shell_toolchain", 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | framework_platform_info() 10 | 11 | bzl_library( 12 | name = "helpers", 13 | srcs = ["helpers.bzl"], 14 | visibility = [ 15 | "//foreign_cc:__subpackages__", 16 | "//test:__subpackages__", 17 | ], 18 | deps = [ 19 | "//foreign_cc/private/framework/toolchains:access", 20 | "//foreign_cc/private/framework/toolchains:commands", 21 | ], 22 | ) 23 | 24 | bzl_library( 25 | name = "toolchain", 26 | srcs = ["toolchain.bzl"], 27 | visibility = ["//foreign_cc:__subpackages__"], 28 | deps = ["//foreign_cc/private/framework/toolchains:mappings"], 29 | ) 30 | 31 | bzl_library( 32 | name = "platform", 33 | srcs = ["platform.bzl"], 34 | visibility = ["//foreign_cc:__subpackages__"], 35 | ) 36 | -------------------------------------------------------------------------------- /foreign_cc/private/framework/toolchains/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | bzl_library( 4 | name = "access", 5 | srcs = ["access.bzl"], 6 | visibility = ["//foreign_cc:__subpackages__"], 7 | deps = [":commands"], 8 | ) 9 | 10 | bzl_library( 11 | name = "freebsd_commands", 12 | srcs = ["freebsd_commands.bzl"], 13 | visibility = ["//foreign_cc:__subpackages__"], 14 | deps = [":commands"], 15 | ) 16 | 17 | bzl_library( 18 | name = "linux_commands", 19 | srcs = ["linux_commands.bzl"], 20 | visibility = ["//foreign_cc:__subpackages__"], 21 | deps = [":commands"], 22 | ) 23 | 24 | bzl_library( 25 | name = "macos_commands", 26 | srcs = ["macos_commands.bzl"], 27 | visibility = ["//foreign_cc:__subpackages__"], 28 | deps = [":commands"], 29 | ) 30 | 31 | bzl_library( 32 | name = "windows_commands", 33 | srcs = ["windows_commands.bzl"], 34 | visibility = ["//foreign_cc:__subpackages__"], 35 | deps = [":commands"], 36 | ) 37 | 38 | bzl_library( 39 | name = "commands", 40 | srcs = ["commands.bzl"], 41 | visibility = ["//foreign_cc:__subpackages__"], 42 | ) 43 | 44 | bzl_library( 45 | name = "mappings", 46 | srcs = ["mappings.bzl"], 47 | visibility = ["//foreign_cc:__subpackages__"], 48 | ) 49 | -------------------------------------------------------------------------------- /foreign_cc/providers.bzl: -------------------------------------------------------------------------------- 1 | """ A module containing all public facing providers """ 2 | 3 | ForeignCcDepsInfo = provider( 4 | doc = """Provider to pass transitive information about external libraries.""", 5 | fields = { 6 | "artifacts": "Depset of ForeignCcArtifactInfo", 7 | }, 8 | ) 9 | 10 | ForeignCcArtifactInfo = provider( 11 | doc = """Groups information about the external library install directory, 12 | and relative bin, include and lib directories. 13 | 14 | Serves to pass transitive information about externally built artifacts up the dependency chain. 15 | 16 | Can not be used as a top-level provider. 17 | Instances of ForeignCcArtifactInfo are encapsulated in a depset [ForeignCcDepsInfo::artifacts](#ForeignCcDepsInfo-artifacts).""", 18 | fields = { 19 | "bin_dir_name": "Bin directory, relative to install directory", 20 | "dll_dir_name": "DLL directory, relative to install directory", 21 | "gen_dir": "Install directory", 22 | "include_dir_name": "Include directory, relative to install directory", 23 | "lib_dir_name": "Lib directory, relative to install directory", 24 | }, 25 | ) 26 | -------------------------------------------------------------------------------- /test/boostrap_tools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | build_test( 4 | name = "boostrap_tools", 5 | tags = [ 6 | "large", 7 | "manual", 8 | ], 9 | targets = [ 10 | "//toolchains:make_tool", 11 | "//toolchains:cmake_tool", 12 | "//toolchains:ninja_tool", 13 | ], 14 | ) 15 | -------------------------------------------------------------------------------- /test/detect_root_test/.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /test/detect_root_test/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:diff_test.bzl", "diff_test") 2 | load(":detect_root_test_rule.bzl", "detect_root_test_rule") 3 | 4 | filegroup( 5 | name = "fg", 6 | srcs = glob( 7 | ["dir1/**"], 8 | ), 9 | ) 10 | 11 | filegroup( 12 | name = "fg_srcs", 13 | srcs = glob( 14 | ["dir1/srcs/**"], 15 | ), 16 | ) 17 | 18 | detect_root_test_rule( 19 | name = "srcs_is_fg", 20 | srcs = ":fg", 21 | out = "out_fg.txt", 22 | ) 23 | 24 | detect_root_test_rule( 25 | name = "srcs_is_fg_srcs", 26 | srcs = ":fg_srcs", 27 | out = "out_fg_srcs.txt", 28 | ) 29 | 30 | detect_root_test_rule( 31 | name = "srcs_in_repo", 32 | srcs = "@rules_foreign_cc_detect_root_test_repo//:srcs", 33 | out = "out_repo.txt", 34 | ) 35 | 36 | diff_test( 37 | name = "repo_test", 38 | file1 = ":srcs_in_repo", 39 | file2 = "expected/out_repo.txt", 40 | ) 41 | 42 | diff_test( 43 | name = "fg_test", 44 | file1 = ":srcs_is_fg", 45 | file2 = "expected/out_fg.txt", 46 | ) 47 | 48 | diff_test( 49 | name = "fg_srcs_test", 50 | file1 = ":srcs_is_fg_srcs", 51 | file2 = "expected/out_fg_srcs.txt", 52 | ) 53 | 54 | test_suite( 55 | name = "tests", 56 | tests = [ 57 | "fg_srcs_test", 58 | "fg_test", 59 | "repo_test", 60 | ], 61 | ) 62 | -------------------------------------------------------------------------------- /test/detect_root_test/detect_root_test_rule.bzl: -------------------------------------------------------------------------------- 1 | """A helper rule for testing detect_root function.""" 2 | 3 | # buildifier: disable=bzl-visibility 4 | load("@rules_foreign_cc//foreign_cc/private:detect_root.bzl", "detect_root") 5 | 6 | def _impl(ctx): 7 | detected_root = detect_root(ctx.attr.srcs) 8 | out = ctx.actions.declare_file(ctx.attr.out) 9 | ctx.actions.write( 10 | output = out, 11 | content = detected_root, 12 | ) 13 | return [DefaultInfo(files = depset([out]))] 14 | 15 | detect_root_test_rule = rule( 16 | implementation = _impl, 17 | attrs = { 18 | "out": attr.string(mandatory = True), 19 | "srcs": attr.label(mandatory = True), 20 | }, 21 | ) 22 | -------------------------------------------------------------------------------- /test/detect_root_test/dir1/srcs/input.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/test/detect_root_test/dir1/srcs/input.txt -------------------------------------------------------------------------------- /test/detect_root_test/expected/out_fg.txt: -------------------------------------------------------------------------------- 1 | dir1/srcs -------------------------------------------------------------------------------- /test/detect_root_test/expected/out_fg_srcs.txt: -------------------------------------------------------------------------------- 1 | dir1/srcs -------------------------------------------------------------------------------- /test/detect_root_test/expected/out_repo.txt: -------------------------------------------------------------------------------- 1 | external/rules_foreign_cc_detect_root_test_repo -------------------------------------------------------------------------------- /test/dir1/include/header1.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /test/dir2/include/header2.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /test/expected/out_symlinked_dirs.txt: -------------------------------------------------------------------------------- 1 | aaa: 2 | header1.h 3 | header2.h 4 | -------------------------------------------------------------------------------- /test/expected/out_symlinked_dirs_freebsd.txt: -------------------------------------------------------------------------------- 1 | header1.h 2 | header2.h 3 | -------------------------------------------------------------------------------- /test/expected/out_symlinked_dirs_macos.txt: -------------------------------------------------------------------------------- 1 | header1.h 2 | header2.h 3 | -------------------------------------------------------------------------------- /test/shell_script_helper_test_rule.bzl: -------------------------------------------------------------------------------- 1 | # buildifier: disable=module-docstring 2 | # buildifier: disable=bzl-visibility 3 | load("//foreign_cc/private/framework:helpers.bzl", "convert_shell_script") 4 | 5 | def _impl(ctx): 6 | text = convert_shell_script(ctx, ctx.attr.script) 7 | out = ctx.actions.declare_file(ctx.attr.out) 8 | ctx.actions.write( 9 | output = out, 10 | content = text, 11 | ) 12 | return [DefaultInfo(files = depset([out]))] 13 | 14 | shell_script_helper_test_rule = rule( 15 | implementation = _impl, 16 | attrs = { 17 | "out": attr.string(mandatory = True), 18 | "script": attr.string_list(mandatory = True), 19 | }, 20 | toolchains = [ 21 | "@rules_foreign_cc//foreign_cc/private/framework:shell_toolchain", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /test/standard_cxx_flags_test/.bazelrc: -------------------------------------------------------------------------------- 1 | build --copt="-fblah0" --cxxopt="-fblah1" --conlyopt="-fblah2" --linkopt="-fblah3" 2 | -------------------------------------------------------------------------------- /test/standard_cxx_flags_test/.bazelversion: -------------------------------------------------------------------------------- 1 | 7.4.1 2 | -------------------------------------------------------------------------------- /test/standard_cxx_flags_test/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load(":tests.bzl", "flags_test") 2 | 3 | flags_test( 4 | name = "flags_test", 5 | copts = ["-fblah4"], 6 | linkopts = ["-fblah5"], 7 | ) 8 | -------------------------------------------------------------------------------- /test/standard_cxx_flags_test/WORKSPACE.bazel: -------------------------------------------------------------------------------- 1 | workspace(name = "standard_cxx_flags_test") 2 | 3 | local_repository( 4 | name = "rules_foreign_cc", 5 | path = "../..", 6 | ) 7 | 8 | load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") 9 | 10 | rules_foreign_cc_dependencies() 11 | 12 | load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") 13 | 14 | py_repositories() 15 | 16 | python_register_toolchains( 17 | name = "python_3_12", 18 | python_version = "3.12", 19 | ) 20 | 21 | load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") 22 | 23 | protobuf_deps() 24 | 25 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 26 | 27 | http_archive( 28 | name = "bazelci_rules", 29 | sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e", 30 | strip_prefix = "bazelci_rules-1.0.0", 31 | url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz", 32 | ) 33 | 34 | load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig") 35 | 36 | # Creates a default toolchain config for RBE. 37 | # Use this as is if you are using the rbe_ubuntu16_04 container, 38 | # otherwise refer to RBE docs. 39 | rbe_preconfig( 40 | name = "buildkite_config", 41 | toolchain = "ubuntu1804-bazel-java11", 42 | ) 43 | -------------------------------------------------------------------------------- /test/utils_test.bzl: -------------------------------------------------------------------------------- 1 | """ Unit tests for some utility functions """ 2 | 3 | load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") 4 | 5 | # buildifier: disable=bzl-visibility 6 | load("//foreign_cc/private:framework.bzl", "uniq_list_keep_order") 7 | 8 | def _uniq_list_keep_order_test(ctx): 9 | env = unittest.begin(ctx) 10 | 11 | list = [1, 2, 3, 1, 4, 1, 2, 3, 5, 1, 2, 4, 7, 5] 12 | filtered = uniq_list_keep_order(list) 13 | asserts.equals(env, [1, 2, 3, 4, 5, 7], filtered) 14 | 15 | filtered_empty = uniq_list_keep_order([]) 16 | asserts.equals(env, [], filtered_empty) 17 | 18 | return unittest.end(env) 19 | 20 | uniq_list_keep_order_test = unittest.make(_uniq_list_keep_order_test) 21 | 22 | def utils_test_suite(): 23 | unittest.suite( 24 | "utils_test_suite", 25 | uniq_list_keep_order_test, 26 | ) 27 | -------------------------------------------------------------------------------- /toolchains/README.md: -------------------------------------------------------------------------------- 1 | # Rules Foreign CC Toolchains 2 | 3 | This package contains implementations for toolchains required for the supported build systems. 4 | 5 | ## Built Toolchains 6 | 7 | These toolchains are for build tools that are built from source. 8 | 9 | ## PreBuilt Toolchains 10 | 11 | These toolchains are for build tools that are built and stored at some remote site and downloaded when required by 12 | any target currently in the build graph. 13 | 14 | ## PreInstalled Toolchains 15 | 16 | These toolchains are for build tools already installed on the host. 17 | -------------------------------------------------------------------------------- /toolchains/native_tools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2 | 3 | bzl_library( 4 | name = "native_tools_toolchain", 5 | srcs = ["native_tools_toolchain.bzl"], 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | bzl_library( 10 | name = "tool_access", 11 | srcs = ["tool_access.bzl"], 12 | visibility = ["//visibility:public"], 13 | ) 14 | -------------------------------------------------------------------------------- /toolchains/patches/BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/toolchains/patches/BUILD.bazel -------------------------------------------------------------------------------- /toolchains/patches/README.md: -------------------------------------------------------------------------------- 1 | # Foreign CC toolchain patches 2 | 3 | ## [cmake-c++11.patch](./cmake-c++11.patch) 4 | 5 | See 6 | 7 | ## [make-reproducible-bootstrap.patch](./make-reproducible-bootstrap.patch) 8 | 9 | This patch avoids reliance on host installed tools for bootstrapping make. 10 | 11 | ## [pkgconfig-builtin-glib-int-conversion.patch](./pkgconfig-builtin-glib-int-conversion.patch) 12 | 13 | This patch fixes explicit integer conversion which causes errors in `clang >= 15` and `gcc >= 14` 14 | 15 | ## [pkgconfig-detectenv.patch](./pkgconfig-detectenv.patch) 16 | 17 | This patch is required as bazel does not provide the VCINSTALLDIR or WINDOWSSDKDIR vars 18 | 19 | ## [pkgconfig-makefile-vc.patch](./pkgconfig-makefile-vc.patch) 20 | 21 | This patch is required as rules_foreign_cc runs in MSYS2 on Windows and MSYS2's "mkdir" is used 22 | -------------------------------------------------------------------------------- /toolchains/patches/cmake-c++11.patch: -------------------------------------------------------------------------------- 1 | --- CMakeLists.txt 2023-01-24 13:46:17.000000000 -0800 2 | +++ CMakeLists.txt 2023-01-24 13:46:43.000000000 -0800 3 | @@ -96,10 +96,6 @@ 4 | 5 | # check for available C++ features 6 | include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake) 7 | - 8 | - if(NOT CMake_HAVE_CXX_UNIQUE_PTR) 9 | - message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).") 10 | - endif() 11 | endif() 12 | 13 | # Inform STL library header wrappers whether to use system versions. -------------------------------------------------------------------------------- /toolchains/patches/make-reproducible-bootstrap.patch: -------------------------------------------------------------------------------- 1 | diff --git Makefile.in Makefile.in 2 | index 9535058..0b12e99 100644 3 | --- Makefile.in 4 | +++ Makefile.in 5 | @@ -1042,8 +1042,8 @@ make_LDADD = $(LIBOBJS) $(GUILE_LIBS) lib/libgnu.a $(GETLOADAVG_LIBS) \ 6 | @LIBINTL@ 7 | 8 | AM_CPPFLAGS = -Isrc -I$(top_srcdir)/src -Ilib -I$(top_srcdir)/lib \ 9 | - -DLIBDIR=\"$(libdir)\" -DINCLUDEDIR=\"$(includedir)\" \ 10 | - -DLOCALEDIR=\"$(localedir)\" $(am__append_2) 11 | + -DLIBDIR=\".\" -DINCLUDEDIR=\"external/rules_foreign_cc/toolchains/make/include\" \ 12 | + -DLOCALEDIR=\"external/rules_foreign_cc/toolchains/make/share/locale\" $(am__append_2) 13 | AM_CFLAGS = $(GUILE_CFLAGS) 14 | 15 | # Extra stuff to include in the distribution. 16 | 17 | -------------------------------------------------------------------------------- /toolchains/patches/pkgconfig-detectenv.patch: -------------------------------------------------------------------------------- 1 | --- detectenv-msvc.mak 2016-04-11 22:39:26.000000000 +0100 2 | +++ detectenv-msvc.mak 2016-04-11 22:39:26.000000000 +0100 3 | @@ -1,12 +1,6 @@ 4 | # Check to see we are configured to build with MSVC (MSDEVDIR, MSVCDIR or 5 | # VCINSTALLDIR) or with the MS Platform SDK (MSSDK or WindowsSDKDir) 6 | -!if !defined(VCINSTALLDIR) && !defined(WINDOWSSDKDIR) 7 | -MSG = ^ 8 | -This Makefile is only for Visual Studio 2008 and later.^ 9 | -You need to ensure that the Visual Studio Environment is properly set up^ 10 | -before running this Makefile. 11 | -!error $(MSG) 12 | -!endif 13 | + 14 | 15 | ERRNUL = 2>NUL 16 | _HASH=^# 17 | -------------------------------------------------------------------------------- /toolchains/patches/pkgconfig-makefile-vc.patch: -------------------------------------------------------------------------------- 1 | --- Makefile.vc 2016-04-11 22:39:26.000000000 +0100 2 | +++ Makefile.vc.new 2022-08-19 17:46:52.031979100 +0100 3 | @@ -73,7 +73,7 @@ 4 | @-if exist $@.manifest mt /manifest $@.manifest /outputresource:$@;1 5 | 6 | $(CFG)\$(PLAT)\pkg-config: 7 | - @-mkdir $@ 8 | + @-mkdir -p $@ 9 | 10 | config.h: config.h.win32 11 | @-copy $@.win32 $@ 12 | -------------------------------------------------------------------------------- /tools/lint/BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazel-contrib/rules_foreign_cc/3d812e59f55cc2be5447d9f0a768934c6162f261/tools/lint/BUILD.bazel -------------------------------------------------------------------------------- /tools/lint/linters.bzl: -------------------------------------------------------------------------------- 1 | """ Provides linting aspects for shellcheck used to check validity of generated shell scripts. """ 2 | 3 | load("@aspect_rules_lint//lint:lint_test.bzl", "lint_test") 4 | load("@aspect_rules_lint//lint:shellcheck.bzl", "lint_shellcheck_aspect") 5 | 6 | shellcheck = lint_shellcheck_aspect( 7 | binary = "@multitool//tools/shellcheck", 8 | config = Label("@//:.shellcheckrc"), 9 | ) 10 | 11 | shellcheck_test = lint_test(aspect = shellcheck) 12 | -------------------------------------------------------------------------------- /version.bzl: -------------------------------------------------------------------------------- 1 | """A module representing the version of rules_foreign_cc""" 2 | 3 | VERSION = "0.15.0" 4 | --------------------------------------------------------------------------------