]> git.lizzy.rs Git - rust.git/blob - src/etc/make-win-dist.py
windows: Copy libwinpthread-1.dll into libdir bin
[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 # rust_root - root directory of the host binaries image
37 # plat_root - root directory of the target platform tools and libs image
38 #             (the two get overlayed on top of each other during installation)
39 # target_triple - triple of the target image being layed out
40 def make_win_dist(rust_root, plat_root, target_triple):
41     # Ask gcc where it keeps its stuff
42     gcc_out = subprocess.check_output(["gcc.exe", "-print-search-dirs"])
43     bin_path = os.environ["PATH"].split(os.pathsep)
44     lib_path = []
45     for line in gcc_out.splitlines():
46         key, val = line.split(':', 1)
47         if key == "programs":
48             bin_path.extend(val.lstrip(' =').split(';'))
49         elif key == "libraries":
50             lib_path.extend(val.lstrip(' =').split(';'))
51
52     target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe",
53                     "libwinpthread-1.dll"]
54
55     rustc_dlls = ["libstdc++-6.dll", "libwinpthread-1.dll"]
56     if target_triple.startswith("i686-"):
57         rustc_dlls.append("libgcc_s_dw2-1.dll")
58     else:
59         rustc_dlls.append("libgcc_s_seh-1.dll")
60
61     target_libs = [ # MinGW libs
62                     "libgcc.a",
63                     "libgcc_eh.a",
64                     "libgcc_s.a",
65                     "libm.a",
66                     "libmingw32.a",
67                     "libmingwex.a",
68                     "libstdc++.a",
69                     "libiconv.a",
70                     "libmoldname.a",
71                     "libpthread.a",
72                     # Windows import libs
73                     "libadvapi32.a",
74                     "libbcrypt.a",
75                     "libcomctl32.a",
76                     "libcomdlg32.a",
77                     "libcrypt32.a",
78                     "libgdi32.a",
79                     "libimagehlp.a",
80                     "libiphlpapi.a",
81                     "libkernel32.a",
82                     "libmsvcrt.a",
83                     "libodbc32.a",
84                     "libole32.a",
85                     "liboleaut32.a",
86                     "libopengl32.a",
87                     "libpsapi.a",
88                     "librpcrt4.a",
89                     "libsetupapi.a",
90                     "libshell32.a",
91                     "libuser32.a",
92                     "libuserenv.a",
93                     "libuuid.a",
94                     "libwinhttp.a",
95                     "libwinmm.a",
96                     "libwinspool.a",
97                     "libws2_32.a",
98                     "libwsock32.a",
99                     ]
100
101     # Find mingw artifacts we want to bundle
102     target_tools = find_files(target_tools, bin_path)
103     rustc_dlls = find_files(rustc_dlls, bin_path)
104     target_libs = find_files(target_libs, lib_path)
105
106     # Copy runtime dlls next to rustc.exe
107     dist_bin_dir = os.path.join(rust_root, "bin")
108     for src in rustc_dlls:
109         shutil.copy(src, dist_bin_dir)
110
111     # Copy platform tools to platform-specific bin directory
112     target_bin_dir = os.path.join(plat_root, "lib", "rustlib", target_triple, "bin")
113     if not os.path.exists(target_bin_dir):
114         os.makedirs(target_bin_dir)
115     for src in target_tools:
116         shutil.copy(src, target_bin_dir)
117
118     # Copy platform libs to platform-specific lib directory
119     target_lib_dir = os.path.join(plat_root, "lib", "rustlib", target_triple, "lib")
120     if not os.path.exists(target_lib_dir):
121         os.makedirs(target_lib_dir)
122     for src in target_libs:
123         shutil.copy(src, target_lib_dir)
124
125 if __name__ == "__main__":
126     make_win_dist(sys.argv[1], sys.argv[2], sys.argv[3])