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.
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.
11 import sys, os, shutil, subprocess
13 def find_files(files, path):
17 filepath = os.path.normpath(os.path.join(dir, fname))
18 if os.path.isfile(filepath):
19 found.append(filepath)
22 raise Exception("Could not find '%s' in %s" % (fname, path))
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)
30 for line in gcc_out.splitlines():
31 key, val = line.split(':', 1)
33 bin_path.extend(val.lstrip(' =').split(';'))
34 elif key == "libraries":
35 lib_path.extend(val.lstrip(' =').split(';'))
37 target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe", "windres.exe"]
39 rustc_dlls = ["libstdc++-6.dll"]
40 if target_triple.startswith("i686-"):
41 rustc_dlls.append("libgcc_s_dw2-1.dll")
43 rustc_dlls.append("libgcc_s_seh-1.dll")
45 target_libs = [ # MinGW libs
87 # Find mingw artifacts we want to bundle
88 target_tools = find_files(target_tools, bin_path)
89 rustc_dlls = find_files(rustc_dlls, bin_path)
90 target_libs = find_files(target_libs, lib_path)
92 # Copy runtime dlls next to rustc.exe
93 dist_bin_dir = os.path.join(dist_root, "bin")
94 for src in rustc_dlls:
95 shutil.copy(src, dist_bin_dir)
97 # Copy platform tools to platform-specific bin directory
98 target_bin_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "bin")
99 if not os.path.exists(target_bin_dir):
100 os.makedirs(target_bin_dir)
101 for src in target_tools:
102 shutil.copy(src, target_bin_dir)
104 # Copy platform libs to platform-spcific lib directory
105 target_lib_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "lib")
106 if not os.path.exists(target_lib_dir):
107 os.makedirs(target_lib_dir)
108 for src in target_libs:
109 shutil.copy(src, target_lib_dir)
112 lic_dir = os.path.join(dist_root, "bin", "third-party")
113 if os.path.exists(lic_dir):
114 shutil.rmtree(lic_dir) # copytree() won't overwrite existing files
115 shutil.copytree(os.path.join(os.path.dirname(__file__), "third-party"), lic_dir)
117 if __name__=="__main__":
118 make_win_dist(sys.argv[1], sys.argv[2])