summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrotzeit <brotzeitmacher@gmail.com>2022-08-25 15:06:17 +0200
committerGitHub <noreply@github.com>2022-08-25 15:06:17 +0200
commit2d6bc53f526623e585aae5855a81a13b709df97d (patch)
tree236ce54544a20c9435c8835ae1ce6643be34e198
parent894487d44c1664a9005cafd625fa99b54ff66c85 (diff)
parentc91d4ddad81ced33bfaf54581f7fc2dc95e32b40 (diff)
downloadrust-mode-2d6bc53f526623e585aae5855a81a13b709df97d.tar.gz
Merge pull request #457 from yanchith/workspace-aware-compilation
Make compilation buffer workspace-aware
-rw-r--r--rust-cargo.el38
-rw-r--r--test-project/Cargo.toml11
-rw-r--r--test-project/src/lib.rs4
3 files changed, 32 insertions, 21 deletions
diff --git a/rust-cargo.el b/rust-cargo.el
index 0c35ddb..cfbcd81 100644
--- a/rust-cargo.el
+++ b/rust-cargo.el
@@ -30,26 +30,24 @@
(defun rust-buffer-project ()
"Get project root if possible."
- (if (file-remote-p default-directory)
- (rust-buffer-crate)
- ;; Copy environment variables into the new buffer, since
- ;; with-temp-buffer will re-use the variables' defaults, even if
- ;; they have been changed in this variable using e.g. envrc-mode.
- ;; See https://github.com/purcell/envrc/issues/12.
- (let ((env process-environment)
- (path exec-path))
- (with-temp-buffer
- ;; Copy the entire environment just in case there's something we
- ;; don't know we need.
- (setq-local process-environment env)
- ;; Set PATH so we can find cargo.
- (setq-local exec-path path)
- (let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
- (when (/= ret 0)
- (error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
- (goto-char 0)
- (let ((output (json-read)))
- (cdr (assoc-string "root" output))))))))
+ ;; Copy environment variables into the new buffer, since
+ ;; with-temp-buffer will re-use the variables' defaults, even if
+ ;; they have been changed in this variable using e.g. envrc-mode.
+ ;; See https://github.com/purcell/envrc/issues/12.
+ (let ((env process-environment)
+ (path exec-path))
+ (with-temp-buffer
+ ;; Copy the entire environment just in case there's something we
+ ;; don't know we need.
+ (setq-local process-environment env)
+ ;; Set PATH so we can find cargo.
+ (setq-local exec-path path)
+ (let ((ret (process-file rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project" "--workspace")))
+ (when (/= ret 0)
+ (error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
+ (goto-char 0)
+ (let ((output (json-read)))
+ (cdr (assoc-string "root" output)))))))
(defun rust-buffer-crate ()
"Try to locate Cargo.toml using `locate-dominating-file'."
diff --git a/test-project/Cargo.toml b/test-project/Cargo.toml
index f741b14..7e9bea9 100644
--- a/test-project/Cargo.toml
+++ b/test-project/Cargo.toml
@@ -1 +1,10 @@
-# Dummy file needed for test
+# Dummy file needed for test.
+#
+# Needs to have at least a few fields set up, because
+#
+# cargo locate-project --workspace
+#
+# will attempt to parse it and fail, if the file is empty.
+[package]
+name = "test-project"
+version = "0.1.0"
diff --git a/test-project/src/lib.rs b/test-project/src/lib.rs
new file mode 100644
index 0000000..cdc8599
--- /dev/null
+++ b/test-project/src/lib.rs
@@ -0,0 +1,4 @@
+pub fn test_project() {
+ // This is only present, because cargo locate-project --workspace actually
+ // validates the rust project and fails if there is no target.
+}