Use a vec, not set for rustc_flags for crate_universe annotations (#1404)

* Use a vec, not set for rustc_flags for crate_universe annotations

* Remove TODO
diff --git a/crate_universe/src/context/crate_context.rs b/crate_universe/src/context/crate_context.rs
index 8ba2ace..923fa1e 100644
--- a/crate_universe/src/context/crate_context.rs
+++ b/crate_universe/src/context/crate_context.rs
@@ -101,8 +101,8 @@
     #[serde(skip_serializing_if = "SelectStringList::should_skip_serializing")]
     pub rustc_env_files: SelectStringList,
 
-    #[serde(skip_serializing_if = "SelectStringList::should_skip_serializing")]
-    pub rustc_flags: SelectStringList,
+    #[serde(skip_serializing_if = "Vec::is_empty")]
+    pub rustc_flags: Vec<String>,
 
     pub version: String,
 
@@ -421,12 +421,8 @@
             }
 
             // Rustc flags
-            // TODO: SelectList is currently backed by `BTreeSet` which is generally incorrect
-            // for rustc flags. Should SelectList be refactored?
             if let Some(extra) = &crate_extra.rustc_flags {
-                for data in extra.iter() {
-                    self.common_attrs.rustc_flags.insert(data.clone(), None);
-                }
+                self.common_attrs.rustc_flags.append(&mut extra.clone());
             }
 
             // Rustc env
diff --git a/crate_universe/src/rendering.rs b/crate_universe/src/rendering.rs
index a0570ba..3fba700 100644
--- a/crate_universe/src/rendering.rs
+++ b/crate_universe/src/rendering.rs
@@ -211,7 +211,7 @@
 
     use crate::config::{Config, CrateId, VendorMode};
     use crate::context::crate_context::{CrateContext, Rule};
-    use crate::context::{BuildScriptAttributes, Context, TargetAttributes};
+    use crate::context::{BuildScriptAttributes, CommonAttributes, Context, TargetAttributes};
     use crate::metadata::Annotations;
     use crate::test;
 
@@ -467,4 +467,54 @@
         // Local vendoring does not produce a `crates.bzl` file.
         assert!(output.get(&PathBuf::from("crates.bzl")).is_none());
     }
+
+    #[test]
+    fn duplicate_rustc_flags() {
+        let mut context = Context::default();
+        let crate_id = CrateId::new("mock_crate".to_owned(), "0.1.0".to_owned());
+
+        let rustc_flags = vec![
+            "-l".to_owned(),
+            "dylib=ssl".to_owned(),
+            "-l".to_owned(),
+            "dylib=crypto".to_owned(),
+        ];
+
+        context.crates.insert(
+            crate_id.clone(),
+            CrateContext {
+                name: crate_id.name,
+                version: crate_id.version,
+                targets: vec![Rule::Library(mock_target_attributes())],
+                common_attrs: CommonAttributes {
+                    rustc_flags: rustc_flags.clone(),
+                    ..CommonAttributes::default()
+                },
+                ..CrateContext::default()
+            },
+        );
+
+        // Enable local vendor mode
+        let config = RenderConfig {
+            vendor_mode: Some(VendorMode::Local),
+            ..mock_render_config()
+        };
+
+        let renderer = Renderer::new(config);
+        let output = renderer.render(&context).unwrap();
+
+        let build_file_content = output
+            .get(&PathBuf::from("BUILD.mock_crate-0.1.0.bazel"))
+            .unwrap();
+
+        // Strip all spaces from the generated BUILD file and ensure it has the flags
+        // represented by `rustc_flags` in the same order.
+        assert!(build_file_content.replace(' ', "").contains(
+            &rustc_flags
+                .iter()
+                .map(|s| format!("\"{}\",", s))
+                .collect::<Vec<String>>()
+                .join("\n")
+        ));
+    }
 }
diff --git a/crate_universe/src/rendering/templates/partials/crate/build_script.j2 b/crate_universe/src/rendering/templates/partials/crate/build_script.j2
index 1aa91bc..9b1ff45 100644
--- a/crate_universe/src/rendering/templates/partials/crate/build_script.j2
+++ b/crate_universe/src/rendering/templates/partials/crate/build_script.j2
@@ -39,7 +39,14 @@
         # warnings. For more details see: 
         # https://doc.rust-lang.org/rustc/lints/levels.html
         "--cap-lints=allow",
-    ] + {% set selectable = crate.build_script_attrs | get(key="rustc_flags", default=Null) %}{% include "partials/starlark/selectable_list.j2" %},
+        {%- if crate.common_attrs | get(key="rustc_flags", default=Null) %}
+
+        # User provided rustc_flags
+        {%- for rustc_flag in crate.common_attrs.rustc_flags %}
+        "{{ rustc_flag }}",
+        {%- endfor %}
+        {%- endif %}
+    ],
     srcs = {% set glob = target.srcs %}{% include "partials/starlark/glob.j2" -%},
     tools = {% set selectable = crate.build_script_attrs | get(key="tools", default=Null) %}{% include "partials/starlark/selectable_list.j2" %},
     version = "{{ crate.common_attrs.version }}",
diff --git a/crate_universe/src/rendering/templates/partials/crate/common_attrs.j2 b/crate_universe/src/rendering/templates/partials/crate/common_attrs.j2
index a381f44..7b1145b 100644
--- a/crate_universe/src/rendering/templates/partials/crate/common_attrs.j2
+++ b/crate_universe/src/rendering/templates/partials/crate/common_attrs.j2
@@ -18,7 +18,14 @@
         # warnings. For more details see: 
         # https://doc.rust-lang.org/rustc/lints/levels.html
         "--cap-lints=allow",
-    ] + {% set selectable = crate.common_attrs | get(key="rustc_flags", default=Null) %}{% include "partials/starlark/selectable_list.j2" -%},
+        {%- if crate.common_attrs | get(key="rustc_flags", default=Null) %}
+
+        # User provided rustc_flags
+        {%- for rustc_flag in crate.common_attrs.rustc_flags %}
+        "{{ rustc_flag }}",
+        {%- endfor %}
+        {%- endif %}
+    ],
     srcs = {% set glob = target.srcs %}{% include "partials/starlark/glob.j2" -%},
     version = "{{ crate.common_attrs.version }}",
     tags = [