Skip to content

Better support for --llvm-root. #27937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,13 @@ then
putvar CFG_ENABLE_CLANG
fi

if [ -z "$CFG_DISABLE_LIBCPP" -a -n "$CFG_ENABLE_CLANG" ]
then
CFG_USING_LIBCPP="1"
else
CFG_USING_LIBCPP="0"
fi

# Same with jemalloc. save the setting here.
if [ -n "$CFG_DISABLE_JEMALLOC" ]
then
Expand Down Expand Up @@ -1682,7 +1689,7 @@ do
CXXFLAGS="$CXXFLAGS $LLVM_CXXFLAGS"
LDFLAGS="$LDFLAGS $LLVM_LDFLAGS"

if [ -z "$CFG_DISABLE_LIBCPP" ] && [ -n "$CFG_USING_CLANG" ]; then
if [ "$CFG_USING_LIBCPP" != "0" ]; then
LLVM_OPTS="$LLVM_OPTS --enable-libcpp"
fi

Expand Down Expand Up @@ -1743,6 +1750,7 @@ putvar CFG_AARCH64_LINUX_ANDROID_NDK
putvar CFG_ARM_LINUX_ANDROIDEABI_NDK
putvar CFG_I686_LINUX_ANDROID_NDK
putvar CFG_MANDIR
putvar CFG_USING_LIBCPP
Copy link
Member

Choose a reason for hiding this comment

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

Were these changes necessary for now? It looks like they're not needed elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They should be needed in src/etc/mklldeps.py...

Huh. Somehow, that part of mklldeps didn't make it. I'll get that fixed.


# Avoid spurious warnings from clang by feeding it original source on
# ccache-miss rather than preprocessed input.
Expand Down
14 changes: 11 additions & 3 deletions mk/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ endif


