File tree 4 files changed +45
-2
lines changed
4 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 38
38
39
39
; ;; Code:
40
40
41
+ (eval-when-compile
42
+ (require 'pcase )
43
+ (require 'let-alist ))
44
+
41
45
(require 'dash )
42
46
(require 'flycheck )
43
47
(require 'seq )
44
48
(require 'json )
45
- (require 'let-alist )
46
49
47
50
(defun flycheck-rust-find-manifest (file-name )
48
51
" Get the Cargo.toml manifest for FILE-NAME.
@@ -146,7 +149,26 @@ description of the conventional Cargo project layout."
146
149
(file-name-directory manifest)))))
147
150
; ; If all else fails, just pick the first target
148
151
(car targets))))
149
- (let-alist target (cons (car .kind) .name)))))
152
+ (let-alist target (cons (flycheck-rust-normalize-target-kind .kind) .name)))))
153
+
154
+ (defun flycheck-rust-normalize-target-kind (kinds )
155
+ " Return the normalized target name from KIND.
156
+
157
+ KIND is a list of target name as returned by `cargo metadata',
158
+ which do not necessarily correspond to to target names that can
159
+ be passed as argument to `cargo rustc'.
160
+
161
+ The normalization returns a valid cargo target based on KINDS."
162
+ ; ; Assumption: we only care about the first kind name. Multiple kinds only
163
+ ; ; seem to happen for library crate types, and those all maps to the same
164
+ ; ; `lib' target.
165
+ (pcase (car kinds)
166
+ (`" dylib" " lib" )
167
+ (`" rlib" " lib" )
168
+ (`" staticlib" " lib" )
169
+ (`" cdylib" " lib" )
170
+ (`" proc-macro" " lib" )
171
+ (_ (car kinds))))
150
172
151
173
;;;### autoload
152
174
(defun flycheck-rust-setup ()
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " custom-lib-target"
3
+ version = " 0.1.0"
4
+
5
+ [lib ]
6
+ name = " foo"
7
+ crate-type = [" dylib" , " cdylib" ]
Original file line number Diff line number Diff line change
1
+ #[ cfg( test) ]
2
+ mod tests {
3
+ #[ test]
4
+ fn it_works ( ) {
5
+ }
6
+ }
Original file line number Diff line number Diff line change 35
35
(defun crate-file (file-name )
36
36
(expand-file-name file-name " tests/test-crate" ))
37
37
38
+ (defun lib-crate-file (file-name )
39
+ (expand-file-name file-name " tests/custom-lib-target" ))
40
+
38
41
(describe
39
42
" `flycheck-rust-find-cargo-target' associates"
40
43
107
110
(expect
108
111
(flycheck-rust-find-cargo-target (crate-file " benches/support/mod.rs" ))
109
112
:to-equal-one-of '(" bench" . " a" ) '(" bench" . " b" )))
113
+
114
+ (it " 'src/lib.rs' to the library target"
115
+ (expect
116
+ (car (flycheck-rust-find-cargo-target (lib-crate-file " src/lib.rs" )))
117
+ :to-equal " lib" ))
110
118
)
You can’t perform that action at this time.
0 commit comments