8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- //! A helper module to probe the Windows Registry when looking for
12
- //! windows-specific tools.
11
+ //! A helper module to looking for windows-specific tools:
12
+ //! 1. On Windows host, probe the Windows Registry if needed;
13
+ //! 2. On non-Windows host, check specified environment variables.
13
14
14
15
use std:: process:: Command ;
15
16
16
17
use crate :: Tool ;
17
- #[ cfg( windows) ]
18
18
use crate :: ToolFamily ;
19
19
20
- #[ cfg( windows) ]
21
20
const MSVC_FAMILY : ToolFamily = ToolFamily :: Msvc { clang_cl : false } ;
22
21
23
- /// Attempts to find a tool within an MSVC installation using the Windows
24
- /// registry as a point to search from.
22
+ /// Attempts to find a tool within an MSVC installation:
23
+ /// 1. On Windows host, using the Windows registry as a point to search from;
24
+ /// 2. On non-Windows host, using related environment variables to search from.
25
+ ///
25
26
///
26
27
/// The `target` argument is the target that the tool should work for (e.g.
27
28
/// compile or link for) and the `tool` argument is the tool to find (e.g.
@@ -39,13 +40,6 @@ pub fn find(target: &str, tool: &str) -> Option<Command> {
39
40
/// Similar to the `find` function above, this function will attempt the same
40
41
/// operation (finding a MSVC tool in a local install) but instead returns a
41
42
/// `Tool` which may be introspected.
42
- #[ cfg( not( windows) ) ]
43
- pub fn find_tool ( _target : & str , _tool : & str ) -> Option < Tool > {
44
- None
45
- }
46
-
47
- /// Documented above.
48
- #[ cfg( windows) ]
49
43
pub fn find_tool ( target : & str , tool : & str ) -> Option < Tool > {
50
44
// This logic is all tailored for MSVC, if we're not that then bail out
51
45
// early.
@@ -54,12 +48,13 @@ pub fn find_tool(target: &str, tool: &str) -> Option<Tool> {
54
48
}
55
49
56
50
// Looks like msbuild isn't located in the same location as other tools like
57
- // cl.exe and lib.exe. To handle this we probe for it manually with
58
- // dedicated registry keys.
51
+ // cl.exe and lib.exe.
59
52
if tool. contains ( "msbuild" ) {
60
53
return impl_:: find_msbuild ( target) ;
61
54
}
62
55
56
+ // Looks like devenv isn't located in the same location as other tools like
57
+ // cl.exe and lib.exe.
63
58
if tool. contains ( "devenv" ) {
64
59
return impl_:: find_devenv ( target) ;
65
60
}
@@ -152,6 +147,7 @@ pub fn find_vs_version() -> Result<VsVers, String> {
152
147
}
153
148
}
154
149
150
+ /// Windows Implementation.
155
151
#[ cfg( windows) ]
156
152
mod impl_ {
157
153
use crate :: com;
@@ -882,6 +878,7 @@ mod impl_ {
882
878
}
883
879
}
884
880
881
+ // To find devenv we probe for it manually with dedicated registry keys.
885
882
pub fn find_devenv ( target : & str ) -> Option < Tool > {
886
883
find_devenv_vs15 ( & target)
887
884
}
@@ -890,6 +887,7 @@ mod impl_ {
890
887
find_tool_in_vs15_path ( r"Common7\IDE\devenv.exe" , target)
891
888
}
892
889
890
+ // To find msbuild we probe for it manually with dedicated registry keys.
893
891
// see http://stackoverflow.com/questions/328017/path-to-msbuild
894
892
pub fn find_msbuild ( target : & str ) -> Option < Tool > {
895
893
// VS 15 (2017) changed how to locate msbuild
@@ -927,3 +925,64 @@ mod impl_ {
927
925
} )
928
926
}
929
927
}
928
+
929
+ /// Non-Windows Implementation.
930
+ #[ cfg( not( windows) ) ]
931
+ mod impl_ {
932
+ use std:: { env, ffi:: OsString } ;
933
+
934
+ use super :: MSVC_FAMILY ;
935
+ use crate :: Tool ;
936
+
937
+ /// Finding msbuild.exe tool under unix system is not currently supported.
938
+ /// Maybe can check it using an environment variable looks like `MSBUILD_BIN`.
939
+ pub fn find_msbuild ( _target : & str ) -> Option < Tool > {
940
+ None
941
+ }
942
+
943
+ // Finding devenv.exe tool under unix system is not currently supported.
944
+ // Maybe can check it using an environment variable looks like `DEVENV_BIN`.
945
+ pub fn find_devenv ( _target : & str ) -> Option < Tool > {
946
+ None
947
+ }
948
+
949
+ /// Attempt to find the tool using environment variables set by vcvars.
950
+ pub fn find_msvc_environment ( tool : & str , _target : & str ) -> Option < Tool > {
951
+ // Early return if the environment doesn't contain a VC install.
952
+ let _vc_install_dir = env:: var_os ( "VCINSTALLDIR" ) ?;
953
+ let vs_install_dir = env:: var_os ( "VSINSTALLDIR" ) ?;
954
+
955
+ let search = |path : OsString | {
956
+ env:: split_paths ( & path)
957
+ . map ( |p| p. join ( tool) )
958
+ . find ( |p| p. exists ( ) )
959
+ } ;
960
+
961
+ search ( vs_install_dir)
962
+ . or_else ( || {
963
+ // Fallback to simply using the current environment.
964
+ env:: var_os ( "PATH" ) . and_then ( search)
965
+ } )
966
+ . map ( |path| Tool :: with_family ( path. into ( ) , MSVC_FAMILY ) )
967
+ }
968
+
969
+ pub fn find_msvc_15plus ( _tool : & str , _target : & str ) -> Option < Tool > {
970
+ None
971
+ }
972
+
973
+ // For MSVC 14 we need to find the Universal CRT as well as either
974
+ // the Windows 10 SDK or Windows 8.1 SDK.
975
+ pub fn find_msvc_14 ( _tool : & str , _target : & str ) -> Option < Tool > {
976
+ None
977
+ }
978
+
979
+ // For MSVC 12 we need to find the Windows 8.1 SDK.
980
+ pub fn find_msvc_12 ( _tool : & str , _target : & str ) -> Option < Tool > {
981
+ None
982
+ }
983
+
984
+ // For MSVC 11 we need to find the Windows 8 SDK.
985
+ pub fn find_msvc_11 ( _tool : & str , _target : & str ) -> Option < Tool > {
986
+ None
987
+ }
988
+ }
0 commit comments