Deprecate out dir tar (#360)

This attribute force the usage of tar as part of the build which
is problematic for various platform. Instead of adding support
for it in native format, just remove this one as we have
the cargo_build_script rule.
diff --git a/docs/flatten.md b/docs/flatten.md
index 41401ad..8797b67 100644
--- a/docs/flatten.md
+++ b/docs/flatten.md
@@ -119,7 +119,7 @@
 | <a id="rust_benchmark-data"></a>data |  List of files used by this rule at runtime.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_benchmark-deps"></a>deps |  List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_benchmark-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
-| <a id="rust_benchmark-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_benchmark-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_benchmark-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_benchmark-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_benchmark-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
@@ -237,7 +237,7 @@
 | <a id="rust_binary-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
 | <a id="rust_binary-linker_script"></a>linker_script |  Link script to forward into linker via rustc options.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_binary-out_binary"></a>out_binary |  -   | Boolean | optional | False |
-| <a id="rust_binary-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_binary-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_binary-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_binary-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_binary-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
@@ -502,7 +502,7 @@
 | <a id="rust_library-data"></a>data |  List of files used by this rule at runtime.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_library-deps"></a>deps |  List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_library-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
-| <a id="rust_library-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_library-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_library-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_library-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_library-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
@@ -771,7 +771,7 @@
 | <a id="rust_test-data"></a>data |  List of files used by this rule at runtime.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_test-deps"></a>deps |  List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_test-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
-| <a id="rust_test-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_test-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_test-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_test-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_test-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
diff --git a/docs/rust.md b/docs/rust.md
index ab986f1..89c1bfc 100644
--- a/docs/rust.md
+++ b/docs/rust.md
@@ -106,7 +106,7 @@
 | <a id="rust_benchmark-data"></a>data |  List of files used by this rule at runtime.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_benchmark-deps"></a>deps |  List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_benchmark-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
-| <a id="rust_benchmark-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_benchmark-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_benchmark-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_benchmark-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_benchmark-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
@@ -224,7 +224,7 @@
 | <a id="rust_binary-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
 | <a id="rust_binary-linker_script"></a>linker_script |  Link script to forward into linker via rustc options.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_binary-out_binary"></a>out_binary |  -   | Boolean | optional | False |
-| <a id="rust_binary-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_binary-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_binary-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_binary-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_binary-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
@@ -319,7 +319,7 @@
 | <a id="rust_library-data"></a>data |  List of files used by this rule at runtime.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_library-deps"></a>deps |  List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_library-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
-| <a id="rust_library-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_library-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_library-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_library-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_library-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
@@ -485,7 +485,7 @@
 | <a id="rust_test-data"></a>data |  List of files used by this rule at runtime.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [<code>include_str!</code>](https://doc.rust-lang.org/std/macro.include_str!.html) macro.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_test-deps"></a>deps |  List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_test-edition"></a>edition |  The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.   | String | optional | "" |
-| <a id="rust_test-out_dir_tar"></a>out_dir_tar |  An optional tar or tar.gz file unpacked and passed as OUT_DIR.<br><br>Many library crates in the Rust ecosystem require sources to be provided to them in the form of an OUT_DIR argument. This argument can be used to supply the contents of this directory.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
+| <a id="rust_test-out_dir_tar"></a>out_dir_tar |  __Deprecated__, do not use, see [#cargo_build_script] instead.   | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
 | <a id="rust_test-proc_macro_deps"></a>proc_macro_deps |  List of <code>rust_library</code> targets with kind <code>proc-macro</code> used to help build this library target.   | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
 | <a id="rust_test-rustc_env"></a>rustc_env |  Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.   | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
 | <a id="rust_test-rustc_flags"></a>rustc_flags |  List of compiler flags passed to <code>rustc</code>.   | List of strings | optional | [] |
diff --git a/examples/hello_out_dir/BUILD b/examples/hello_out_dir/BUILD
deleted file mode 100644
index f291e1b..0000000
--- a/examples/hello_out_dir/BUILD
+++ /dev/null
@@ -1,24 +0,0 @@
-load(
-    "@io_bazel_rules_rust//rust:rust.bzl",
-    "rust_binary",
-    "rust_library",
-    "rust_test",
-)
-
-rust_library(
-    name = "hello_out_dir",
-    srcs = ["src/lib.rs"],
-    out_dir_tar = ":repacked_srcs.tar.gz",
-)
-
-rust_binary(
-    name = "hello_out_dir_bin",
-    srcs = ["src/main.rs"],
-    out_dir_tar = ":repacked_srcs.tar.gz",
-)
-
-rust_test(
-    name = "hello_out_dir_test",
-    crate = ":hello_out_dir",
-    out_dir_tar = ":repacked_srcs.tar.gz",
-)
diff --git a/examples/hello_out_dir/repacked_srcs.tar.gz b/examples/hello_out_dir/repacked_srcs.tar.gz
deleted file mode 100644
index 156fdf2..0000000
--- a/examples/hello_out_dir/repacked_srcs.tar.gz
+++ /dev/null
Binary files differ
diff --git a/examples/hello_out_dir/src/lib.rs b/examples/hello_out_dir/src/lib.rs
deleted file mode 100644
index 62f0e8d..0000000
--- a/examples/hello_out_dir/src/lib.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-#[allow(dead_code)]
-struct Demo {
-    secret_number: i64,
-}
-
-impl Demo {
-    #[allow(dead_code)]
-    pub fn new() -> Demo {
-        Demo {
-            secret_number: include!(concat!(env!("OUT_DIR"), "/body.rs")),
-        }
-    }
-}
-
-#[cfg(test)]
-mod test {
-    #[test]
-    fn test_out_dir_contents() {
-        let secret_number = include!(concat!(env!("OUT_DIR"), "/body.rs"));
-        assert_eq!(secret_number, 8888);
-    }
-}
diff --git a/examples/hello_out_dir/src/main.rs b/examples/hello_out_dir/src/main.rs
deleted file mode 100644
index e53cdb4..0000000
--- a/examples/hello_out_dir/src/main.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-fn main() {
-    println!(
-        "The secret number was {}",
-        include!(concat!(env!("OUT_DIR"), "/body.rs"))
-    );
-}
diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl
index 467e837..b92cde5 100644
--- a/rust/private/rust.bzl
+++ b/rust/private/rust.bzl
@@ -48,6 +48,13 @@
 def _determine_output_hash(lib_rs):
     return repr(hash(lib_rs.path))
 
+def _deprecated_attributes(ctx):
+    if getattr(ctx.attr, "out_dir_tar", None):
+        fail(ctx, "".join([
+            "`out_dir_tar` is no longer supported, please use cargo/cargo_build_script.bzl ",
+            "instead. If you used `cargo raze`, please use version 0.3.3 or later.",
+        ]))
+
 def _determine_lib_name(name, crate_type, toolchain, lib_hash = ""):
     extension = None
     if crate_type in ("dylib", "cdylib", "proc-macro"):
@@ -110,6 +117,7 @@
 def _rust_library_impl(ctx):
     # Find lib.rs
     lib_rs = crate_root_src(ctx.attr, ctx.files.srcs)
+    _deprecated_attributes(ctx)
 
     toolchain = find_toolchain(ctx)
 
@@ -180,6 +188,7 @@
         test_binary: The File object for the test binary.
     """
     toolchain = find_toolchain(ctx)
+    _deprecated_attributes(ctx)
 
     if ctx.attr.crate:
         # Target is building the crate in `test` config
@@ -231,6 +240,7 @@
 
 def _rust_benchmark_impl(ctx):
     bench_script = ctx.outputs.executable
+    _deprecated_attributes(ctx)
 
     # Build the underlying benchmark binary.
     bench_binary = ctx.actions.declare_file(
@@ -347,13 +357,7 @@
         default = "0.0.0",
     ),
     "out_dir_tar": attr.label(
-        doc = _tidy("""
-            An optional tar or tar.gz file unpacked and passed as OUT_DIR.
-
-            Many library crates in the Rust ecosystem require sources to be provided
-            to them in the form of an OUT_DIR argument. This argument can be used to
-            supply the contents of this directory.
-        """),
+        doc = "__Deprecated__, do not use, see [#cargo_build_script] instead.",
         allow_single_file = [
             ".tar",
             ".tar.gz",
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
index c006615..303ecfd 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
@@ -518,10 +518,6 @@
         args.add("--edition={}".format(crate.edition))
 
 def _create_out_dir_action(ctx, file, build_info, dep_info):
-    tar_file_attr = getattr(file, "out_dir_tar", None)
-    if build_info and tar_file_attr:
-        fail("Target {} has both a build_script dependency and an out_dir_tar - this is not allowed.".format(ctx.label))
-
     prep_commands = []
     input_files = []
     # Env vars and build flags which need to be set in the action's command line, rather than on the action's env,
@@ -529,18 +525,11 @@
     dynamic_env = {}
     dynamic_build_flags = []
 
-    # TODO: Remove system tar usage
     if build_info:
         prep_commands.append("export $(cat %s)" % build_info.rustc_env.path)
         # out_dir will be added as input by the transitive_build_infos loop below.
         dynamic_env["OUT_DIR"] = "${{EXEC_ROOT}}/{}".format(build_info.out_dir.path)
         dynamic_build_flags.append("$(cat '%s')" % build_info.flags.path)
-    elif tar_file_attr:
-        out_dir = ".out-dir"
-        prep_commands.append("mkdir -p $OUT_DIR")
-        prep_commands.append("tar -xzf {tar} -C $OUT_DIR".format(tar=tar_file_attr.path))
-        input_files.append(tar_file_attr)
-        dynamic_env["OUT_DIR"] = "${{EXEC_ROOT}}/{}".format(out_dir)
 
     # This should probably only actually be exposed to actions which link.
     for dep_build_info in dep_info.transitive_build_infos.to_list():