summaryrefslogtreecommitdiffstats
path: root/build/cargo
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbuild/cargo-host-linker3
-rw-r--r--build/cargo-host-linker.bat3
-rwxr-xr-xbuild/cargo-linker58
-rw-r--r--build/cargo-linker.bat2
-rw-r--r--build/cargo/cargo-audit.yaml6
-rw-r--r--build/cargo/cargo-check.yaml5
-rw-r--r--build/cargo/cargo-clippy.yaml4
-rw-r--r--build/cargo/cargo-deny.yaml10
-rw-r--r--build/cargo/cargo-machete.yaml4
-rw-r--r--build/cargo/cargo-udeps.yaml4
10 files changed, 99 insertions, 0 deletions
diff --git a/build/cargo-host-linker b/build/cargo-host-linker
new file mode 100755
index 0000000000..cbd0472bf7
--- /dev/null
+++ b/build/cargo-host-linker
@@ -0,0 +1,3 @@
+#!/bin/sh
+# See comment in cargo-linker.
+eval ${MOZ_CARGO_WRAP_HOST_LD} ${MOZ_CARGO_WRAP_HOST_LDFLAGS} '"$@"'
diff --git a/build/cargo-host-linker.bat b/build/cargo-host-linker.bat
new file mode 100644
index 0000000000..80e6eab273
--- /dev/null
+++ b/build/cargo-host-linker.bat
@@ -0,0 +1,3 @@
+@echo off
+REM See comment in cargo-linker (without extension)
+%MOZ_CARGO_WRAP_HOST_LD% %MOZ_CARGO_WRAP_HOST_LDFLAGS% %*
diff --git a/build/cargo-linker b/build/cargo-linker
new file mode 100755
index 0000000000..94b05f8213
--- /dev/null
+++ b/build/cargo-linker
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+# If you want to use a custom linker with Cargo, Cargo requires that you
+# specify it in Cargo.toml or via the matching environment variable.
+# Passing extra options to the linker is possible with Cargo via
+# RUSTFLAGS='-C link-args', but testing showed that doing this reliably
+# was difficult.
+#
+# Our solution to these problems is to use this wrapper script. We pass
+# in the LD and the LDFLAGS to use via environment variables.
+#
+# * MOZ_CARGO_WRAP_LD is equivalent to CC on Unix-y platforms, and CC
+# frequently has additional arguments in addition to the compiler
+# itself.
+#
+# * MOZ_CARGO_WRAP_LDFLAGS contains space-separated arguments to pass,
+# and not quoting it ensures that each of those arguments is passed
+# as a separate argument to the actual LD.
+#
+# * In rare cases, we also need MOZ_CARGO_WRAP_LD_CXX, which is the
+# equivalent of CXX, when linking C++ code. Usually, this should
+# simply work by the use of CC and -lstdc++ (added by cc-rs).
+# However, in the case of sanitizer runtimes, there is a separate
+# runtime for C and C++ and linking C++ code with the C runtime can
+# fail if the requested feature is in the C++ runtime only (bug 1747298).
+
+import os
+import sys
+
+SANITIZERS = {
+ "asan": "address",
+ "hwasan": "hwaddress",
+ "lsan": "leak",
+ "msan": "memory",
+ "tsan": "thread",
+}
+
+use_clang_sanitizer = os.environ.get("MOZ_CLANG_NEWER_THAN_RUSTC_LLVM")
+wrap_ld = os.environ["MOZ_CARGO_WRAP_LD"]
+args = os.environ["MOZ_CARGO_WRAP_LDFLAGS"].split()
+for arg in sys.argv[1:]:
+ if arg in ["-lc++", "-lstdc++"]:
+ wrap_ld = os.environ["MOZ_CARGO_WRAP_LD_CXX"]
+ elif use_clang_sanitizer and arg.endswith("san.a"):
+ # When clang is newer than rustc's LLVM, we replace rust's sanitizer
+ # runtimes with clang's.
+ filename = os.path.basename(arg)
+ prefix, dot, suffix = filename[:-2].rpartition(".")
+ if (
+ prefix.startswith("librustc-")
+ and prefix.endswith("_rt") and dot == "."
+ ):
+ args.append(f"-fsanitize={SANITIZERS[suffix]}")
+ continue
+ args.append(arg)
+
+wrap_ld = wrap_ld.split()
+os.execvp(wrap_ld[0], wrap_ld + args)
diff --git a/build/cargo-linker.bat b/build/cargo-linker.bat
new file mode 100644
index 0000000000..36ab80dac3
--- /dev/null
+++ b/build/cargo-linker.bat
@@ -0,0 +1,2 @@
+@echo off
+%MOZ_CARGO_WRAP_LD% %MOZ_CARGO_WRAP_LDFLAGS% %*
diff --git a/build/cargo/cargo-audit.yaml b/build/cargo/cargo-audit.yaml
new file mode 100644
index 0000000000..8efb56acff
--- /dev/null
+++ b/build/cargo/cargo-audit.yaml
@@ -0,0 +1,6 @@
+---
+command: cargo-audit
+continue_on_error: false
+cargo_build_flags:
+ - -f
+ - "{topsrcdir}/Cargo.lock"
diff --git a/build/cargo/cargo-check.yaml b/build/cargo/cargo-check.yaml
new file mode 100644
index 0000000000..54fe0fb825
--- /dev/null
+++ b/build/cargo/cargo-check.yaml
@@ -0,0 +1,5 @@
+---
+command: cargo-check
+continue_on_error: true
+# cargo_build_flags: []
+requires_export: true
diff --git a/build/cargo/cargo-clippy.yaml b/build/cargo/cargo-clippy.yaml
new file mode 100644
index 0000000000..427b3d6347
--- /dev/null
+++ b/build/cargo/cargo-clippy.yaml
@@ -0,0 +1,4 @@
+---
+command: cargo-clippy
+continue_on_error: true
+# cargo_build_flags: []
diff --git a/build/cargo/cargo-deny.yaml b/build/cargo/cargo-deny.yaml
new file mode 100644
index 0000000000..fde45e37d9
--- /dev/null
+++ b/build/cargo/cargo-deny.yaml
@@ -0,0 +1,10 @@
+---
+command: cargo-deny
+continue_on_error: true
+cargo_build_flags:
+ - --frozen
+ - --manifest-path
+ - "{manifest}"
+ - --target={arch}
+ - --features
+ - "{features}"
diff --git a/build/cargo/cargo-machete.yaml b/build/cargo/cargo-machete.yaml
new file mode 100644
index 0000000000..42ec301ee0
--- /dev/null
+++ b/build/cargo/cargo-machete.yaml
@@ -0,0 +1,4 @@
+---
+command: cargo-machete
+continue_on_error: true
+cargo_build_flags: ["{topsrcdir}/{directory}/Cargo.toml"]
diff --git a/build/cargo/cargo-udeps.yaml b/build/cargo/cargo-udeps.yaml
new file mode 100644
index 0000000000..a33cfcf873
--- /dev/null
+++ b/build/cargo/cargo-udeps.yaml
@@ -0,0 +1,4 @@
+---
+command: cargo-udeps
+continue_on_error: true
+# cargo_build_flags: []