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.
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.
23 def find_files(files, path):
27 filepath = os.path.normpath(os.path.join(dir, fname))
28 if os.path.isfile(filepath):
29 found.append(filepath)
32 raise Exception("Could not find '%s' in %s" % (fname, path))
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)
41 for line in gcc_out.splitlines():
42 key, val = line.split(':', 1)
44 bin_path.extend(val.lstrip(' =').split(';'))
45 elif key == "libraries":
46 lib_path.extend(val.lstrip(' =').split(';'))
48 target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe"]
50 rustc_dlls = ["libstdc++-6.dll"]
51 if target_triple.startswith("i686-"):
52 rustc_dlls.append("libgcc_s_dw2-1.dll")
54 rustc_dlls.append("libgcc_s_seh-1.dll")
56 target_libs = [ # MinGW libs
99 # Find mingw artifacts we want to bundle
100 target_tools = find_files(target_tools, bin_path)
101 rustc_dlls = find_files(rustc_dlls, bin_path)
102 target_libs = find_files(target_libs, lib_path)
104 # Copy runtime dlls next to rustc.exe
105 dist_bin_dir = os.path.join(rust_root, "bin")
106 for src in rustc_dlls:
107 shutil.copy(src, dist_bin_dir)
109 # Copy platform tools to platform-specific bin directory
110 target_bin_dir = os.path.join(gcc_root, "bin", "rustlib", target_triple, "bin")
111 if not os.path.exists(target_bin_dir):
112 os.makedirs(target_bin_dir)
113 for src in target_tools:
114 shutil.copy(src, target_bin_dir)
116 # Copy platform libs to platform-specific lib directory
117 target_lib_dir = os.path.join(gcc_root, "bin", "rustlib", target_triple, "lib")
118 if not os.path.exists(target_lib_dir):
119 os.makedirs(target_lib_dir)
120 for src in target_libs:
121 shutil.copy(src, target_lib_dir)
123 if __name__ == "__main__":
124 make_win_dist(sys.argv[1], sys.argv[2], sys.argv[3])