Navigation Menu

Skip to content

Commit

Permalink
Bug 1353541 Fix rustc in MinGW build r=froydnj,ted
Browse files Browse the repository at this point in the history
rustc generates .lib files for its libraries when compiling for Windows
(even using MinGW on Linux). But MinGW expects .a files. So we add in
rust-specific prefix and suffixes so MinGW builds can find the libs that
rustc generates. (And the RUST_LIB- variables default to the same vales
as the LIB_ variables otherwise.)

MozReview-Commit-ID: ClsA0YuJaxh

--HG--
extra : rebase_source : 7b46460c94ceb34b7a5a302ce91d3f1dca600041
  • Loading branch information
tomrittervg committed Apr 26, 2017
1 parent bdcfea4 commit f8c3899
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 6 deletions.
11 changes: 7 additions & 4 deletions build/moz.configure/rust.configure
Expand Up @@ -107,14 +107,14 @@ def rust_triple_alias(host_or_target):
"""
assert host_or_target in (host, target)

@depends(rustc, host_or_target, when=rust_compiler)
@depends(rustc, host_or_target, building_with_gcc, when=rust_compiler)
@imports('os')
@imports('subprocess')
@imports(_from='mozbuild.configure.util', _import='LineIO')
@imports(_from='mozbuild.shellutil', _import='quote')
@imports(_from='tempfile', _import='mkstemp')
@imports(_from='textwrap', _import='dedent')
def rust_target(rustc, host_or_target):
def rust_target(rustc, host_or_target, building_with_gcc):
# Rust's --target options are similar to, but not exactly the same
# as, the autoconf-derived targets we use. An example would be that
# Rust uses distinct target triples for targetting the GNU C++ ABI
Expand All @@ -130,6 +130,9 @@ def rust_triple_alias(host_or_target):
# Avoid having to write out os+kernel for all the platforms where
# they don't differ.
os_or_kernel = host_or_target.kernel if host_or_target.kernel == 'Linux' and host_or_target.os != 'Android' else host_or_target.os
# If we are targetting Windows but the compiler is gcc, we need to
# use a different rustc target
os_or_kernel = 'WINNT-MINGW' if building_with_gcc and host_or_target.kernel == 'WINNT' else os_or_kernel
rustc_target = {
# DragonFly
('x86_64', 'DragonFly'): 'x86_64-unknown-dragonfly',
Expand Down Expand Up @@ -163,10 +166,10 @@ def rust_triple_alias(host_or_target):
('arm', 'Android'): 'armv7-linux-androideabi',
('x86', 'Android'): 'i686-linux-android',
# Windows
# XXX better detection of CXX needed here, to figure out whether
# we need i686-pc-windows-gnu instead, since mingw32 builds work.
('x86', 'WINNT'): 'i686-pc-windows-msvc',
('x86_64', 'WINNT'): 'x86_64-pc-windows-msvc',
('x86', 'WINNT-MINGW'): 'i686-pc-windows-gnu',
('x86_64', 'WINNT-MINGW'): 'x86_64-pc-windows-gnu',
}.get((host_or_target.cpu, os_or_kernel), None)

if rustc_target is None:
Expand Down
2 changes: 2 additions & 0 deletions config/expandlibs_config.py
Expand Up @@ -17,8 +17,10 @@ def normalize_suffix(suffix):
AR_EXTRACT = substs['AR_EXTRACT'].replace('$(AR)', AR)
DLL_PREFIX = substs['DLL_PREFIX']
LIB_PREFIX = substs['LIB_PREFIX']
RUST_LIB_PREFIX = substs['RUST_LIB_PREFIX']
OBJ_SUFFIX = normalize_suffix(substs['OBJ_SUFFIX'])
LIB_SUFFIX = normalize_suffix(substs['LIB_SUFFIX'])
RUST_LIB_SUFFIX = normalize_suffix(substs['RUST_LIB_SUFFIX'])
DLL_SUFFIX = normalize_suffix(substs['DLL_SUFFIX'])
IMPORT_LIB_SUFFIX = normalize_suffix(substs['IMPORT_LIB_SUFFIX'])
LIBS_DESC_SUFFIX = normalize_suffix(substs['LIBS_DESC_SUFFIX'])
Expand Down
1 change: 1 addition & 0 deletions config/makefiles/debugmake.mk
Expand Up @@ -94,6 +94,7 @@ showbuild:
ACDEFINES \
BIN_SUFFIX \
LIB_SUFFIX \
RUST_LIB_SUFFIX \
DLL_SUFFIX \
IMPORT_LIB_SUFFIX \
INSTALL \
Expand Down
6 changes: 6 additions & 0 deletions js/src/old-configure.in
Expand Up @@ -408,9 +408,11 @@ AS='$(CC)'
AS_DASH_C_FLAG='-c'
DLL_PREFIX=lib
LIB_PREFIX=lib
RUST_LIB_PREFIX=lib
DLL_SUFFIX=.so
OBJ_SUFFIX=o
LIB_SUFFIX=a
RUST_LIB_SUFFIX=a
IMPORT_LIB_SUFFIX=
DIRENT_INO=d_ino
MOZ_USER_DIR=".mozilla"
Expand Down Expand Up @@ -673,8 +675,10 @@ case "$target" in
PKG_SKIP_STRIP=1
OBJ_SUFFIX=obj
LIB_SUFFIX=lib
RUST_LIB_SUFFIX=lib
DLL_PREFIX=
LIB_PREFIX=
RUST_LIB_PREFIX=
IMPORT_LIB_SUFFIX=lib
MKSHLIB='$(LINK) -NOLOGO -DLL -OUT:$@ -PDB:$(LINK_PDBFILE) $(DSO_LDOPTS)'
MKCSHLIB='$(LINK) -NOLOGO -DLL -OUT:$@ -PDB:$(LINK_PDBFILE) $(DSO_LDOPTS)'
Expand Down Expand Up @@ -2095,10 +2099,12 @@ AC_SUBST(DSO_CFLAGS)
AC_SUBST(DSO_PIC_CFLAGS)
AC_SUBST(DSO_LDOPTS)
AC_SUBST(LIB_PREFIX)
AC_SUBST(RUST_LIB_PREFIX)
AC_SUBST(DLL_PREFIX)
AC_SUBST(DLL_SUFFIX)
AC_DEFINE_UNQUOTED(MOZ_DLL_SUFFIX, "$DLL_SUFFIX")
AC_SUBST(LIB_SUFFIX)
AC_SUBST(RUST_LIB_SUFFIX)
AC_SUBST(OBJ_SUFFIX)
AC_SUBST(BIN_SUFFIX)
AC_SUBST(IMPORT_LIB_SUFFIX)
Expand Down
8 changes: 8 additions & 0 deletions old-configure.in
Expand Up @@ -506,9 +506,11 @@ AS='$(CC)'
AS_DASH_C_FLAG='-c'
DLL_PREFIX=lib
LIB_PREFIX=lib
RUST_LIB_PREFIX=lib
DLL_SUFFIX=.so
OBJ_SUFFIX=o
LIB_SUFFIX=a
RUST_LIB_SUFFIX=a
IMPORT_LIB_SUFFIX=
DIRENT_INO=d_ino
MOZ_USER_DIR=".mozilla"
Expand Down Expand Up @@ -926,6 +928,8 @@ case "$target" in
MOZ_FIX_LINK_PATHS=
DLL_PREFIX=
IMPORT_LIB_SUFFIX=a
RUST_LIB_PREFIX=
RUST_LIB_SUFFIX=lib

WIN32_CONSOLE_EXE_LDFLAGS=-mconsole
WIN32_GUI_EXE_LDFLAGS=-mwindows
Expand All @@ -948,8 +952,10 @@ case "$target" in
PKG_SKIP_STRIP=1
OBJ_SUFFIX=obj
LIB_SUFFIX=lib
RUST_LIB_SUFFIX=lib
DLL_PREFIX=
LIB_PREFIX=
RUST_LIB_PREFIX=
IMPORT_LIB_SUFFIX=lib
MKSHLIB='$(LINK) -NOLOGO -DLL -OUT:$@ -PDB:$(LINK_PDBFILE) $(DSO_LDOPTS)'
MKCSHLIB='$(LINK) -NOLOGO -DLL -OUT:$@ -PDB:$(LINK_PDBFILE) $(DSO_LDOPTS)'
Expand Down Expand Up @@ -5322,10 +5328,12 @@ AC_SUBST(DSO_CFLAGS)
AC_SUBST(DSO_PIC_CFLAGS)
AC_SUBST(DSO_LDOPTS)
AC_SUBST(LIB_PREFIX)
AC_SUBST(RUST_LIB_PREFIX)
AC_SUBST(DLL_PREFIX)
AC_SUBST(DLL_SUFFIX)
AC_DEFINE_UNQUOTED(MOZ_DLL_SUFFIX, "$DLL_SUFFIX")
AC_SUBST(LIB_SUFFIX)
AC_SUBST(RUST_LIB_SUFFIX)
AC_SUBST(OBJ_SUFFIX)
AC_SUBST(BIN_SUFFIX)
AC_SUBST(IMPORT_LIB_SUFFIX)
Expand Down
3 changes: 3 additions & 0 deletions python/mozbuild/mozbuild/backend/configenvironment.py
Expand Up @@ -125,8 +125,11 @@ def __init__(self, topsrcdir, topobjdir, defines=None,
self.topobjdir = mozpath.abspath(topobjdir)
self.mozconfig = mozpath.abspath(mozconfig) if mozconfig else None
self.lib_prefix = self.substs.get('LIB_PREFIX', '')
self.rust_lib_prefix = self.substs.get('RUST_LIB_PREFIX', '')
if 'LIB_SUFFIX' in self.substs:
self.lib_suffix = '.%s' % self.substs['LIB_SUFFIX']
if 'RUST_LIB_SUFFIX' in self.substs:
self.rust_lib_suffix = '.%s' % self.substs['RUST_LIB_SUFFIX']
self.dll_prefix = self.substs.get('DLL_PREFIX', '')
self.dll_suffix = self.substs.get('DLL_SUFFIX', '')
if self.substs.get('IMPORT_LIB_SUFFIX'):
Expand Down
4 changes: 2 additions & 2 deletions python/mozbuild/mozbuild/frontend/data.py
Expand Up @@ -539,9 +539,9 @@ def __init__(self, context, basename, cargo_file, crate_type, dependencies,
# filenames. But we need to keep the basename consistent because
# many other things in the build system depend on that.
assert self.crate_type == 'staticlib'
self.lib_name = '%s%s%s' % (context.config.lib_prefix,
self.lib_name = '%s%s%s' % (context.config.rust_lib_prefix,
basename.replace('-', '_'),
context.config.lib_suffix)
context.config.rust_lib_suffix)
self.dependencies = dependencies
build_dir = mozpath.join(target_dir,
cargo_output_directory(context, self.TARGET_SUBST_VAR))
Expand Down
10 changes: 10 additions & 0 deletions python/mozbuild/mozbuild/test/backend/common.py
Expand Up @@ -48,7 +48,9 @@
'non_global_defines': [],
'substs': {
'LIB_PREFIX': 'lib',
'RUST_LIB_PREFIX': 'lib',
'LIB_SUFFIX': 'a',
'RUST_LIB_SUFFIX': 'a',
'COMPILE_ENVIRONMENT': '1',
},
},
Expand All @@ -59,7 +61,9 @@
'COMPILE_ENVIRONMENT': '1',
'RUST_TARGET': 'x86_64-unknown-linux-gnu',
'LIB_PREFIX': 'lib',
'RUST_LIB_PREFIX': 'lib',
'LIB_SUFFIX': 'a',
'RUST_LIB_SUFFIX': 'a',
},
},
'host-rust-library': {
Expand All @@ -70,7 +74,9 @@
'RUST_HOST_TARGET': 'x86_64-unknown-linux-gnu',
'RUST_TARGET': 'armv7-linux-androideabi',
'LIB_PREFIX': 'lib',
'RUST_LIB_PREFIX': 'lib',
'LIB_SUFFIX': 'a',
'RUST_LIB_SUFFIX': 'a',
},
},
'host-rust-library-features': {
Expand All @@ -81,7 +87,9 @@
'RUST_HOST_TARGET': 'x86_64-unknown-linux-gnu',
'RUST_TARGET': 'armv7-linux-androideabi',
'LIB_PREFIX': 'lib',
'RUST_LIB_PREFIX': 'lib',
'LIB_SUFFIX': 'a',
'RUST_LIB_SUFFIX': 'a',
},
},
'rust-library-features': {
Expand All @@ -91,7 +99,9 @@
'COMPILE_ENVIRONMENT': '1',
'RUST_TARGET': 'x86_64-unknown-linux-gnu',
'LIB_PREFIX': 'lib',
'RUST_LIB_PREFIX': 'lib',
'LIB_SUFFIX': 'a',
'RUST_LIB_SUFFIX': 'a',
},
},
'rust-programs': {
Expand Down
2 changes: 2 additions & 0 deletions python/mozbuild/mozbuild/test/common.py
Expand Up @@ -42,7 +42,9 @@ def __init__(self,

self.external_source_dir = None
self.lib_prefix = 'lib'
self.rust_lib_prefix = 'lib'
self.lib_suffix = '.a'
self.rust_lib_suffix = '.a'
self.import_prefix = 'lib'
self.import_suffix = '.so'
self.dll_prefix = 'lib'
Expand Down

0 comments on commit f8c3899

Please sign in to comment.