# LLVM linkage:
# Note: Filter with llvm-config so that optional targets which aren't present
# don't cause errors (ie PNaCl's target is only present within PNaCl's LLVM
# fork).
LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
$(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
$$(LLVM_CONFIG_$(1)) "$(CFG_STDCPP_NAME)"
$(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(filter $$(shell \
$$(LLVM_CONFIG_$(1)) --components), \
$(LLVM_OPTIONAL_COMPONENTS)) $(LLVM_REQUIRED_COMPONENTS)" \
"$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" $$(LLVM_CONFIG_$(1)) \
"$(CFG_STDCPP_NAME)" "$$(CFG_USING_LIBCPP)"
endef

$(foreach host,$(CFG_HOST), \
Expand All @@ -94,7 +100,9 @@ $(foreach host,$(CFG_HOST), \

# This can't be done in target.mk because it's included before this file.
define LLVM_LINKAGE_DEPS
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(3))
RUSTFLAGS$(1)_rustc_llvm_T_$(3) += $$(shell echo $$(LLVM_ALL_COMPONENTS_$(3)) | tr '-' '_' |\
sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg have_component_\1/g')
endef

$(foreach source,$(CFG_HOST), \
Expand Down
15 changes: 13 additions & 2 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,18 @@ endif
# LLVM macros
######################################################################

LLVM_COMPONENTS=x86 arm aarch64 mips powerpc ipo bitreader bitwriter linker asmparser mcjit \
LLVM_OPTIONAL_COMPONENTS=x86 arm aarch64 mips powerpc
LLVM_REQUIRED_COMPONENTS=ipo bitreader bitwriter linker asmparser mcjit \
interpreter instrumentation

ifneq ($(CFG_LLVM_ROOT),)
# Ensure we only try to link targets that the installed LLVM actually has:
LLVM_COMPONENTS := $(filter $(shell $(CFG_LLVM_ROOT)/bin/llvm-config$(X_$(CFG_BUILD)) --components),\
$(LLVM_OPTIONAL_COMPONENTS)) $(LLVM_REQUIRED_COMPONENTS)
else
LLVM_COMPONENTS := $(LLVM_OPTIONAL_COMPONENTS) $(LLVM_REQUIRED_COMPONENTS)
endif

# Only build these LLVM tools
LLVM_TOOLS=bugpoint llc llvm-ar llvm-as llvm-dis llvm-mc opt llvm-extract

Expand Down Expand Up @@ -314,6 +323,8 @@ LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))

LLVM_ALL_COMPONENTS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --components)

endef

$(foreach host,$(CFG_HOST), \
Expand Down Expand Up @@ -476,7 +487,7 @@ endif
endif

LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
$$(CURDIR)/$$(HLIB$(1)_H_$(3))
$$(CURDIR)/$$(HLIB$(1)_H_$(3)):$$(CFG_LLVM_INST_DIR_$(3))/lib
LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))

Expand Down
1 change: 1 addition & 0 deletions mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
@$$(call E, rustc: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) \
$$(STDCPP_LIBDIR_RUSTFLAGS_$(2)) \
$$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
-o $$@ $$< --cfg $(4)

endef
Expand Down
4 changes: 3 additions & 1 deletion mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,9 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
"$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
$(1) \
$$(S) \
$(3)
$(3) \
"$$(LLVM_LIBDIR_RUSTFLAGS_$(3))" \
"$$(LLVM_ALL_COMPONENTS_$(3))"
@touch -r $$@.start_time $$@ && rm $$@.start_time
else
# FIXME #11094 - The above rule doesn't work right for multiple targets
Expand Down
2 changes: 2 additions & 0 deletions src/etc/maketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def convert_path_spec(name, value):
putenv('TARGET_RPATH_DIR', os.path.abspath(sys.argv[11]))
putenv('RUST_BUILD_STAGE', sys.argv[12])
putenv('S', os.path.abspath(sys.argv[13]))
putenv('RUSTFLAGS', sys.argv[15])
Copy link
Member

Choose a reason for hiding this comment

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

Was this necessary to pass along? It looks like this isn't used elsewhere from this patch? Also this looks like it skipped a number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was this necessary to pass along? It looks like this isn't used elsewhere from this patch?

Yeah, the execution-engine test needs access to LLVM's dylib. Since trying to disable that test only when LLVM is shared would also require an additional env var, might as well just fix the test.

Also this looks like it skipped a number?

Didn't skip a number; target_triple from earlier in the file takes arguement 14.

Copy link
Member

Choose a reason for hiding this comment

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

Hm does the run-make test need to be updated to read this variable? It looks like there aren't changes to that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, fixed.

putenv('LLVM_COMPONENTS', sys.argv[16])
putenv('PYTHON', sys.executable)
os.putenv('TARGET', target_triple)

Expand Down
22 changes: 18 additions & 4 deletions src/etc/mklldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
enable_static = sys.argv[3]
llvm_config = sys.argv[4]
stdcpp_name = sys.argv[5]
use_libcpp = sys.argv[6]

f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
Expand All @@ -44,11 +45,25 @@ def run(args):
sys.exit(1)
return out

def runErr(args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()

if err:
return False, out
else:
return True, out

f.write("\n")

args = [llvm_config, '--shared-mode']
args.extend(components)
llvm_shared, out = runErr(args)
if llvm_shared:
llvm_shared = 'shared' in out

# LLVM libs
args = [llvm_config, '--libs', '--system-libs']

args.extend(components)
out = run(args)
for lib in out.strip().replace("\n", ' ').split(' '):
Expand All @@ -63,8 +78,7 @@ def run(args):
elif lib[0] == '-':
lib = lib.strip()[1:]
f.write("#[link(name = \"" + lib + "\"")
# LLVM libraries are all static libraries
if 'LLVM' in lib:
if not llvm_shared and 'LLVM' in lib:
f.write(", kind = \"static\"")
f.write(")]\n")

Expand All @@ -83,7 +97,7 @@ def run(args):
# Note that we use `cfg_attr` here because on MSVC the C++ standard library
# is not c++ or stdc++, but rather the linker takes care of linking the
# right standard library.
if 'stdlib=libc++' in out:
if use_libcpp != "0" or 'stdlib=libc++' in out:
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"c++\"))]\n")
else:
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"" + stdcpp_name + "\"))]\n")
Expand Down
32 changes: 32 additions & 0 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#![feature(link_args)]
#![feature(staged_api)]
#![feature(linked_from)]
#![feature(concat_idents)]

extern crate libc;
#[macro_use] #[no_link] extern crate rustc_bitflags;
Expand Down Expand Up @@ -2327,6 +2328,37 @@ pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
.expect("got a non-UTF8 DebugLoc from LLVM")
}

pub fn initialize_available_targets() {
macro_rules! init_target(
($cfg:ident $arch:ident) => { {
#[cfg($cfg)]
fn init() {
unsafe {
let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
f();
let f = concat_idents!(LLVMInitialize, $arch, Target);
f();
let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
f();
let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
f();
let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
f();
}
}
#[cfg(not($cfg))]
fn init() { }
init();
} }
);

init_target!(have_component_powerpc PowerPC);
init_target!(have_component_mips Mips);
init_target!(have_component_aarch64 AArch64);
init_target!(have_component_arm ARM);
init_target!(have_component_x86 X86);
}

