]> git.lizzy.rs Git - rust.git/blob - src/etc/make-win-dist.py
rollup merge of #20258: sanxiyn/show-span-2
[rust.git] / src / etc / make-win-dist.py
1 # Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 # Script parameters:
12 #     argv[1] = rust component root,
13 #     argv[2] = gcc component root,
14 #     argv[3] = target triple
15 # The first two correspond to the two installable components defined in the setup script.
16
17 import sys, os, shutil, subprocess
18
19 def find_files(files, path):
20     found = []
21     for fname in files:
22         for dir in path:
23             filepath = os.path.normpath(os.path.join(dir, fname))
24             if os.path.isfile(filepath):
25                 found.append(filepath)
26                 break
27         else:
28             raise Exception("Could not find '%s' in %s" % (fname, path))
29     return found
30
31 def make_win_dist(rust_root, gcc_root, target_triple):
32     # Ask gcc where it keeps its stuff
33     gcc_out = subprocess.check_output(["gcc.exe", "-print-search-dirs"])
34     bin_path = os.environ["PATH"].split(os.pathsep)
35     lib_path = []
36     for line in gcc_out.splitlines():
37         key, val = line.split(':', 1)
38         if key == "programs":
39             bin_path.extend(val.lstrip(' =').split(';'))
40         elif key == "libraries":
41             lib_path.extend(val.lstrip(' =').split(';'))
42
43     target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe", "windres.exe"]
44
45     rustc_dlls = ["libstdc++-6.dll"]
46     if target_triple.startswith("i686-"):
47         rustc_dlls.append("libgcc_s_dw2-1.dll")
48     else:
49         rustc_dlls.append("libgcc_s_seh-1.dll")
50
51     target_libs = [ # MinGW libs
52                     "crtbegin.o",
53                     "crtend.o",
54                     "crt2.o",
55                     "dllcrt2.o",
56                     "libgcc.a",
57                     "libgcc_eh.a",
58                     "libgcc_s.a",
59                     "libm.a",
60                     "libmingw32.a",
61                     "libmingwex.a",
62                     "libstdc++.a",
63                     "libiconv.a",
64                     "libmoldname.a",
65                     # Windows import libs
66                     "libadvapi32.a",
67                     "libbcrypt.a",
68                     "libcomctl32.a",
69                     "libcomdlg32.a",
70                     "libcrypt32.a",
71                     "libgdi32.a",
72                     "libimagehlp.a",
73                     "libiphlpapi.a",
74                     "libkernel32.a",
75                     "libmsvcrt.a",
76                     "libodbc32.a",
77                     "libole32.a",
78                     "liboleaut32.a",
79                     "libopengl32.a",
80                     "libpsapi.a",
81                     "librpcrt4.a",
82                     "libsetupapi.a",
83                     "libshell32.a",
84                     "libuser32.a",
85                     "libuuid.a",
86                     "libwinhttp.a",
87                     "libwinmm.a",
88                     "libwinspool.a",
89                     "libws2_32.a",
90                     "libwsock32.a",
91                     ]
92
93     # Find mingw artifacts we want to bundle
94     target_tools = find_files(target_tools, bin_path)
95     rustc_dlls = find_files(rustc_dlls, bin_path)
96     target_libs = find_files(target_libs, lib_path)
97
98     # Copy runtime dlls next to rustc.exe
99     dist_bin_dir = os.path.join(rust_root, "bin")
100     for src in rustc_dlls:
101         shutil.copy(src, dist_bin_dir)
102
103     # Copy platform tools to platform-specific bin directory
104     target_bin_dir = os.path.join(gcc_root, "bin", "rustlib", target_triple, "bin")
105     if not os.path.exists(target_bin_dir):
106         os.makedirs(target_bin_dir)
107     for src in target_tools:
108         shutil.copy(src, target_bin_dir)
109
110     # Copy platform libs to platform-specific lib directory
111     target_lib_dir = os.path.join(gcc_root, "bin", "rustlib", target_triple, "lib")
112     if not os.path.exists(target_lib_dir):
113         os.makedirs(target_lib_dir)
114     for src in target_libs:
115         shutil.copy(src, target_lib_dir)
116
117 if __name__=="__main__":
118     make_win_dist(sys.argv[1], sys.argv[2], sys.argv[3])