Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Add library alias for Rust libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol1234 committed Dec 5, 2017
1 parent bc47ec7 commit e5feb38
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
46 changes: 42 additions & 4 deletions mx.sulong/mx_sulong.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def extract_compiler_args(args, useDoubleDash=False):
def runLLVM(args=None, out=None):
"""uses Sulong to execute a LLVM IR file"""
vmArgs, sulongArgs = truffle_extract_VM_args(args)
return mx.run_java(getCommonOptions(False) + vmArgs + getClasspathOptions() + ["com.oracle.truffle.llvm.Sulong"] + sulongArgs, out=out)
return mx.run_java(getCommonOptions(False) + substituteLibAliases(vmArgs) + getClasspathOptions() + ["com.oracle.truffle.llvm.Sulong"] + sulongArgs, out=out)

def getCommonOptions(withAssertion, lib_args=None):
options = ['-Dgraal.TruffleCompilationExceptionsArePrinted=true',
Expand All @@ -371,6 +371,37 @@ def getCommonOptions(withAssertion, lib_args=None):

return options

def substituteLibAliases(vmArgs):
librariesOption = '-Dpolyglot.llvm.libraries='
substitutedVmArgs = []
lib_args = None
for vmArg in vmArgs:
if vmArg.startswith(librariesOption):
lib_args = vmArg[len(librariesOption):].split(':')
else:
substitutedVmArgs.append(vmArg)
if lib_args is None:
return vmArgs

lib_aliases = {
'l(.*)rust' : '<rustlib:*>'
}

lib_aliases = {re.compile(k+'$'):v for k, v in lib_aliases.items()}
resolved_lib_args = []
for lib_arg in lib_args:
for lib_alias, lib_alias_value in lib_aliases.items():
match = lib_alias.match(lib_arg)
if match:
lib_arg = lib_alias_value
if match.lastindex is not None:
lib_arg = lib_arg.replace('*', match.group(1))
lib_arg = mx_subst.path_substitutions.substitute(lib_arg)
resolved_lib_args.append(lib_arg)
substitutedVmArgs.append(librariesOption + ':'.join(resolved_lib_args))

return substitutedVmArgs

def getLLVMRootOption():
return "-Dsulongtest.projectRoot=" + _root

Expand Down Expand Up @@ -501,15 +532,22 @@ def findGCCProgram(gccProgram, optional=False):

def findRustLibrary(name):
"""looks up the path to the given Rust library for the active toolchain; tries to install the active toolchain if it is missing; exits if installation fails"""
lib_types = ('so', 'dylib')

rustc = subprocess.Popen(['rustc', '--version'], stdout=subprocess.PIPE)
rustc.communicate()
if rustc.returncode != 0:
exit('the active Rust toolchain could not be installed automatically')
exit('could not install the active Rust toolchain automatically')

rustc = subprocess.Popen(['rustc', '--print', 'sysroot'], stdout=subprocess.PIPE)
sysroot = rustc.communicate()[0].rstrip()
lib_dir_path = os.path.join(sysroot, 'lib', 'lib' + name + '*.so')
return glob.glob(lib_dir_path)[0]
lib_paths = []
for lib_type in lib_types:
lib_paths.extend(glob.glob(os.path.join(sysroot, 'lib', 'lib' + name + '-*.' + lib_type)))
if len(lib_paths) == 0:
exit('could not find Rust library ' + name)
else:
return lib_paths[0]

mx_subst.path_substitutions.register_with_arg('rustlib', findRustLibrary)

Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ EMBED_BC=
BC_FILE=%/O0.bc.o

check_rustc:
@rustc --version || (echo "the active Rust toolchain could not be installed automatically $$?"; exit 1)
@rustc --version || (echo "could not install the active Rust toolchain automatically $$?"; exit 1)

%.bc.o: %.bc
$(QUIETLY) objcopy -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.llvmbc $< $@
Expand Down

0 comments on commit e5feb38

Please sign in to comment.