All Projects → wildarch → blackjack

wildarch / blackjack

Licence: other
Build cargo dependencies with Bazel

Programming Languages

Starlark
911 projects
rust
11053 projects
shell
77523 projects

Projects that are alternatives of or similar to blackjack

bzl
Bzl - Integrated CLI + UI + VSCode Extension for Bazel
Stars: ✭ 43 (+26.47%)
Mutual labels:  bazel
ng-qt
Build extremely powerful and efficient native cross-platform desktop applications using Angular and NodeGUI
Stars: ✭ 14 (-58.82%)
Mutual labels:  bazel
rustsec
Audit Cargo.lock files for dependencies with security vulnerabilities
Stars: ✭ 956 (+2711.76%)
Mutual labels:  cargo
cargo-llvm-cov
Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Stars: ✭ 181 (+432.35%)
Mutual labels:  cargo
pazel
pazel - generate Bazel BUILD files for Python
Stars: ✭ 38 (+11.76%)
Mutual labels:  bazel
gobazel
gobazel is a tool to help golang bazel developers to map bazel's folder structure to golang's standard folder structure, through FUSE (thus only works for Linux and MacOS users).
Stars: ✭ 28 (-17.65%)
Mutual labels:  bazel
rhack
Temporary edit external crates that your project depends on
Stars: ✭ 104 (+205.88%)
Mutual labels:  cargo
svelte-ts
[WIP] Tools for building Svelte apps with TS
Stars: ✭ 89 (+161.76%)
Mutual labels:  bazel
bazel.cmake
bazel.cmake mimics the behavior of bazel to simplify the usability of CMake
Stars: ✭ 38 (+11.76%)
Mutual labels:  bazel
broom
A disk cleaning utility for developers.
Stars: ✭ 38 (+11.76%)
Mutual labels:  cargo
create-bazel-workspace
Generate a new polyglot Bazel workspace with minimal configuration
Stars: ✭ 16 (-52.94%)
Mutual labels:  bazel
glitter
🌌⭐ Git tooling of the future.
Stars: ✭ 150 (+341.18%)
Mutual labels:  cargo
bazel-packages
[WIP] Collection of Bazel packages
Stars: ✭ 14 (-58.82%)
Mutual labels:  bazel
vcpkg-rs
Build library for finding native libraries in vcpkg for Rust - Windows (msvc), Linux and macOS
Stars: ✭ 68 (+100%)
Mutual labels:  cargo
cargo-wix
A cargo subcommand to build Windows installers for rust projects using the WiX Toolset
Stars: ✭ 142 (+317.65%)
Mutual labels:  cargo
rules poetry
Bazel rules that use Poetry for Python package management
Stars: ✭ 40 (+17.65%)
Mutual labels:  bazel
rules node
Node rules for Bazel (unsupported)
Stars: ✭ 51 (+50%)
Mutual labels:  bazel
rules clojure
Clojure rules for Bazel
Stars: ✭ 27 (-20.59%)
Mutual labels:  bazel
rules sh
Shell rules for Bazel
Stars: ✭ 18 (-47.06%)
Mutual labels:  bazel
crm
Cargo registry manager (Cargo 注册表管理器),用于方便的管理和更换 Rust 国内镜像源
Stars: ✭ 103 (+202.94%)
Mutual labels:  cargo

Blackjack - build cargo dependencies with Bazel

Generate bazel targets for crates.io dependencies in your Cargo.toml.

Blackjack reads standard Cargo.toml, so the same project can build with both cargo and Bazel. Adding Bazel support to an existing cargo project is as simple as adding a WORKSPACE and BUILD file.

WORKSPACE:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Configure a Rust toolchain.
# See https://github.com/bazelbuild/rules_rust for more details.
http_archive(
    name = "rules_rust",
    sha256 = "cf2e82c56c73c3213bc2d94303aee88d7e44634ad1e1fe183befa85b17b5021d",
    strip_prefix = "rules_rust-0e3593fc5d839e4a74523f07e885b761ee19e662",
    urls = [
        # Master branch as of 2021-12-19
        "https://github.com/bazelbuild/rules_rust/archive/0e3593fc5d839e4a74523f07e885b761ee19e662.tar.gz",
    ],
)
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()

# Set up blackjack
http_archive(
    name = "blackjack",
    url = "https://github.com/wildarch/blackjack/archive/909b66db4782cf963791aa4a24793244dffdba17.zip",
    strip_prefix = "blackjack-909b66db4782cf963791aa4a24793244dffdba17",
)
load("@blackjack//:workspace.bzl", "blackjack_cargo")
blackjack_cargo()

BUILD file in the same directory as Cargo.toml:

load("@blackjack//:blackjack.bzl", "blackjack")

blackjack(name = "blackjack")

Now run bazel run //:blackjack. You'll find a newly created cargo_dependencies.bzl file next to your Cargo.toml.

Note: Blackjack pulls in its own cargo executable, so you do not need to have it installed.

Import the generated dependencies into your WORKSPACE:

load("//:cargo_dependencies.bzl", "cargo_dependencies")
cargo_dependencies()

Dependencies from Cargo.toml are now available as rust_library rules under the label @crates_io_{name}//:{name}.

For an example, see here.

Updates

If you make any changes to the dependency graph, simply re-run bazel run //:blackjack to build an updated cargo_dependencies.bzl file.

Configuration

Many crates will build out of the box. For more exotic crates (linking to C libraries, build scripts etc.), there are a few configuration options. This configuration is embedded in the Cargo.toml in the metadata section.

To pass extra flags to rustc when compiling a particular crate, add the following to the end of Cargo.toml:

[package.metadata.blackjack.proc-macro2]
rustc_flags = ["--cfg=use_proc_macro"]

Note: Blackjack provides default settings for a few common crates such as proc-macro2, so you don't always need to add them yourself. Please send PRs for default settings for other common crates!

If a dependency needs a build script, but does not otherwise do anything complicated, try adding something like:

[package.metadata.blackjack.proc-macro-nested]
build_script = true

If all else fails, you can replace the dependency with a custom rust_library target:

[package.metadata.blackjack.libz-sys]
replace = "@custom_libz_sys"

For a simple example of replacing a dependency and linking to a C library, see here.

If you want to change the default crates_io_ prefix for generated dependency targets, that is possible too:

[package.metadata.blackjack]
prefix = "blackjack_crates_io"

Now instead of @crates_io_serde//:serde, use blackjack_crates_io_serde//:serde.

Things that don't work yet (but would gladly accept a PR for)

  • Support for Windows. All that is really needed here is to add it to the list of supported platforms, and fix the platform specific workspace test.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].