Squashed 'third_party/rules_rust/' content from commit bf59038ca
git-subtree-dir: third_party/rules_rust
git-subtree-split: bf59038cac11798cbaef9f3bf965bad8182b97fa
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
Change-Id: I5a20e403203d670df467ea97dde9a4ac40339a8d
diff --git a/examples/sys/basic/BUILD.bazel b/examples/sys/basic/BUILD.bazel
new file mode 100644
index 0000000..142aa89
--- /dev/null
+++ b/examples/sys/basic/BUILD.bazel
@@ -0,0 +1,33 @@
+# Copyright 2020 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("@rules_rust//rust:defs.bzl", "rust_binary")
+
+package(default_visibility = ["//visibility:public"])
+
+rust_binary(
+ name = "hello_sys",
+ srcs = ["src/main.rs"],
+ edition = "2018",
+ # Note the `cargo-raze` dependencies here need to have been loaded
+ # in the WORKSPACE file. See `//sys:sys_deps.bzl` for rmore details.
+ deps = ["//sys/basic/raze:bzip2"],
+)
+
+sh_test(
+ name = "test",
+ srcs = ["test.sh"],
+ args = ["$(location :hello_sys)"],
+ data = [":hello_sys"],
+)
diff --git a/examples/sys/basic/Cargo.lock b/examples/sys/basic/Cargo.lock
new file mode 100644
index 0000000..7a14e37
--- /dev/null
+++ b/examples/sys/basic/Cargo.lock
@@ -0,0 +1,47 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "bzip2"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b"
+dependencies = [
+ "bzip2-sys",
+ "libc",
+]
+
+[[package]]
+name = "bzip2-sys"
+version = "0.1.9+1.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ad3b39a260062fca31f7b0b12f207e8f2590a67d32ec7d59c20484b07ea7285e"
+dependencies = [
+ "cc",
+ "libc",
+ "pkg-config",
+]
+
+[[package]]
+name = "cc"
+version = "1.0.60"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c"
+
+[[package]]
+name = "libc"
+version = "0.2.77"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
+
+[[package]]
+name = "pkg-config"
+version = "0.3.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
+
+[[package]]
+name = "rules_rust_examples_basic_sys"
+version = "0.0.1"
+dependencies = [
+ "bzip2",
+]
diff --git a/examples/sys/basic/Cargo.toml b/examples/sys/basic/Cargo.toml
new file mode 100644
index 0000000..61b97fc
--- /dev/null
+++ b/examples/sys/basic/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "rules_rust_examples_basic_sys"
+version = "0.0.1"
+
+[[bin]]
+name = "rules_rust_examples_basic_sys"
+path = "src/main.rs"
+
+[dependencies]
+bzip2 = "=0.3.3"
+
+[package.metadata.raze]
+workspace_path = "//sys/basic/raze"
+genmode = "Remote"
+gen_workspace_prefix = "basic_sys"
+rust_rules_workspace_name = "rules_rust"
+package_aliases_dir = "raze"
+default_gen_buildrs = false
+
+[package.metadata.raze.crates.bzip2-sys.'0.1.9+1.0.8']
+gen_buildrs = true
diff --git a/examples/sys/basic/raze/BUILD.bazel b/examples/sys/basic/raze/BUILD.bazel
new file mode 100644
index 0000000..ade3349
--- /dev/null
+++ b/examples/sys/basic/raze/BUILD.bazel
@@ -0,0 +1,30 @@
+"""
+@generated
+cargo-raze generated Bazel file.
+
+DO NOT EDIT! Replaced on runs of cargo-raze
+"""
+
+package(default_visibility = ["//visibility:public"])
+
+licenses([
+ "notice", # See individual crates for specific licenses
+])
+
+# Aliased targets
+alias(
+ name = "bzip2",
+ actual = "@basic_sys__bzip2__0_3_3//:bzip2",
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+)
+
+# Export file for Stardoc support
+exports_files(
+ [
+ "crates.bzl",
+ ],
+ visibility = ["//visibility:public"],
+)
diff --git a/examples/sys/basic/raze/crates.bzl b/examples/sys/basic/raze/crates.bzl
new file mode 100644
index 0000000..beacc3e
--- /dev/null
+++ b/examples/sys/basic/raze/crates.bzl
@@ -0,0 +1,62 @@
+"""
+@generated
+cargo-raze generated Bazel file.
+
+DO NOT EDIT! Replaced on runs of cargo-raze
+"""
+
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") # buildifier: disable=load
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # buildifier: disable=load
+load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") # buildifier: disable=load
+
+def basic_sys_fetch_remote_crates():
+ """This function defines a collection of repos and should be called in a WORKSPACE file"""
+ maybe(
+ http_archive,
+ name = "basic_sys__bzip2__0_3_3",
+ url = "https://crates.io/api/v1/crates/bzip2/0.3.3/download",
+ type = "tar.gz",
+ sha256 = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b",
+ strip_prefix = "bzip2-0.3.3",
+ build_file = Label("//sys/basic/raze/remote:BUILD.bzip2-0.3.3.bazel"),
+ )
+
+ maybe(
+ http_archive,
+ name = "basic_sys__bzip2_sys__0_1_9_1_0_8",
+ url = "https://crates.io/api/v1/crates/bzip2-sys/0.1.9+1.0.8/download",
+ type = "tar.gz",
+ sha256 = "ad3b39a260062fca31f7b0b12f207e8f2590a67d32ec7d59c20484b07ea7285e",
+ strip_prefix = "bzip2-sys-0.1.9+1.0.8",
+ build_file = Label("//sys/basic/raze/remote:BUILD.bzip2-sys-0.1.9+1.0.8.bazel"),
+ )
+
+ maybe(
+ http_archive,
+ name = "basic_sys__cc__1_0_60",
+ url = "https://crates.io/api/v1/crates/cc/1.0.60/download",
+ type = "tar.gz",
+ sha256 = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c",
+ strip_prefix = "cc-1.0.60",
+ build_file = Label("//sys/basic/raze/remote:BUILD.cc-1.0.60.bazel"),
+ )
+
+ maybe(
+ http_archive,
+ name = "basic_sys__libc__0_2_77",
+ url = "https://crates.io/api/v1/crates/libc/0.2.77/download",
+ type = "tar.gz",
+ sha256 = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235",
+ strip_prefix = "libc-0.2.77",
+ build_file = Label("//sys/basic/raze/remote:BUILD.libc-0.2.77.bazel"),
+ )
+
+ maybe(
+ http_archive,
+ name = "basic_sys__pkg_config__0_3_18",
+ url = "https://crates.io/api/v1/crates/pkg-config/0.3.18/download",
+ type = "tar.gz",
+ sha256 = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33",
+ strip_prefix = "pkg-config-0.3.18",
+ build_file = Label("//sys/basic/raze/remote:BUILD.pkg-config-0.3.18.bazel"),
+ )
diff --git a/examples/sys/basic/raze/remote/BUILD.bazel b/examples/sys/basic/raze/remote/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/examples/sys/basic/raze/remote/BUILD.bazel
diff --git a/examples/sys/basic/raze/remote/BUILD.bzip2-0.3.3.bazel b/examples/sys/basic/raze/remote/BUILD.bzip2-0.3.3.bazel
new file mode 100644
index 0000000..403de65
--- /dev/null
+++ b/examples/sys/basic/raze/remote/BUILD.bzip2-0.3.3.bazel
@@ -0,0 +1,57 @@
+"""
+@generated
+cargo-raze crate build file.
+
+DO NOT EDIT! Replaced on runs of cargo-raze
+"""
+
+# buildifier: disable=load
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+# buildifier: disable=load
+load(
+ "@rules_rust//rust:defs.bzl",
+ "rust_binary",
+ "rust_library",
+ "rust_proc_macro",
+ "rust_test",
+)
+
+package(default_visibility = [
+ # Public for visibility by "@raze__crate__version//" targets.
+ #
+ # Prefer access through "//sys/basic/raze", which limits external
+ # visibility to explicit Cargo.toml dependencies.
+ "//visibility:public",
+])
+
+licenses([
+ "notice", # MIT from expression "MIT OR Apache-2.0"
+])
+
+# Generated Targets
+
+rust_library(
+ name = "bzip2",
+ srcs = glob(["**/*.rs"]),
+ crate_features = [
+ ],
+ crate_root = "src/lib.rs",
+ data = [],
+ edition = "2015",
+ rustc_flags = [
+ "--cap-lints=allow",
+ ],
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+ version = "0.3.3",
+ # buildifier: leave-alone
+ deps = [
+ "@basic_sys__bzip2_sys__0_1_9_1_0_8//:bzip2_sys",
+ "@basic_sys__libc__0_2_77//:libc",
+ ],
+)
+
+# Unsupported target "tokio" with type "test" omitted
diff --git a/examples/sys/basic/raze/remote/BUILD.bzip2-sys-0.1.9+1.0.8.bazel b/examples/sys/basic/raze/remote/BUILD.bzip2-sys-0.1.9+1.0.8.bazel
new file mode 100644
index 0000000..2401d2c
--- /dev/null
+++ b/examples/sys/basic/raze/remote/BUILD.bzip2-sys-0.1.9+1.0.8.bazel
@@ -0,0 +1,87 @@
+"""
+@generated
+cargo-raze crate build file.
+
+DO NOT EDIT! Replaced on runs of cargo-raze
+"""
+
+# buildifier: disable=load
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+# buildifier: disable=load
+load(
+ "@rules_rust//rust:defs.bzl",
+ "rust_binary",
+ "rust_library",
+ "rust_proc_macro",
+ "rust_test",
+)
+
+package(default_visibility = [
+ # Public for visibility by "@raze__crate__version//" targets.
+ #
+ # Prefer access through "//sys/basic/raze", which limits external
+ # visibility to explicit Cargo.toml dependencies.
+ "//visibility:public",
+])
+
+licenses([
+ "notice", # MIT from expression "MIT OR Apache-2.0"
+])
+
+# Generated Targets
+# buildifier: disable=out-of-order-load
+# buildifier: disable=load-on-top
+load(
+ "@rules_rust//cargo:cargo_build_script.bzl",
+ "cargo_build_script",
+)
+
+cargo_build_script(
+ name = "bzip2_sys_build_script",
+ srcs = glob(["**/*.rs"]),
+ build_script_env = {
+ },
+ crate_features = [
+ ],
+ crate_root = "build.rs",
+ data = glob(["**"]),
+ edition = "2015",
+ links = "bzip2",
+ rustc_flags = [
+ "--cap-lints=allow",
+ ],
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+ version = "0.1.9+1.0.8",
+ visibility = ["//visibility:private"],
+ deps = [
+ "@basic_sys__cc__1_0_60//:cc",
+ "@basic_sys__pkg_config__0_3_18//:pkg_config",
+ ],
+)
+
+rust_library(
+ name = "bzip2_sys",
+ srcs = glob(["**/*.rs"]),
+ crate_features = [
+ ],
+ crate_root = "lib.rs",
+ data = [],
+ edition = "2015",
+ rustc_flags = [
+ "--cap-lints=allow",
+ ],
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+ version = "0.1.9+1.0.8",
+ # buildifier: leave-alone
+ deps = [
+ ":bzip2_sys_build_script",
+ "@basic_sys__libc__0_2_77//:libc",
+ ],
+)
diff --git a/examples/sys/basic/raze/remote/BUILD.cc-1.0.60.bazel b/examples/sys/basic/raze/remote/BUILD.cc-1.0.60.bazel
new file mode 100644
index 0000000..ad826c1
--- /dev/null
+++ b/examples/sys/basic/raze/remote/BUILD.cc-1.0.60.bazel
@@ -0,0 +1,85 @@
+"""
+@generated
+cargo-raze crate build file.
+
+DO NOT EDIT! Replaced on runs of cargo-raze
+"""
+
+# buildifier: disable=load
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+# buildifier: disable=load
+load(
+ "@rules_rust//rust:defs.bzl",
+ "rust_binary",
+ "rust_library",
+ "rust_proc_macro",
+ "rust_test",
+)
+
+package(default_visibility = [
+ # Public for visibility by "@raze__crate__version//" targets.
+ #
+ # Prefer access through "//sys/basic/raze", which limits external
+ # visibility to explicit Cargo.toml dependencies.
+ "//visibility:public",
+])
+
+licenses([
+ "notice", # MIT from expression "MIT OR Apache-2.0"
+])
+
+# Generated Targets
+
+rust_binary(
+ # Prefix bin name to disambiguate from (probable) collision with lib name
+ # N.B.: The exact form of this is subject to change.
+ name = "cargo_bin_gcc_shim",
+ srcs = glob(["**/*.rs"]),
+ crate_features = [
+ ],
+ crate_root = "src/bin/gcc-shim.rs",
+ data = [],
+ edition = "2018",
+ rustc_flags = [
+ "--cap-lints=allow",
+ ],
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+ version = "1.0.60",
+ # buildifier: leave-alone
+ deps = [
+ ":cc",
+ ],
+)
+
+rust_library(
+ name = "cc",
+ srcs = glob(["**/*.rs"]),
+ crate_features = [
+ ],
+ crate_root = "src/lib.rs",
+ data = [],
+ edition = "2018",
+ rustc_flags = [
+ "--cap-lints=allow",
+ ],
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+ version = "1.0.60",
+ # buildifier: leave-alone
+ deps = [
+ ],
+)
+
+# Unsupported target "cc_env" with type "test" omitted
+
+# Unsupported target "cflags" with type "test" omitted
+
+# Unsupported target "cxxflags" with type "test" omitted
+
+# Unsupported target "test" with type "test" omitted
diff --git a/examples/sys/basic/raze/remote/BUILD.libc-0.2.77.bazel b/examples/sys/basic/raze/remote/BUILD.libc-0.2.77.bazel
new file mode 100644
index 0000000..4b8aed7
--- /dev/null
+++ b/examples/sys/basic/raze/remote/BUILD.libc-0.2.77.bazel
@@ -0,0 +1,59 @@
+"""
+@generated
+cargo-raze crate build file.
+
+DO NOT EDIT! Replaced on runs of cargo-raze
+"""
+
+# buildifier: disable=load
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+# buildifier: disable=load
+load(
+ "@rules_rust//rust:defs.bzl",
+ "rust_binary",
+ "rust_library",
+ "rust_proc_macro",
+ "rust_test",
+)
+
+package(default_visibility = [
+ # Public for visibility by "@raze__crate__version//" targets.
+ #
+ # Prefer access through "//sys/basic/raze", which limits external
+ # visibility to explicit Cargo.toml dependencies.
+ "//visibility:public",
+])
+
+licenses([
+ "notice", # MIT from expression "MIT OR Apache-2.0"
+])
+
+# Generated Targets
+
+# Unsupported target "build-script-build" with type "custom-build" omitted
+
+rust_library(
+ name = "libc",
+ srcs = glob(["**/*.rs"]),
+ crate_features = [
+ "default",
+ "std",
+ ],
+ crate_root = "src/lib.rs",
+ data = [],
+ edition = "2015",
+ rustc_flags = [
+ "--cap-lints=allow",
+ ],
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+ version = "0.2.77",
+ # buildifier: leave-alone
+ deps = [
+ ],
+)
+
+# Unsupported target "const_fn" with type "test" omitted
diff --git a/examples/sys/basic/raze/remote/BUILD.pkg-config-0.3.18.bazel b/examples/sys/basic/raze/remote/BUILD.pkg-config-0.3.18.bazel
new file mode 100644
index 0000000..0121432
--- /dev/null
+++ b/examples/sys/basic/raze/remote/BUILD.pkg-config-0.3.18.bazel
@@ -0,0 +1,55 @@
+"""
+@generated
+cargo-raze crate build file.
+
+DO NOT EDIT! Replaced on runs of cargo-raze
+"""
+
+# buildifier: disable=load
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+# buildifier: disable=load
+load(
+ "@rules_rust//rust:defs.bzl",
+ "rust_binary",
+ "rust_library",
+ "rust_proc_macro",
+ "rust_test",
+)
+
+package(default_visibility = [
+ # Public for visibility by "@raze__crate__version//" targets.
+ #
+ # Prefer access through "//sys/basic/raze", which limits external
+ # visibility to explicit Cargo.toml dependencies.
+ "//visibility:public",
+])
+
+licenses([
+ "notice", # MIT from expression "MIT OR Apache-2.0"
+])
+
+# Generated Targets
+
+rust_library(
+ name = "pkg_config",
+ srcs = glob(["**/*.rs"]),
+ crate_features = [
+ ],
+ crate_root = "src/lib.rs",
+ data = [],
+ edition = "2015",
+ rustc_flags = [
+ "--cap-lints=allow",
+ ],
+ tags = [
+ "cargo-raze",
+ "manual",
+ ],
+ version = "0.3.18",
+ # buildifier: leave-alone
+ deps = [
+ ],
+)
+
+# Unsupported target "test" with type "test" omitted
diff --git a/examples/sys/basic/src/main.rs b/examples/sys/basic/src/main.rs
new file mode 100644
index 0000000..a02bdb0
--- /dev/null
+++ b/examples/sys/basic/src/main.rs
@@ -0,0 +1,42 @@
+use bzip2::read::BzEncoder;
+use bzip2::Compression;
+use std::io::Read;
+
+fn main() {
+ let stdin = std::io::stdin();
+ let stdin = stdin.lock();
+ let mut raw_counter = CountingStream::new(stdin);
+
+ let compressed_count = {
+ let compressor = BzEncoder::new(&mut raw_counter, Compression::Best);
+ let mut compressed_counter = CountingStream::new(compressor);
+ std::io::copy(&mut compressed_counter, &mut std::io::sink()).unwrap();
+ compressed_counter.count
+ };
+
+ println!(
+ "Compressed {} to {} bytes",
+ raw_counter.count, compressed_count
+ );
+}
+
+struct CountingStream<R: Read> {
+ stream: R,
+ count: usize,
+}
+
+impl<R: Read> CountingStream<R> {
+ fn new(stream: R) -> Self {
+ CountingStream { stream, count: 0 }
+ }
+}
+
+impl<R: Read> Read for CountingStream<R> {
+ fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
+ let result = self.stream.read(buf);
+ if let Ok(read_bytes) = result {
+ self.count += read_bytes;
+ }
+ result
+ }
+}
diff --git a/examples/sys/basic/test.sh b/examples/sys/basic/test.sh
new file mode 100755
index 0000000..b2aa8e0
--- /dev/null
+++ b/examples/sys/basic/test.sh
@@ -0,0 +1,5 @@
+#!/bin/bash -eu
+
+out="$(echo -n "Hello world" | "$1")"
+
+[[ "${out}" == "Compressed 11 to 50 bytes" ]] || (echo "Got ${out}" && exit 1)