Repository: rust-lang/cc-rs (rust)

Issue:
Target strings that end in -none (such as aarch64-unknown-none) should not default to -fPIC
According to the [docs](https://docs.rs/cc/latest/cc/struct.Build.html#method.pic)

> This [pic] option defaults to false for windows-gnu and bare metal targets and to true for all other targets.

This means the bare metal target `aarch64-unknown-none` should default to false, but the current logic only looks for `-none-`, and not `-none`.

Pull request description:
disable pic for targets that end in `-none`
This fixes #1211

Patch:
diff --git a/src/lib.rs b/src/lib.rs
index e963828..2a7e3a1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1983,6 +1983,7 @@ impl Build {
                 if self.pic.unwrap_or(
                     !target.contains("windows")
                         && !target.contains("-none-")
+                        && !target.ends_with("-none")
                         && !target.contains("uefi"),
                 ) {
                     cmd.push_cc_arg("-fPIC".into());


Test patch:
diff --git a/tests/test.rs b/tests/test.rs
index 5f31f3e..9d5ce50 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -269,6 +269,20 @@ fn gnu_x86_64_no_plt() {
     test.cmd(0).must_have("-fno-plt");
 }
 
+#[test]
+fn gnu_aarch64_none_no_pic() {
+    for target in &["aarch64-unknown-none-gnu", "aarch64-unknown-none"] {
+        let test = Test::gnu();
+        test.gcc()
+            .target(&target)
+            .host(&target)
+            .file("foo.c")
+            .compile("foo");
+
+        test.cmd(0).must_not_have("-fPIC");
+    }
+}
+
 #[test]
 fn gnu_set_stdlib() {
     reset_env();