Skip to content

Commit

Permalink
Package rustc's mingw dependencies into Windows installer.
Browse files Browse the repository at this point in the history
gcc, ld, ar, dlltool, windres go into $(RUST)/bin/rustlib/<triple>/bin/
platform libraries and startup objects got into $(RUST)/bin/rustlib/<triple>/lib/
  • Loading branch information
vadimcn committed Sep 11, 2014
1 parent 0ac9e9b commit 7085b3e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 28 deletions.
2 changes: 1 addition & 1 deletion mk/dist.mk
Expand Up @@ -123,7 +123,7 @@ PKG_EXE = dist/$(PKG_NAME)-$(CFG_BUILD).exe
$(PKG_EXE): rust.iss modpath.iss upgrade.iss LICENSE.txt rust-logo.ico \
$(CSREQ3_T_$(CFG_BUILD)_H_$(CFG_BUILD)) \
dist-prepare-win
$(CFG_PYTHON) $(S)src/etc/copy-runtime-deps.py tmp/dist/win/bin $(CFG_BUILD)
$(CFG_PYTHON) $(S)src/etc/make-win-dist.py tmp/dist/win $(CFG_BUILD)
@$(call E, ISCC: $@)
$(Q)"$(CFG_ISCC)" $<

Expand Down
24 changes: 0 additions & 24 deletions src/etc/copy-runtime-deps.py

This file was deleted.

82 changes: 82 additions & 0 deletions src/etc/make-win-dist.py
@@ -0,0 +1,82 @@
# Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import sys, os, shutil, subprocess

def find_files(files, path):
found = []
for fname in files:
for dir in path:
filepath = os.path.normpath(os.path.join(dir, fname))
if os.path.isfile(filepath):
found.append(filepath)
break
else:
raise Exception("Could not find '%s' in %s" % (fname, path))
return found

def make_win_dist(dist_root, target_triple):
# Ask gcc where it keeps its' stuff
gcc_out = subprocess.check_output(["gcc.exe", "-print-search-dirs"])
bin_path = os.environ["PATH"].split(os.pathsep)
lib_path = []
for line in gcc_out.splitlines():
key, val = line.split(':', 1)
if key == "programs":
bin_path.extend(val.lstrip(' =').split(';'))
elif key == "libraries":
lib_path.extend(val.lstrip(' =').split(';'))

target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe", "windres.exe"]

rustc_dlls = ["libstdc++-6.dll"]
if target_triple.startswith("i686-"):
rustc_dlls.append("libgcc_s_dw2-1.dll")
else:
rustc_dlls.append("libgcc_s_seh-1.dll")

target_libs = ["crtbegin.o", "crtend.o", "crt2.o", "dllcrt2.o",
"libadvapi32.a", "libcrypt32.a", "libgcc.a", "libgcc_eh.a", "libgcc_s.a",
"libimagehlp.a", "libiphlpapi.a", "libkernel32.a", "libm.a", "libmingw32.a",
"libmingwex.a", "libmsvcrt.a", "libpsapi.a", "libshell32.a", "libstdc++.a",
"libuser32.a", "libws2_32.a", "libiconv.a", "libmoldname.a"]

# Find mingw artifacts we want to bundle
target_tools = find_files(target_tools, bin_path)
rustc_dlls = find_files(rustc_dlls, bin_path)
target_libs = find_files(target_libs, lib_path)

# Copy runtime dlls next to rustc.exe
dist_bin_dir = os.path.join(dist_root, "bin")
for src in rustc_dlls:
shutil.copy(src, dist_bin_dir)

# Copy platform tools (and another copy of runtime dlls) to platform-spcific bin directory
target_bin_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "bin")
if not os.path.exists(target_bin_dir):
os.makedirs(target_bin_dir)
for src in target_tools:
shutil.copy(src, target_bin_dir)

# Copy platform libs to platform-spcific lib directory
target_lib_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "lib")
if not os.path.exists(target_lib_dir):
os.makedirs(target_lib_dir)
for src in target_libs:
shutil.copy(src, target_lib_dir)

# Copy license files
lic_dir = os.path.join(dist_root, "bin", "third-party")
if os.path.exists(lic_dir):
shutil.rmtree(lic_dir) # copytree() won't overwrite existing files
shutil.copytree(os.path.join(os.path.dirname(__file__), "third-party"), lic_dir)

if __name__=="__main__":
make_win_dist(sys.argv[1], sys.argv[2])
6 changes: 3 additions & 3 deletions src/etc/snapshot.py
Expand Up @@ -157,9 +157,9 @@ def get_winnt_runtime_deps(platform):
path_dirs = os.environ["PATH"].split(os.pathsep)
for name in deps:
for dir in path_dirs:
matches = glob.glob(os.path.join(dir, name))
if matches:
runtime_deps.append(matches[0])
filepath = os.path.join(dir, name)
if os.path.isfile(filepath):
runtime_deps.append(filepath)
break
else:
raise Exception("Could not find runtime dependency: %s" % name)
Expand Down

5 comments on commit 7085b3e

@bors
Copy link
Contributor

@bors bors commented on 7085b3e Sep 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at vadimcn@7085b3e

@bors
Copy link
Contributor

@bors bors commented on 7085b3e Sep 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging vadimcn/rust/package-gcc = 7085b3e into auto

@bors
Copy link
Contributor

@bors bors commented on 7085b3e Sep 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vadimcn/rust/package-gcc = 7085b3e merged ok, testing candidate = 06c0b1d

@bors
Copy link
Contributor

@bors bors commented on 7085b3e Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 7085b3e Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 06c0b1d

Please sign in to comment.