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