// The module containing the native LLVM dependencies, generated by the build system
// Note that this must come after the rustllvm extern declaration so that
// parts of LLVM that rustllvm depends on aren't thrown away by the linker.
Expand Down
34 changes: 1 addition & 33 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,39 +961,7 @@ pub unsafe fn configure_llvm(sess: &Session) {

llvm::LLVMInitializePasses();

// Only initialize the platforms supported by Rust here, because
// using --llvm-root will have multiple platforms that rustllvm
// doesn't actually link to and it's pointless to put target info
// into the registry that Rust cannot generate machine code for.
llvm::LLVMInitializeX86TargetInfo();
llvm::LLVMInitializeX86Target();
llvm::LLVMInitializeX86TargetMC();
llvm::LLVMInitializeX86AsmPrinter();
llvm::LLVMInitializeX86AsmParser();

llvm::LLVMInitializeARMTargetInfo();
llvm::LLVMInitializeARMTarget();
llvm::LLVMInitializeARMTargetMC();
llvm::LLVMInitializeARMAsmPrinter();
llvm::LLVMInitializeARMAsmParser();

llvm::LLVMInitializeAArch64TargetInfo();
llvm::LLVMInitializeAArch64Target();
llvm::LLVMInitializeAArch64TargetMC();
llvm::LLVMInitializeAArch64AsmPrinter();
llvm::LLVMInitializeAArch64AsmParser();

llvm::LLVMInitializeMipsTargetInfo();
llvm::LLVMInitializeMipsTarget();
llvm::LLVMInitializeMipsTargetMC();
llvm::LLVMInitializeMipsAsmPrinter();
llvm::LLVMInitializeMipsAsmParser();

llvm::LLVMInitializePowerPCTargetInfo();
llvm::LLVMInitializePowerPCTarget();
llvm::LLVMInitializePowerPCTargetMC();
llvm::LLVMInitializePowerPCAsmPrinter();
llvm::LLVMInitializePowerPCAsmParser();
llvm::initialize_available_targets();

llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
llvm_args.as_ptr());
Expand Down
7 changes: 7 additions & 0 deletions src/test/run-make/execution-engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# This is a basic test of LLVM ExecutionEngine functionality using compiled
# Rust code built using the `rustc` crate.

ifeq ($(filter executionengine,$(LLVM_COMPONENTS)),executionengine)

ifneq ($(shell uname),FreeBSD)
all:
$(RUSTC) test.rs
Expand All @@ -12,3 +14,8 @@ else
all:

endif

else
all:

endif
21 changes: 17 additions & 4 deletions src/test/run-make/simd-ffi/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
-include ../tools.mk

TARGETS =
ifeq ($(filter arm,$(LLVM_COMPONENTS)),arm)
# construct a fairly exhaustive list of platforms that we
# support. These ones don't follow a pattern
TARGETS=arm-linux-androideabi arm-unknown-linux-gnueabihf arm-unknown-linux-gnueabi
TARGETS += arm-linux-androideabi arm-unknown-linux-gnueabihf arm-unknown-linux-gnueabi
endif

ifeq ($(filter x86,$(LLVM_COMPONENTS)),x86)
X86_ARCHS = i686 x86_64
else
X86_ARCHS =
endif

# these ones do, each OS lists the architectures it supports
LINUX=aarch64 i686 x86_64 mips mipsel
WINDOWS=i686 x86_64
LINUX=$(filter aarch64 mips,$(LLVM_COMPONENTS)) $(X86_ARCHS)
ifeq ($(filter mips,$(LLVM_COMPONENTS)),mips)
LINUX += mipsel
endif

WINDOWS=$(X86_ARCHS)
# fails with: failed to get iphonesimulator SDK path: no such file or directory
#IOS=i386 aarch64 armv7
DARWIN=i686 x86_64
DARWIN=$(X86_ARCHS)

$(foreach arch,$(LINUX),$(eval TARGETS += $(arch)-unknown-linux-gnu))
$(foreach arch,$(WINDOWS),$(eval TARGETS += $(arch)-pc-windows-gnu))
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TARGET_RPATH_ENV = \
$(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(TARGET_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"

BARE_RUSTC := $(HOST_RPATH_ENV) $(RUSTC)
RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS)
#CC := $(CC) -L $(TMPDIR)
HTMLDOCCK := $(PYTHON) $(S)/src/etc/htmldocck.py

Expand Down