[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 2d6bc53f52 4/4: Merge pull request #457 from yan
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 2d6bc53f52 4/4: Merge pull request #457 from yanchith/workspace-aware-compilation |
Date: |
Thu, 25 Aug 2022 09:59:15 -0400 (EDT) |
branch: elpa/rust-mode
commit 2d6bc53f526623e585aae5855a81a13b709df97d
Merge: 894487d44c c91d4ddad8
Author: brotzeit <brotzeitmacher@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #457 from yanchith/workspace-aware-compilation
Make compilation buffer workspace-aware
---
rust-cargo.el | 38 ++++++++++++++++++--------------------
test-project/Cargo.toml | 11 ++++++++++-
test-project/src/lib.rs | 4 ++++
3 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/rust-cargo.el b/rust-cargo.el
index 0c35ddb150..cfbcd819a7 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 f741b14a34..7e9bea9f70 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 0000000000..cdc8599312
--- /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.
+}