]> git.lizzy.rs Git - rust.git/blob - src/etc/make-win-dist.py
Rollup merge of 21662 - oli-obk:hashmap_enum_json, r=alexcrichton
[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
18 import os
19 import shutil
20 import subprocess
21
22
23 def find_files(files, path):
24     found = []
25     for fname in files:
26         for dir in path:
27             filepath = os.path.normpath(os.path.join(dir, fname))
28             if os.path.isfile(filepath):
29                 found.append(filepath)
30                 break
31         else:
32             raise Exception("Could not find '%s' in %s" % (fname, path))
33     return found
34
35
36 def make_win_dist(rust_root, gcc_root, target_triple):
37     # Ask gcc where it keeps its stuff
38     gcc_out = subprocess.check_output(["gcc.exe", "-print-search-dirs"])
39     bin_path = os.environ["PATH"].split(os.pathsep)
40     lib_path = []
41     for line in gcc_out.splitlines():
42         key, val = line.split(':', 1)
43         if key == "programs":
44             bin_path.extend(val.lstrip(' =').split(';'))
45         elif key == "libraries":
46             lib_path.extend(val.lstrip(' =').split(';'))
47
48     target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe", "windres.exe"]
49
50     rustc_dlls = ["libstdc++-6.dll"]
51     if target_triple.startswith("i686-"):
52         rustc_dlls.append("libgcc_s_dw2-1.dll")
53     else:
54         rustc_dlls.append("libgcc_s_seh-1.dll")
55
56     target_libs = [ # MinGW libs
57                     "crtbegin.o",
58                     "crtend.o",
59                     "crt2.o",
60                     "dllcrt2.o",
61                     "libgcc.a",
62                     "libgcc_eh.a",
63                     "libgcc_s.a",
64                     "libm.a",
65                     "libmingw32.a",
66                     "libmingwex.a",
67                     "libstdc++.a",
68                     "libiconv.a",
69                     "libmoldname.a",
70                     # Windows import libs
71                     "libadvapi32.a",
72                     "libbcrypt.a",
73                     "libcomctl32.a",
74                     "libcomdlg32.a",
75                     "libcrypt32.a",
76                     "libgdi32.a",
77                     "libimagehlp.a",
78                     "libiphlpapi.a",
79                     "libkernel32.a",
80                     "libmsvcrt.a",
81                     "libodbc32.a",
82                     "libole32.a",
83                     "liboleaut32.a",
84                     "libopengl32.a",
85                     "libpsapi.a",
86                     "librpcrt4.a",
87                     "libsetupapi.a",
88                     "libshell32.a",
89                     "libuser32.a",
90                     "libuuid.a",
91                     "libwinhttp.a",
92                     "libwinmm.a",
93                     "libwinspool.a",
94                     "libws2_32.a",
95                     "libwsock32.a",
96                     ]
97
98     # Find mingw artifacts we want to bundle
99     target_tools = find_files(target_tools, bin_path)
100     rustc_dlls = find_files(rustc_dlls, bin_path)
101     target_libs = find_files(target_libs, lib_path)
102
103     # Copy runtime dlls next to rustc.exe
104     dist_bin_dir = os.path.join(rust_root, "bin")
105     for src in rustc_dlls:
106         shutil.copy(src, dist_bin_dir)
107
108     # Copy platform tools to platform-specific bin directory
109     target_bin_dir = os.path.join(gcc_root, "bin", "rustlib", target_triple, "bin")
110     if not os.path.exists(target_bin_dir):
111         os.makedirs(target_bin_dir)
112     for src in target_tools:
113         shutil.copy(src, target_bin_dir)
114
115     # Copy platform libs to platform-specific lib directory
116     target_lib_dir = os.path.join(gcc_root, "bin", "rustlib", target_triple, "lib")
117     if not os.path.exists(target_lib_dir):
118         os.makedirs(target_lib_dir)
119     for src in target_libs:
120         shutil.copy(src, target_lib_dir)
121
122 if __name__ == "__main__":
123     make_win_dist(sys.argv[1], sys.argv[2], sys.argv[3])