Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D
@ 2017-06-16 20:41 Adrian Perez de Castro
  2017-06-16 20:41 ` [Buildroot] [PATCH 1/2] llvm: new package Adrian Perez de Castro
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Adrian Perez de Castro @ 2017-06-16 20:41 UTC (permalink / raw)
  To: buildroot

Hello everybody,

This set of patches adds an LLVM package. For now my main motivation is to
enable support for llvmpipe in Mesa3D'd swrast Gallium driver, which we I am
using in am embedded ARM device which does not provide a GPU, and software
rendering is enough for a small 320x240 LCD framebuffer -- so that is tested
and working.

So far the built LLVM enables only the code generation backend for the CPU of
the target device, which fits the Mesa3D use-case. Having a llvm package in
Buildroot is interesting for many reasons, and I see this as a first step, on
top of which to build on later: target packages for new programming languages
using Clang+LLVM as cross-toolchain, or enabling building programs written in
Rust are just a few examples.

I'll be happy to iterate on these patches with your feedback (keep me CC'd,
please), and have them upstream.

Best regards,

--
 Adri?n ?

Adrian Perez de Castro (2):
  llvm: new package
  mesa3d: Allow optionally using LLVM in drivers

 package/Config.in                                  |   1 +
 ...-Clean-up-exported-values-update-for-shar.patch |  57 ++++++++
 package/llvm/Config.in                             |  48 +++++++
 package/llvm/llvm.hash                             |   2 +
 package/llvm/llvm.mk                               | 145 +++++++++++++++++++++
 package/mesa3d/Config.in                           |  11 ++
 package/mesa3d/mesa3d.mk                           |   9 +-
 7 files changed, 272 insertions(+), 1 deletion(-)
 create mode 100644 package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
 create mode 100644 package/llvm/Config.in
 create mode 100644 package/llvm/llvm.hash
 create mode 100644 package/llvm/llvm.mk

-- 
2.13.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH 1/2] llvm: new package
  2017-06-16 20:41 [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D Adrian Perez de Castro
@ 2017-06-16 20:41 ` Adrian Perez de Castro
  2017-06-17 14:31   ` Thomas Petazzoni
  2017-06-19 19:03   ` [Buildroot] [PATCH v2 " Adrian Perez de Castro
  2017-06-16 20:41 ` [Buildroot] [PATCH 2/2] mesa3d: Allow optionally using LLVM in drivers Adrian Perez de Castro
  2017-07-01 12:52 ` [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D Romain Naour
  2 siblings, 2 replies; 9+ messages in thread
From: Adrian Perez de Castro @ 2017-06-16 20:41 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
---
 package/Config.in                                  |   1 +
 ...-Clean-up-exported-values-update-for-shar.patch |  57 ++++++++
 package/llvm/Config.in                             |  48 +++++++
 package/llvm/llvm.hash                             |   2 +
 package/llvm/llvm.mk                               | 145 +++++++++++++++++++++
 5 files changed, 253 insertions(+)
 create mode 100644 package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
 create mode 100644 package/llvm/Config.in
 create mode 100644 package/llvm/llvm.hash
 create mode 100644 package/llvm/llvm.mk

diff --git a/package/Config.in b/package/Config.in
index c997e2a306..d86bb4f5ac 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -146,6 +146,7 @@ menu "Development tools"
 	source "package/jo/Config.in"
 	source "package/jq/Config.in"
 	source "package/libtool/Config.in"
+	source "package/llvm/Config.in"
 	source "package/make/Config.in"
 	source "package/patch/Config.in"
 	source "package/pkgconf/Config.in"
diff --git a/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
new file mode 100644
index 0000000000..679683a823
--- /dev/null
+++ b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
@@ -0,0 +1,57 @@
+From 628b899be14a6bab4b32dbd53aabd447dcc16cb7 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Sat, 20 Aug 2016 23:47:41 +0200
+Subject: [PATCH] llvm-config: Clean up exported values, update for shared
+ linking
+
+Gentoo-specific fixup for llvm-config, including:
+- wiping build-specific CFLAGS, CXXFLAGS,
+- making --src-root return invalid path (/dev/null).
+
+Thanks to Steven Newbury for the initial patch.
+
+Bug: https://bugs.gentoo.org/565358
+Bug: https://bugs.gentoo.org/501684
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/llvm/files/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
+
+
+diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
+index 744fa4e44d1..593788aaef3 100644
+--- a/tools/llvm-config/CMakeLists.txt
++++ b/tools/llvm-config/CMakeLists.txt
+@@ -32,8 +32,12 @@ get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
+ set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
+ set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
+ set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+-set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+-set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
++# Just use CMAKE_CPP_FLAGS for CFLAGS and CXXFLAGS, otherwise compiler
++# specific flags will be set when we don't know what compiler will be used
++# with external project utilising llvm-config.  C++ Standard is required.
++# TODO: figure out if we can remove -std=c++11 and move it to revdeps.
++set(LLVM_CFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
++set(LLVM_CXXFLAGS "${CMAKE_CPP_FLAGS} -std=c++11 ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+ set(LLVM_BUILD_SYSTEM cmake)
+ set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
+ set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}")
+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
+index d780094861c..c61c72ff48c 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -549,7 +550,11 @@ int main(int argc, char **argv) {
+       } else if (Arg == "--obj-root") {
+         OS << ActivePrefix << '\n';
+       } else if (Arg == "--src-root") {
+-        OS << LLVM_SRC_ROOT << '\n';
++        if (IsInDevelopmentTree) {
++          OS << LLVM_SRC_ROOT << '\n';
++        } else {
++          OS << "/dev/null\n";
++        }
+       } else if (Arg == "--ignore-libllvm") {
+         LinkDyLib = false;
+         LinkMode = BuiltSharedLibs ? LinkModeShared : LinkModeAuto;
+-- 
+2.11.0
+
diff --git a/package/llvm/Config.in b/package/llvm/Config.in
new file mode 100644
index 0000000000..92ad52d7b2
--- /dev/null
+++ b/package/llvm/Config.in
@@ -0,0 +1,48 @@
+config BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT
+	bool
+	default y
+	depends on BR2_arm || BR2_armeb || BR2_aarch64 || \
+		BR2_i386 || BR2_x86_64 || \
+		BR2_mips || BR2_mipsel || \
+		BR2_mips64 || BR2_mips64el || \
+		BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le || \
+		BR2_sparc
+
+menuconfig BR2_PACKAGE_LLVM
+	bool "llvm"
+	depends on BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT && \
+		BR2_INSTALL_LIBSTDCPP && BR2_TOOLCHAIN_BUILDROOT_WCHAR
+	select BR2_PACKAGE_LIBXML2
+	select BR2_PACKAGE_ZLIB
+	help
+		The LLVM Project is a collection of modular and reusable compiler
+		and toolchain technologies.
+
+		http://llvm.org
+
+comment "llvm requires C++ and wide-character support"
+	depends on !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_BUILDROOT_WCHAR
+
+if BR2_PACKAGE_LLVM
+
+config BR2_PACKAGE_LLVM_ENABLE_FFI
+	bool "Support libffi"
+	default n
+	select BR2_PACKAGE_LIBFFI
+	help
+		Use libffi in the LLVM Interpreter in order to enable calling
+		external functions.
+
+config BR2_PACKAGE_LLVM_ENABLE_RTTI
+	bool "C++: Support RTTI"
+	default n
+	help
+		Enable support for C++ Run-Time Type Information (RTTI)
+
+config BR2_PACKAGE_LLVM_ENABLE_EH
+	bool "C++: Support exception handling"
+	default n
+	help
+		Enable support for C++ exception handling (try/catch)
+
+endif
diff --git a/package/llvm/llvm.hash b/package/llvm/llvm.hash
new file mode 100644
index 0000000000..b11cd14bf4
--- /dev/null
+++ b/package/llvm/llvm.hash
@@ -0,0 +1,2 @@
+# Computed locally after checking the GPG signature:
+sha256 8d10511df96e73b8ff9e7abbfb4d4d432edbdbe965f1f4f07afaf370b8a533be  llvm-4.0.0.src.tar.xz
diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
new file mode 100644
index 0000000000..0e9bd5fc41
--- /dev/null
+++ b/package/llvm/llvm.mk
@@ -0,0 +1,145 @@
+################################################################################
+#
+# llvm
+#
+################################################################################
+
+LLVM_VERSION = 4.0.0
+LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
+LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
+LLVM_LICENSE = University of Illinois/NCSA Open Source License
+LLVM_LICENSE_FILES = LICENSE.TXT
+LLVM_INSTALL_STAGING = YES
+LLVM_INSTALL_TARGET = YES
+LLVM_DEPENDENCIES = libxml2 zlib host-python host-cmake
+
+# Determine the name of the LLVM target to enable depending on
+# the Buildroot target settings.
+#
+ifeq ($(BR2_i386),y)
+  LLVM_TARGET_ARCH := X86
+else ifeq ($(BR2_x86_64),y)
+  LLVM_TARGET_ARCH := X86
+else ifeq ($(BR2_arm),y)
+  LLVM_TARGET_ARCH := ARM
+else ifeq ($(BR2_armeb),y)
+  LLVM_TARGET_ARCH := ARM
+else ifeq ($(BR2_aarch64),y)
+  LLVM_TARGET_ARCH := AArch64
+else ifeq ($(BR2_mips),y)
+  LLVM_TARGET_ARCH := Mips
+else ifeq ($(BR2_mipsel),y)
+  LLVM_TARGET_ARCH := Mips
+else ifeq ($(BR2_mips64),y)
+  LLVM_TARGET_ARCH := Mips
+else ifeq ($(BR2_mips64el),y)
+  LLVM_TARGET_ARCH := Mips
+else ifeq ($(BR2_powerpc),y)
+  LLVM_TARGET_ARCH := PowerPC
+else ifeq ($(BR2_powerpc64),y)
+  LLVM_TARGET_ARCH := PowerPC
+else ifeq ($(BR2_powerpc64le),y)
+  LLVM_TARGET_ARCH := PowerPC
+else ifeq ($(BR2_sparc),y)
+  LLVM_TARGET_ARCH := Sparc
+else
+  $(error Target architecture not supported by LLVM)
+endif
+
+
+# List of build options at:
+#    http://llvm.org/docs/CMake.html
+#
+LLVM_CONF_OPTS := \
+  -DLLVM_DEFAULT_TARGET_TRIPLE=$(GNU_TARGET_NAME) \
+  -DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME) \
+  -DLLVM_TARGETS_TO_BUILD=$(LLVM_TARGET_ARCH) \
+  -DLLVM_TARGET_ARCH=$(LLVM_TARGET_ARCH) \
+  -DLLVM_OPTIMIZED_TABLEGEN=YES \
+  -DLLVM_ENABLE_ZLIB=YES \
+  -DLLVM_INCLUDE_TOOLS=YES \
+  -DLLVM_INCLUDE_UTILS=NO \
+  -DLLVM_INCLUDE_EXAMPLES=NO \
+  -DLLVM_INCLUDE_TESTS=NO \
+  -DLLVM_BUILD_TESTS=NO \
+  -DLLVM_BUILD_RUNTIME=NO \
+  -DLLVM_ENABLE_PROJECTS=''
+
+
+# The Go bindings have no CMake rules@the moment, but better remove the
+# check preventively. Building the Go and OCaml bindings is yet unsupported.
+#
+LLVM_CONF_OPTS += \
+  -DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND \
+  -DOCAMLFIND=OCAMLFIND-NOTFOUND
+
+
+# Building per-component shared libraries is NOT recommended by upstream.
+# The all-in-one libLLVM-<version>.so is enabled with a different setting.
+LLVM_CONF_OPTS += \
+  -DBUILD_SHARED_LIBS=NO \
+  -DLLVM_BUILD_LLVM_DYLIB=$(if $(BR2_STATIC_LIBS),NO,YES)
+
+
+ifeq ($(BR2_PACKAGE_LLVM_ENABLE_FFI),y)
+  LLVM_DEPENDENCIES += libffi
+  LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=YES
+else
+  LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=NO
+endif
+
+ifeq ($(BR2_PACKAGE_LLVM_ENABLE_RTTI),y)
+  LLVM_CONF_OPTS += -DLLVM_ENABLE_RTTI=YES
+else
+  LLVM_CONF_OPTS += -DLLVM_ENABLE_RTTI=NO
+endif
+
+ifeq ($(BR2_PACKAGE_LLVM_ENABLE_EH),y)
+  LLVM_CONF_OPTS += -DLLVM_ENABLE_EH=YES
+else
+  LLVM_CONF_OPTS += -DLLVM_ENABLE_EH=NO
+endif
+
+# LLVM expects to always be built in a separate directory.
+LLVM_SUPPORTS_IN_SOURCE_BUILD = NO
+
+$(eval $(cmake-package))
+
+# XXX: LLVM does include some support for building native tools. This is used
+#      to build e.g. llvm-config, and a host-native llvm-tblgen if needed.
+#      Unfortunately, Buildroot is overzealous about passing the parameters
+#      needed for cross-building, and the CMake configuration for the native
+#      tools ends up using the cross-toolchain. Once "cmake-package" has
+#      defined LLVM_*_CMDS, this adds:
+#
+#        - A call to CMake which resets CMAKE_{C,CXX,ASM}_COMPILER with the
+#          paths to the host-native ones. Note that using the *_NOCCACHE
+#          variables is needed, otherwise CMake will choke.
+#
+#        - The file "BuildVariables.inc" is copied over from the cross-build
+#          directory to the native one. This way a new "llvm-config" which
+#          can run on the build host returns information about the target
+#          build which gets installed in the sysroot. This is done as an
+#          appended build command. Note that Make has to be re-invoked to
+#          rebuild after copying the file over.
+#
+#        - Last but not least, "llvm-config" is copied into the sysroot with
+#          the target triple prefix, because packages using sane build systems
+#          will first try that.
+#
+LLVM_CONFIGURE_CMDS += \
+  && cd $(LLVM_BUILDDIR)/NATIVE \
+  && PATH=$(BR_PATH) $(LLVM_CONF_ENV) $(BR2_CMAKE) $(LLVM_SRCDIR) \
+     -DCMAKE_C_COMPILER='$(HOSTCC_NOCCACHE)' \
+     -DCMAKE_ASM_COMPILER='$(HOSTCC_NOCCACHE)' \
+     -DCMAKE_CXX_COMPILER='$(HOSTCXX_NOCCACHE)'
+
+LLVM_BUILD_CMDS += \
+  && cp $(LLVM_BUILDDIR)/tools/llvm-config/BuildVariables.inc \
+     $(LLVM_BUILDDIR)/NATIVE/tools/llvm-config/BuildVariables.inc \
+  && $(HOST_MAKE_ENV) $(LLVM_MAKE_ENV) $(LLVM_MAKE) $(LLVM_MAKE_OPTS) \
+     -C $(LLVM_BUILDDIR)/NATIVE llvm-config
+
+LLVM_INSTALL_STAGING_CMDS += \
+  && install -Dm755 $(LLVM_BUILDDIR)/NATIVE/bin/llvm-config \
+     $(STAGING_DIR)/usr/bin/$(GNU_TARGET_NAME)-llvm-config
-- 
2.13.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH 2/2] mesa3d: Allow optionally using LLVM in drivers
  2017-06-16 20:41 [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D Adrian Perez de Castro
  2017-06-16 20:41 ` [Buildroot] [PATCH 1/2] llvm: new package Adrian Perez de Castro
@ 2017-06-16 20:41 ` Adrian Perez de Castro
  2017-07-01 12:52 ` [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D Romain Naour
  2 siblings, 0 replies; 9+ messages in thread
From: Adrian Perez de Castro @ 2017-06-16 20:41 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
---
 package/mesa3d/Config.in | 11 +++++++++++
 package/mesa3d/mesa3d.mk |  9 ++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/package/mesa3d/Config.in b/package/mesa3d/Config.in
index 36a0304e27..03a0668a01 100644
--- a/package/mesa3d/Config.in
+++ b/package/mesa3d/Config.in
@@ -44,6 +44,17 @@ config BR2_PACKAGE_MESA3D_DRIVER
 config BR2_PACKAGE_MESA3D_NEEDS_XA
 	bool
 
+config BR2_PACKAGE_MESA3D_USE_LLVM
+	bool "Enable LLVM usage"
+	default y
+	depends on BR2_PACKAGE_LLVM
+	select BR2_PACKAGE_LLVM_ENABLE_RTTI
+	help
+		Build optimized driver code which makes use of LLVM (e.g. llvmpipe).
+
+comment "optional llvm support depends on llvm"
+	depends on !BR2_PACKAGE_LLVM
+
 comment "Gallium drivers"
 
 config BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_ETNAVIV
diff --git a/package/mesa3d/mesa3d.mk b/package/mesa3d/mesa3d.mk
index 2884063526..2e402e53aa 100644
--- a/package/mesa3d/mesa3d.mk
+++ b/package/mesa3d/mesa3d.mk
@@ -57,6 +57,13 @@ MESA3D_CONF_OPTS += \
 	--disable-xa
 endif
 
+ifeq ($(BR2_PACKAGE_MESA3D_USE_LLVM),y)
+MESA3D_DEPENDENCIES += llvm
+MESA3D_CONF_OPTS += --enable-llvm
+else
+MESA3D_CONF_OPTS += --disable-llvm
+endif
+
 # Drivers
 
 #Gallium Drivers
@@ -211,6 +218,6 @@ MESA3D_CONF_OPTS += --disable-lmsensors
 endif
 
 # Avoid automatic search of llvm-config
-MESA3D_CONF_OPTS += --with-llvm-prefix=$(STAGING_DIR)/usr/bin
+MESA3D_CONF_OPTS += --with-llvm-prefix=$(STAGING_DIR)/usr
 
 $(eval $(autotools-package))
-- 
2.13.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH 1/2] llvm: new package
  2017-06-16 20:41 ` [Buildroot] [PATCH 1/2] llvm: new package Adrian Perez de Castro
@ 2017-06-17 14:31   ` Thomas Petazzoni
  2017-06-19 18:41     ` Adrian Perez de Castro
  2017-06-19 19:03   ` [Buildroot] [PATCH v2 " Adrian Perez de Castro
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Petazzoni @ 2017-06-17 14:31 UTC (permalink / raw)
  To: buildroot

Hello,

On Fri, 16 Jun 2017 23:41:42 +0300, Adrian Perez de Castro wrote:
> Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>

Thanks a lot for this patch. It's definitely good to see someone
working on LLVM support.

> diff --git a/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> new file mode 100644
> index 0000000000..679683a823
> --- /dev/null
> +++ b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> @@ -0,0 +1,57 @@
> +From 628b899be14a6bab4b32dbd53aabd447dcc16cb7 Mon Sep 17 00:00:00 2001
> +From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
> +Date: Sat, 20 Aug 2016 23:47:41 +0200
> +Subject: [PATCH] llvm-config: Clean up exported values, update for shared
> + linking
> +
> +Gentoo-specific fixup for llvm-config, including:
> +- wiping build-specific CFLAGS, CXXFLAGS,
> +- making --src-root return invalid path (/dev/null).

It would be nice to explain why this patch is needed.

> +
> +Thanks to Steven Newbury for the initial patch.
> +
> +Bug: https://bugs.gentoo.org/565358
> +Bug: https://bugs.gentoo.org/501684
> +
> +Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/llvm/files/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> +
> +

Please add your Signed-off-by here.

> diff --git a/package/llvm/Config.in b/package/llvm/Config.in
> new file mode 100644
> index 0000000000..92ad52d7b2
> --- /dev/null
> +++ b/package/llvm/Config.in
> @@ -0,0 +1,48 @@
> +config BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT

Why are you calling this BR2_PACKAGE_HOST_LLVM ? Isn't this instead
related to which target architectures LLVM support?

Also, it should be "SUPPORTS" with a final "S".

> +	bool
> +	default y
> +	depends on BR2_arm || BR2_armeb || BR2_aarch64 || \
> +		BR2_i386 || BR2_x86_64 || \
> +		BR2_mips || BR2_mipsel || \
> +		BR2_mips64 || BR2_mips64el || \
> +		BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le || \
> +		BR2_sparc

It would IMO be a bit more readable as follows:

config BR2_PACKAGE_LLVM_ARCH_SUPPORTS
	bool
	default y if BR2_arm || BR2_armeb
	default y if BR2_aarch64
	default y if ...

> +menuconfig BR2_PACKAGE_LLVM

A "menuconfig" is probably not needed, keep this just a plain "config".

> +	bool "llvm"
> +	depends on BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT && \
> +		BR2_INSTALL_LIBSTDCPP && BR2_TOOLCHAIN_BUILDROOT_WCHAR

Please split each depends on on its own line.

> +	select BR2_PACKAGE_LIBXML2
> +	select BR2_PACKAGE_ZLIB
> +	help
> +		The LLVM Project is a collection of modular and reusable compiler
> +		and toolchain technologies.
> +
> +		http://llvm.org

Indentation of the help text is one tab + two spaces. Please run your
package through ./support/scripts/check-package to detect such coding
style related issues.

> +comment "llvm requires C++ and wide-character support"

Should be:

comment "llvm needs a toolchain w/ C++, wchar"
	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS

Indeed, the wording of such comments is standardized in Buildroot, and
the depends on allows to not show the comment if llvm is anyway not
available for the selected architecture.

> +	depends on !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_BUILDROOT_WCHAR
> +
> +if BR2_PACKAGE_LLVM
> +
> +config BR2_PACKAGE_LLVM_ENABLE_FFI
> +	bool "Support libffi"
> +	default n

"default n" is never needed, as it's the default, please remove
everywhere.

> +	select BR2_PACKAGE_LIBFFI
> +	help
> +		Use libffi in the LLVM Interpreter in order to enable calling
> +		external functions.

One tab + two spaces for the indentation (please fix globally).

> +config BR2_PACKAGE_LLVM_ENABLE_RTTI
> +	bool "C++: Support RTTI"
> +	default n
> +	help
> +		Enable support for C++ Run-Time Type Information (RTTI)
> +
> +config BR2_PACKAGE_LLVM_ENABLE_EH
> +	bool "C++: Support exception handling"
> +	default n
> +	help
> +		Enable support for C++ exception handling (try/catch)

Is it really important to make those features configurable, as opposed
to having them unconditionally enabled? What is the size impact?

> diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
> new file mode 100644
> index 0000000000..0e9bd5fc41
> --- /dev/null
> +++ b/package/llvm/llvm.mk
> @@ -0,0 +1,145 @@
> +################################################################################
> +#
> +# llvm
> +#
> +################################################################################
> +
> +LLVM_VERSION = 4.0.0
> +LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
> +LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
> +LLVM_LICENSE = University of Illinois/NCSA Open Source License

We want SPDX license codes for the <pkg>_LICENSE variable. According to
https://spdx.org/licenses/, the corresponding code is just "NCSA".

> +LLVM_LICENSE_FILES = LICENSE.TXT
> +LLVM_INSTALL_STAGING = YES
> +LLVM_INSTALL_TARGET = YES

This last line is not needed, it's the default.

> +LLVM_DEPENDENCIES = libxml2 zlib host-python host-cmake

Remove host-cmake, it's automatically added to the dependencies since
you're using cmake-package.

> +# Determine the name of the LLVM target to enable depending on
> +# the Buildroot target settings.
> +#
> +ifeq ($(BR2_i386),y)
> +  LLVM_TARGET_ARCH := X86
> +else ifeq ($(BR2_x86_64),y)
> +  LLVM_TARGET_ARCH := X86
> +else ifeq ($(BR2_arm),y)
> +  LLVM_TARGET_ARCH := ARM
> +else ifeq ($(BR2_armeb),y)
> +  LLVM_TARGET_ARCH := ARM
> +else ifeq ($(BR2_aarch64),y)
> +  LLVM_TARGET_ARCH := AArch64
> +else ifeq ($(BR2_mips),y)
> +  LLVM_TARGET_ARCH := Mips
> +else ifeq ($(BR2_mipsel),y)
> +  LLVM_TARGET_ARCH := Mips
> +else ifeq ($(BR2_mips64),y)
> +  LLVM_TARGET_ARCH := Mips
> +else ifeq ($(BR2_mips64el),y)
> +  LLVM_TARGET_ARCH := Mips
> +else ifeq ($(BR2_powerpc),y)
> +  LLVM_TARGET_ARCH := PowerPC
> +else ifeq ($(BR2_powerpc64),y)
> +  LLVM_TARGET_ARCH := PowerPC
> +else ifeq ($(BR2_powerpc64le),y)
> +  LLVM_TARGET_ARCH := PowerPC
> +else ifeq ($(BR2_sparc),y)
> +  LLVM_TARGET_ARCH := Sparc
> +else
> +  $(error Target architecture not supported by LLVM)
> +endif

Don't use := for assignments, but =. Also, this could probably be more
nicely handled in the Config.in file. Something like:

config BR2_PACKAGE_LLVM_ARCH
	string
	default "X86" if BR2_i386 || BR2_x86_64
	default "ARM" if BR2_arm || BR2_armeb
	...

and in llvm.mk:

LLVM_ARCH = $(call qstrip,$(BR2_PACKAGE_LLVM_ARCH))

> +# List of build options at:
> +#    http://llvm.org/docs/CMake.html
> +#
> +LLVM_CONF_OPTS := \

Use = for assignments, not :=.

> +  -DLLVM_DEFAULT_TARGET_TRIPLE=$(GNU_TARGET_NAME) \
> +  -DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME) \
> +  -DLLVM_TARGETS_TO_BUILD=$(LLVM_TARGET_ARCH) \
> +  -DLLVM_TARGET_ARCH=$(LLVM_TARGET_ARCH) \
> +  -DLLVM_OPTIMIZED_TABLEGEN=YES \
> +  -DLLVM_ENABLE_ZLIB=YES \

zlib support is optional ?

> +  -DLLVM_INCLUDE_TOOLS=YES \
> +  -DLLVM_INCLUDE_UTILS=NO \
> +  -DLLVM_INCLUDE_EXAMPLES=NO \
> +  -DLLVM_INCLUDE_TESTS=NO \
> +  -DLLVM_BUILD_TESTS=NO \
> +  -DLLVM_BUILD_RUNTIME=NO \
> +  -DLLVM_ENABLE_PROJECTS=''
> +
> +

Please use only one blank line.

> +# The Go bindings have no CMake rules at the moment, but better remove the
> +# check preventively. Building the Go and OCaml bindings is yet unsupported.
> +#
> +LLVM_CONF_OPTS += \
> +  -DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND \
> +  -DOCAMLFIND=OCAMLFIND-NOTFOUND
> +
> +

Only one blank line.

> +# Building per-component shared libraries is NOT recommended by upstream.
> +# The all-in-one libLLVM-<version>.so is enabled with a different setting.
> +LLVM_CONF_OPTS += \
> +  -DBUILD_SHARED_LIBS=NO \
> +  -DLLVM_BUILD_LLVM_DYLIB=$(if $(BR2_STATIC_LIBS),NO,YES)
> +
> +

Only one blank line.

> +ifeq ($(BR2_PACKAGE_LLVM_ENABLE_FFI),y)
> +  LLVM_DEPENDENCIES += libffi
> +  LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=YES
> +else
> +  LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=NO

No indentation inside the ifeq...endif blocks (please fix globally).

> +# XXX: LLVM does include some support for building native tools. This is used
> +#      to build e.g. llvm-config, and a host-native llvm-tblgen if needed.
> +#      Unfortunately, Buildroot is overzealous about passing the parameters
> +#      needed for cross-building, and the CMake configuration for the native

Can you explain in what respect Buildroot is "overzealous"? Is there
anything we can/should fix?

> +#      tools ends up using the cross-toolchain. Once "cmake-package" has
> +#      defined LLVM_*_CMDS, this adds:
> +#
> +#        - A call to CMake which resets CMAKE_{C,CXX,ASM}_COMPILER with the
> +#          paths to the host-native ones. Note that using the *_NOCCACHE
> +#          variables is needed, otherwise CMake will choke.
> +#
> +#        - The file "BuildVariables.inc" is copied over from the cross-build
> +#          directory to the native one. This way a new "llvm-config" which
> +#          can run on the build host returns information about the target
> +#          build which gets installed in the sysroot. This is done as an
> +#          appended build command. Note that Make has to be re-invoked to
> +#          rebuild after copying the file over.
> +#
> +#        - Last but not least, "llvm-config" is copied into the sysroot with
> +#          the target triple prefix, because packages using sane build systems
> +#          will first try that.

Buildroot doesn't rename <foo>-config scripts/programs to be prefixed
with the target triple prefix, so it would be better to keep it named
llvm-config, like all other <foo>-config in $(STAGING_DIR)/usr/bin.

> +LLVM_CONFIGURE_CMDS += \

Using those += is really not clean. Instead, you should use
POST_CONFIGURE_HOOKS, POST_BUILD_HOOKS and POST_INSTALL_STAGING_HOOKS.

However, I'd really like to understand how Buildroot is "overzealous"
and see if things can work out of the box without doing those hacks.

Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH 1/2] llvm: new package
  2017-06-17 14:31   ` Thomas Petazzoni
@ 2017-06-19 18:41     ` Adrian Perez de Castro
  0 siblings, 0 replies; 9+ messages in thread
From: Adrian Perez de Castro @ 2017-06-19 18:41 UTC (permalink / raw)
  To: buildroot

Hello,

Thanks for taking some time to review the patches :-)
I'll comment inline below.

On Sat, 17 Jun 2017 16:31:54 +0200, Thomas Petazzoni <thomas.petazzoni@free-electrons.com> wrote:

> On Fri, 16 Jun 2017 23:41:42 +0300, Adrian Perez de Castro wrote:
> > Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
> 
> Thanks a lot for this patch. It's definitely good to see someone
> working on LLVM support.
>
> > diff --git a/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> > new file mode 100644
> > index 0000000000..679683a823
> > --- /dev/null
> > +++ b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> > @@ -0,0 +1,57 @@
> > +From 628b899be14a6bab4b32dbd53aabd447dcc16cb7 Mon Sep 17 00:00:00 2001
> > +From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
> > +Date: Sat, 20 Aug 2016 23:47:41 +0200
> > +Subject: [PATCH] llvm-config: Clean up exported values, update for shared
> > + linking
> > +
> > +Gentoo-specific fixup for llvm-config, including:
> > +- wiping build-specific CFLAGS, CXXFLAGS,
> > +- making --src-root return invalid path (/dev/null).
> 
> It would be nice to explain why this patch is needed.

This patch does a couple of things which I are interesting for myself (to
build Mesa3D with llvmpipe in swrast), and which I image may be desired for
Buildroot as well:

 * Removes CFLAGS/CXXFLAGS from the output of ?llvm-config?. This way packages
   which use LLVM will use the Buildroot compiler flags (either global ones or
   defined locally-defined in a package). For example, this avoids cases like
   the following:

	 - A build being done with ?-Os? chosen in .config
	 - A package known to break with ?-Os? replaces it with ?-O2?.
	 - LLVM built with ?-Os? has the output from ?llvm-config? including ?-Os?
	   and adding that to the package build flags end up being ?-O2 ? -Os?,
	   resulting in a broken package.

 * It makes ?llvm-config --src-root? return ?/dev/null?. This is to prevent
   other packages to build tools which should be built as part of the LLVM
   build process (and that therefore need the path to the LLVM sources).

Depending on which approach Buildroot follows regarding additional tools
(lldb, clang, lld, etc), it may be possible to drop the second part of the
patch. What would we prefer, using separate per-component packages, or
sub-options for the LLVM package? Personally I would favor the latter,
as it seems to be less error prone, but I have no strong preference here.

> > +Thanks to Steven Newbury for the initial patch.
> > +
> > +Bug: https://bugs.gentoo.org/565358
> > +Bug: https://bugs.gentoo.org/501684
> > +
> > +Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/llvm/files/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> > +
> > +
> 
> Please add your Signed-off-by here.

Oh, I forgot this, thanks.

> > diff --git a/package/llvm/Config.in b/package/llvm/Config.in
> > new file mode 100644
> > index 0000000000..92ad52d7b2
> > --- /dev/null
> > +++ b/package/llvm/Config.in
> > @@ -0,0 +1,48 @@
> > +config BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT
> 
> Why are you calling this BR2_PACKAGE_HOST_LLVM ? Isn't this instead
> related to which target architectures LLVM support?
> 
> Also, it should be "SUPPORTS" with a final "S".

Indeed, this a mistake. I'll rename it to ?BR2_PACKAGE_LLVM_ARCH_SUPPORTS?.

> > +	bool
> > +	default y
> > +	depends on BR2_arm || BR2_armeb || BR2_aarch64 || \
> > +		BR2_i386 || BR2_x86_64 || \
> > +		BR2_mips || BR2_mipsel || \
> > +		BR2_mips64 || BR2_mips64el || \
> > +		BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le || \
> > +		BR2_sparc
> 
> It would IMO be a bit more readable as follows:
> 
> config BR2_PACKAGE_LLVM_ARCH_SUPPORTS
> 	bool
> 	default y if BR2_arm || BR2_armeb
> 	default y if BR2_aarch64
> 	default y if ...

Cool, I didn't know that multiple ?default y? lines are supported :-)

> > +menuconfig BR2_PACKAGE_LLVM
> 
> A "menuconfig" is probably not needed, keep this just a plain "config".

Okay.

> > +	bool "llvm"
> > +	depends on BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT && \
> > +		BR2_INSTALL_LIBSTDCPP && BR2_TOOLCHAIN_BUILDROOT_WCHAR
> 
> Please split each depends on on its own line.

Will do.

> > +	select BR2_PACKAGE_LIBXML2
> > +	select BR2_PACKAGE_ZLIB
> > +	help
> > +		The LLVM Project is a collection of modular and reusable compiler
> > +		and toolchain technologies.
> > +
> > +		http://llvm.org
> 
> Indentation of the help text is one tab + two spaces. Please run your
> package through ./support/scripts/check-package to detect such coding
> style related issues.

Handy tool, and works nicely with Vim, I'm now using this to get the list of
reported issues in the quickfix window:

   :set makeprg=./support/scripts/check-package\ %
   :make

:-)

> > +comment "llvm requires C++ and wide-character support"
> 
> Should be:
> 
> comment "llvm needs a toolchain w/ C++, wchar"
> 	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
>
> Indeed, the wording of such comments is standardized in Buildroot, and
> the depends on allows to not show the comment if llvm is anyway not
> available for the selected architecture.

Wouldn't the existing dependencies be needed as well? I.e:

    comment "llvm needs a toolchain w/ C++, wchar"
    	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
    	depends on !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_BUILDROOT_WCHAR

> > +config BR2_PACKAGE_LLVM_ENABLE_RTTI
> > +	bool "C++: Support RTTI"
> > +	default n
> > +	help
> > +		Enable support for C++ Run-Time Type Information (RTTI)
> > +
> > +config BR2_PACKAGE_LLVM_ENABLE_EH
> > +	bool "C++: Support exception handling"
> > +	default n
> > +	help
> > +		Enable support for C++ exception handling (try/catch)
> 
> Is it really important to make those features configurable, as opposed
> to having them unconditionally enabled? What is the size impact?

Both add a measurable amount of data to the generated object code. The
size binary size reduction when disabling RTTI for building LLVM are in the
ballpark of 5 to 10% according to Chris Lattner, one of the developers:

  https://stackoverflow.com/a/5138926

The same goes for exception handling. I did one build with both of them
disabled, and another with both options enabled, with the following results
for the combined shared library (?strip -x --strip-unneeded libLLVM-4.0.so?):

  text        data    bss     dec       hex
  15664977    385820  113648  16164445  f6a65d libLLVM-4.0.so  [with EH+RTTI]
  14164237    361440  113648  14639325  df60dd libLLVM-4.0.so  [without EH/RTTI]

That's a total saving of 1.45 MiB, which looks pretty good to me.

> > diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
> > new file mode 100644
> > index 0000000000..0e9bd5fc41
> > --- /dev/null
> > +++ b/package/llvm/llvm.mk
> > @@ -0,0 +1,145 @@
> > +################################################################################
> > +#
> > +# llvm
> > +#
> > +################################################################################
> > +
> > +LLVM_VERSION = 4.0.0
> > +LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
> > +LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
> > +LLVM_LICENSE = University of Illinois/NCSA Open Source License
> 
> We want SPDX license codes for the <pkg>_LICENSE variable. According to
> https://spdx.org/licenses/, the corresponding code is just "NCSA".
> 
> > +LLVM_LICENSE_FILES = LICENSE.TXT
> > +LLVM_INSTALL_STAGING = YES
> > +LLVM_INSTALL_TARGET = YES
> 
> This last line is not needed, it's the default.
> 
> > +LLVM_DEPENDENCIES = libxml2 zlib host-python host-cmake
> 
> Remove host-cmake, it's automatically added to the dependencies since
> you're using cmake-package.
> 
> > +# Determine the name of the LLVM target to enable depending on
> > +# the Buildroot target settings.
> > +#
> > +ifeq ($(BR2_i386),y)
> > +  LLVM_TARGET_ARCH := X86
> > +else ifeq ($(BR2_x86_64),y)
> > +  LLVM_TARGET_ARCH := X86
> > +else ifeq ($(BR2_arm),y)
> > +  LLVM_TARGET_ARCH := ARM
> > +else ifeq ($(BR2_armeb),y)
> > +  LLVM_TARGET_ARCH := ARM
> > +else ifeq ($(BR2_aarch64),y)
> > +  LLVM_TARGET_ARCH := AArch64
> > +else ifeq ($(BR2_mips),y)
> > +  LLVM_TARGET_ARCH := Mips
> > +else ifeq ($(BR2_mipsel),y)
> > +  LLVM_TARGET_ARCH := Mips
> > +else ifeq ($(BR2_mips64),y)
> > +  LLVM_TARGET_ARCH := Mips
> > +else ifeq ($(BR2_mips64el),y)
> > +  LLVM_TARGET_ARCH := Mips
> > +else ifeq ($(BR2_powerpc),y)
> > +  LLVM_TARGET_ARCH := PowerPC
> > +else ifeq ($(BR2_powerpc64),y)
> > +  LLVM_TARGET_ARCH := PowerPC
> > +else ifeq ($(BR2_powerpc64le),y)
> > +  LLVM_TARGET_ARCH := PowerPC
> > +else ifeq ($(BR2_sparc),y)
> > +  LLVM_TARGET_ARCH := Sparc
> > +else
> > +  $(error Target architecture not supported by LLVM)
> > +endif
> 
> Don't use := for assignments, but =. Also, this could probably be more
> nicely handled in the Config.in file. Something like:
>
> config BR2_PACKAGE_LLVM_ARCH
> 	string
> 	default "X86" if BR2_i386 || BR2_x86_64
> 	default "ARM" if BR2_arm || BR2_armeb
> 	...
>
> and in llvm.mk:
>
> LLVM_ARCH = $(call qstrip,$(BR2_PACKAGE_LLVM_ARCH))

Now that's a neat trick using kconfig, thanks!

> > +# List of build options at:
> > +#    http://llvm.org/docs/CMake.html
> > +#
> > +LLVM_CONF_OPTS := \
>
> Use = for assignments, not :=.

Out of curiosity, and as a side question: What is the reason for not using
?:=? for assignments?

It looks to me as if it would be better to use the immediate-expansion
assignment (?:=?) at least when the right side of the assignment contains
potentially expensive expansions. For example:

  LLVM_ARCH := $(call qstrip,$(BR2_PACKAGE_LLVM_ARCH))
  LLVM_CONF_OPTS += \
	-DLLVM_TARGETS_TO_BUILD=$(LLVM_ARCH) \
  	-DLLVM_TARGET_ARCH=$(LLVM_ARCH) ...

...will call ?qstrip? only once, while using a lazy-expansion assignment (?=?)
causes the ?qstrip? macro to be called twice every time that $(LLVM_CONF_OPTS)
gets expanded. Using ?:=? expands the macro just once.

(I am sure there is a good reason for sticking with ?=?, and I am curious
about it, that's all)

> > +  -DLLVM_DEFAULT_TARGET_TRIPLE=$(GNU_TARGET_NAME) \
> > +  -DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME) \
> > +  -DLLVM_TARGETS_TO_BUILD=$(LLVM_TARGET_ARCH) \
> > +  -DLLVM_TARGET_ARCH=$(LLVM_TARGET_ARCH) \
> > +  -DLLVM_OPTIMIZED_TABLEGEN=YES \
> > +  -DLLVM_ENABLE_ZLIB=YES \
> 
> zlib support is optional ?

Yes. Support for zlib is enabled by default, and it's possible to disable it.
Do you think it would be worth to enable it conditionally when zlib is being
built? Probably any target for which LLVM will be built surely has a few KiB
more for zlib.

> > +# XXX: LLVM does include some support for building native tools. This is used
> > +#      to build e.g. llvm-config, and a host-native llvm-tblgen if needed.
> > +#      Unfortunately, Buildroot is overzealous about passing the parameters
> > +#      needed for cross-building, and the CMake configuration for the native
> 
> Can you explain in what respect Buildroot is "overzealous"? Is there
> anything we can/should fix?

To be honest, I am not 100% sure that Buildroot is to blame here. There is
some code in the build files for LLVM which supposedly handle building a
version of ?llvm-config? which can be executed in the host:

  https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-config/CMakeLists.txt#L65

but even when ?CMAKE_CROSSCOMPILING? is indeed correctly set in the toolchain
file generated by Buildroot, when the tools under ?NATIVE/? are built normally
the results and up being ARM (=target) binaries. The same happens with the
?llvm-tblgen? binary, which needs to be run in the host during compilation.

After much struggling and trying different things, I settled on re-configuring
the ?NATIVE/? subdirectory to use ?HOST{CC,CXX}_NOCACHE? which has been working
reliably for weeks now (somehow, trying to use ccache here breaks the builds,
though :-S)

Because LLVM includes some provisions for cross-compiling which are not
working well, I assumed that maybe Buildroot is doing something funny here.
But take into account that my knowledge of CMake is limited (for now!) and it
could as well be that the LLVM build system is broken instead.

> > +#      tools ends up using the cross-toolchain. Once "cmake-package" has
> > +#      defined LLVM_*_CMDS, this adds:
> > +#
> > +#        - A call to CMake which resets CMAKE_{C,CXX,ASM}_COMPILER with the
> > +#          paths to the host-native ones. Note that using the *_NOCCACHE
> > +#          variables is needed, otherwise CMake will choke.
> > +#
> > +#        - The file "BuildVariables.inc" is copied over from the cross-build
> > +#          directory to the native one. This way a new "llvm-config" which
> > +#          can run on the build host returns information about the target
> > +#          build which gets installed in the sysroot. This is done as an
> > +#          appended build command. Note that Make has to be re-invoked to
> > +#          rebuild after copying the file over.
> > +#
> > +#        - Last but not least, "llvm-config" is copied into the sysroot with
> > +#          the target triple prefix, because packages using sane build systems
> > +#          will first try that.
> 
> Buildroot doesn't rename <foo>-config scripts/programs to be prefixed
> with the target triple prefix, so it would be better to keep it named
> llvm-config, like all other <foo>-config in $(STAGING_DIR)/usr/bin.

It's fine to just call the binary ?llvm-config?, the idea behind this was to
avoid this warning when configuring Mesa3D:

  Checking for llvm-config... /home/aperez/devel/wpe/buildroot-upstream/output/host/usr/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/bin/llvm-config
  configure: WARNING: using cross tools not prefixed with host triplet

Let's change it back to just ?llvm-config?, then.

> > +LLVM_CONFIGURE_CMDS += \
> 
> Using those += is really not clean. Instead, you should use
> POST_CONFIGURE_HOOKS, POST_BUILD_HOOKS and POST_INSTALL_STAGING_HOOKS.

Certainly.

> However, I'd really like to understand how Buildroot is "overzealous"
> and see if things can work out of the box without doing those hacks.

As mentioned above, I do not have a good reason to be 100% sure that this is
Buildroot's fault. Any ideas on what may be going on here will be very welcome
and I am willing to try and improve this as much as my spare time allows. In
the next days I won't have the chance to spend time figuring this out, but at
any rate, I will be submitting an updated patch today or tomorrow with the
rest of suggested changes.

Cheers,

--
 Adri?n ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170619/811d091c/attachment.asc>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH v2 1/2] llvm: new package
  2017-06-16 20:41 ` [Buildroot] [PATCH 1/2] llvm: new package Adrian Perez de Castro
  2017-06-17 14:31   ` Thomas Petazzoni
@ 2017-06-19 19:03   ` Adrian Perez de Castro
  2017-06-19 19:03     ` [Buildroot] [PATCH v2 2/2] mesa3d: Allow optionally using LLVM in drivers Adrian Perez de Castro
  2017-07-02 10:32     ` [Buildroot] [PATCH v2 1/2] llvm: new package Romain Naour
  1 sibling, 2 replies; 9+ messages in thread
From: Adrian Perez de Castro @ 2017-06-19 19:03 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>

---
Changes v1 -> v2:
    - Added missing Signed-off-by in patch.
    - Renamed BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT to BR2_PACKAGE_LLVM_ARCH_SUPPORTS
      and made its dependencies more readable.
    - Fixed indentation of help texts in Config.in.
    - Changed comment in Config.in to use the standard Buildroot wording.
    - Handle converting Buildroot's target architecture to LLVM's in
      Config.in instead of in llvm.mk.
    - Change LLVM_LICENSE to use the SPDX license string.
    - Use hooks in llvm.mk instead of appending commands to LLVM_*_CMDS.
    - Fixed all the code style issues pointed out by
      support/scripts/check-package.
---
 package/Config.in                                  |   1 +
 ...-Clean-up-exported-values-update-for-shar.patch |  58 +++++++++++
 package/llvm/Config.in                             |  54 ++++++++++
 package/llvm/llvm.hash                             |   2 +
 package/llvm/llvm.mk                               | 116 +++++++++++++++++++++
 5 files changed, 231 insertions(+)
 create mode 100644 package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
 create mode 100644 package/llvm/Config.in
 create mode 100644 package/llvm/llvm.hash
 create mode 100644 package/llvm/llvm.mk

diff --git a/package/Config.in b/package/Config.in
index aeb7430c89..f8a9dcc307 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -146,6 +146,7 @@ menu "Development tools"
 	source "package/jo/Config.in"
 	source "package/jq/Config.in"
 	source "package/libtool/Config.in"
+	source "package/llvm/Config.in"
 	source "package/make/Config.in"
 	source "package/patch/Config.in"
 	source "package/pkgconf/Config.in"
diff --git a/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
new file mode 100644
index 0000000000..a687e60af7
--- /dev/null
+++ b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
@@ -0,0 +1,58 @@
+From 628b899be14a6bab4b32dbd53aabd447dcc16cb7 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Sat, 20 Aug 2016 23:47:41 +0200
+Subject: [PATCH] llvm-config: Clean up exported values, update for shared
+ linking
+
+Gentoo-specific fixup for llvm-config, including:
+- wiping build-specific CFLAGS, CXXFLAGS,
+- making --src-root return invalid path (/dev/null).
+
+Thanks to Steven Newbury for the initial patch.
+
+Bug: https://bugs.gentoo.org/565358
+Bug: https://bugs.gentoo.org/501684
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/llvm/files/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
+
+Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
+
+diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
+index 744fa4e44d1..593788aaef3 100644
+--- a/tools/llvm-config/CMakeLists.txt
++++ b/tools/llvm-config/CMakeLists.txt
+@@ -32,8 +32,12 @@ get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
+ set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
+ set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
+ set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+-set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+-set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
++# Just use CMAKE_CPP_FLAGS for CFLAGS and CXXFLAGS, otherwise compiler
++# specific flags will be set when we don't know what compiler will be used
++# with external project utilising llvm-config.  C++ Standard is required.
++# TODO: figure out if we can remove -std=c++11 and move it to revdeps.
++set(LLVM_CFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
++set(LLVM_CXXFLAGS "${CMAKE_CPP_FLAGS} -std=c++11 ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+ set(LLVM_BUILD_SYSTEM cmake)
+ set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
+ set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}")
+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
+index d780094861c..c61c72ff48c 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -549,7 +550,11 @@ int main(int argc, char **argv) {
+       } else if (Arg == "--obj-root") {
+         OS << ActivePrefix << '\n';
+       } else if (Arg == "--src-root") {
+-        OS << LLVM_SRC_ROOT << '\n';
++        if (IsInDevelopmentTree) {
++          OS << LLVM_SRC_ROOT << '\n';
++        } else {
++          OS << "/dev/null\n";
++        }
+       } else if (Arg == "--ignore-libllvm") {
+         LinkDyLib = false;
+         LinkMode = BuiltSharedLibs ? LinkModeShared : LinkModeAuto;
+-- 
+2.11.0
+
diff --git a/package/llvm/Config.in b/package/llvm/Config.in
new file mode 100644
index 0000000000..f6145fd7f6
--- /dev/null
+++ b/package/llvm/Config.in
@@ -0,0 +1,54 @@
+config BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	bool
+	default y if BR2_arm || BR2_armeb
+	default y if BR2_aarch64
+	default y if BR2_i386 || BR2_x86_64
+	default y if BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el
+	default y if BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le
+	default y if BR2_sparc
+
+config BR2_PACKAGE_LLVM_TARGET_ARCH
+	string
+	default "ARM" if BR2_arm || BR2_armeb
+	default "AArch64" if BR2_aarch64
+	default "X86" if BR2_i386 || BR2_x86_64
+	default "Mips" if BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el
+	default "PowerPC" if BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le
+	default "Sparc" if BR2_sparc
+
+config BR2_PACKAGE_LLVM
+	bool "llvm"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on BR2_INSTALL_LIBSTDCPP
+	depends on BR2_TOOLCHAIN_BUILDROOT_WCHAR
+	select BR2_PACKAGE_LIBXML2
+	select BR2_PACKAGE_ZLIB
+	help
+	  The LLVM Project is a collection of modular and reusable
+	  compiler and toolchain technologies.
+
+	  http://llvm.org
+
+comment "llvm needs a toolchain w/ C++, wchar"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+
+if BR2_PACKAGE_LLVM
+
+config BR2_PACKAGE_LLVM_ENABLE_FFI
+	bool "Support libffi"
+	select BR2_PACKAGE_LIBFFI
+	help
+	  Use libffi in the LLVM Interpreter in order to enable calling
+	  external functions.
+
+config BR2_PACKAGE_LLVM_ENABLE_RTTI
+	bool "C++: Support RTTI"
+	help
+	  Enable support for C++ Run-Time Type Information (RTTI)
+
+config BR2_PACKAGE_LLVM_ENABLE_EH
+	bool "C++: Support exception handling"
+	help
+	  Enable support for C++ exception handling (try/catch)
+
+endif
diff --git a/package/llvm/llvm.hash b/package/llvm/llvm.hash
new file mode 100644
index 0000000000..b11cd14bf4
--- /dev/null
+++ b/package/llvm/llvm.hash
@@ -0,0 +1,2 @@
+# Computed locally after checking the GPG signature:
+sha256 8d10511df96e73b8ff9e7abbfb4d4d432edbdbe965f1f4f07afaf370b8a533be  llvm-4.0.0.src.tar.xz
diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
new file mode 100644
index 0000000000..9d10f3a5c6
--- /dev/null
+++ b/package/llvm/llvm.mk
@@ -0,0 +1,116 @@
+################################################################################
+#
+# llvm
+#
+################################################################################
+
+LLVM_VERSION = 4.0.0
+LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
+LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
+LLVM_LICENSE = NCSA
+LLVM_LICENSE_FILES = LICENSE.TXT
+LLVM_INSTALL_STAGING = YES
+LLVM_DEPENDENCIES = libxml2 zlib host-python
+
+LLVM_TARGET_ARCH = $(call qstrip,$(BR2_PACKAGE_LLVM_TARGET_ARCH))
+
+# List of build options at:
+#    http://llvm.org/docs/CMake.html
+#
+LLVM_CONF_OPTS = \
+	-DLLVM_DEFAULT_TARGET_TRIPLE=$(GNU_TARGET_NAME) \
+	-DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME) \
+	-DLLVM_TARGETS_TO_BUILD=$(LLVM_TARGET_ARCH) \
+	-DLLVM_TARGET_ARCH=$(LLVM_TARGET_ARCH) \
+	-DLLVM_OPTIMIZED_TABLEGEN=YES \
+	-DLLVM_ENABLE_ZLIB=YES \
+	-DLLVM_INCLUDE_TOOLS=YES \
+	-DLLVM_INCLUDE_UTILS=NO \
+	-DLLVM_INCLUDE_EXAMPLES=NO \
+	-DLLVM_INCLUDE_TESTS=NO \
+	-DLLVM_BUILD_TESTS=NO \
+	-DLLVM_BUILD_RUNTIME=NO \
+	-DLLVM_ENABLE_PROJECTS=''
+
+# The Go bindings have no CMake rules@the moment, but better remove the
+# check preventively. Building the Go and OCaml bindings is yet unsupported.
+#
+LLVM_CONF_OPTS += \
+	-DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND \
+	-DOCAMLFIND=OCAMLFIND-NOTFOUND
+
+# Building per-component shared libraries is NOT recommended by upstream.
+# The all-in-one libLLVM-<version>.so is enabled with a different setting.
+LLVM_CONF_OPTS += \
+	-DBUILD_SHARED_LIBS=NO \
+	-DLLVM_BUILD_LLVM_DYLIB=$(if $(BR2_STATIC_LIBS),NO,YES)
+
+ifeq ($(BR2_PACKAGE_LLVM_ENABLE_FFI),y)
+LLVM_DEPENDENCIES += libffi
+LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=YES
+else
+LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=NO
+endif
+
+ifeq ($(BR2_PACKAGE_LLVM_ENABLE_RTTI),y)
+LLVM_CONF_OPTS += -DLLVM_ENABLE_RTTI=YES
+else
+LLVM_CONF_OPTS += -DLLVM_ENABLE_RTTI=NO
+endif
+
+ifeq ($(BR2_PACKAGE_LLVM_ENABLE_EH),y)
+LLVM_CONF_OPTS += -DLLVM_ENABLE_EH=YES
+else
+LLVM_CONF_OPTS += -DLLVM_ENABLE_EH=NO
+endif
+
+# LLVM expects to always be built in a separate directory.
+LLVM_SUPPORTS_IN_SOURCE_BUILD = NO
+
+# XXX: LLVM does include some support for building native tools. This is used
+#      to build e.g. llvm-config, and a host-native llvm-tblgen if needed.
+#      Unfortunately, Buildroot is overzealous about passing the parameters
+#      needed for cross-building, and the CMake configuration for the native
+#      tools ends up using the cross-toolchain. Once "cmake-package" has
+#      defined LLVM_*_CMDS, this adds:
+#
+#        - A call to CMake which resets CMAKE_{C,CXX,ASM}_COMPILER with the
+#          paths to the host-native ones. Note that using the *_NOCCACHE
+#          variables is needed, otherwise CMake will choke.
+#
+#        - The file "BuildVariables.inc" is copied over from the cross-build
+#          directory to the native one. This way a new "llvm-config" which
+#          can run on the build host returns information about the target
+#          build which gets installed in the sysroot. This is done as an
+#          appended build command. Note that Make has to be re-invoked to
+#          rebuild after copying the file over.
+#
+#        - Last but not least, "llvm-config" is copied into the sysroot with
+#          the target triple prefix, because packages using sane build systems
+#          will first try that.
+#
+
+define LLVM_CONFIGURE_NATIVE_TOOLS_CMDS
+	cd $(LLVM_BUILDDIR)/NATIVE && \
+	PATH=$(BR_PATH) $(LLVM_CONF_ENV) $(BR2_CMAKE) $(LLVM_SRCDIR) \
+		-DCMAKE_C_COMPILER='$(HOSTCC_NOCCACHE)' \
+		-DCMAKE_ASM_COMPILER='$(HOSTCC_NOCCACHE)' \
+		-DCMAKE_CXX_COMPILER='$(HOSTCXX_NOCCACHE)'
+endef
+
+LLVM_POST_CONFIGURE_HOOKS += LLVM_CONFIGURE_NATIVE_TOOLS_CMDS
+
+define LLVM_REBUILD_NATIVE_LLVM_CONFIG_CMDS
+	cp $(LLVM_BUILDDIR)/tools/llvm-config/BuildVariables.inc $(LLVM_BUILDDIR)/NATIVE/tools/llvm-config/BuildVariables.inc
+	$(HOST_MAKE_ENV) $(LLVM_MAKE_ENV) $(LLVM_MAKE) $(LLVM_MAKE_OPTS) -C $(LLVM_BUILDDIR)/NATIVE llvm-config
+endef
+
+LLVM_POST_BUILD_HOOKS += LLVM_REBUILD_NATIVE_LLVM_CONFIG_CMDS
+
+define LLVM_INSTALL_STAGING_NATIVE_LLVM_CONFIG_CMDS
+	install -Dm755 $(LLVM_BUILDDIR)/NATIVE/bin/llvm-config $(STAGING_DIR)/usr/bin/llvm-config
+endef
+
+LLVM_POST_INSTALL_STAGING_HOOKS += LLVM_INSTALL_STAGING_NATIVE_LLVM_CONFIG_CMDS
+
+$(eval $(cmake-package))
-- 
2.13.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH v2 2/2] mesa3d: Allow optionally using LLVM in drivers
  2017-06-19 19:03   ` [Buildroot] [PATCH v2 " Adrian Perez de Castro
@ 2017-06-19 19:03     ` Adrian Perez de Castro
  2017-07-02 10:32     ` [Buildroot] [PATCH v2 1/2] llvm: new package Romain Naour
  1 sibling, 0 replies; 9+ messages in thread
From: Adrian Perez de Castro @ 2017-06-19 19:03 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
---
 package/mesa3d/Config.in | 11 +++++++++++
 package/mesa3d/mesa3d.mk |  9 ++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/package/mesa3d/Config.in b/package/mesa3d/Config.in
index 36a0304e27..03a0668a01 100644
--- a/package/mesa3d/Config.in
+++ b/package/mesa3d/Config.in
@@ -44,6 +44,17 @@ config BR2_PACKAGE_MESA3D_DRIVER
 config BR2_PACKAGE_MESA3D_NEEDS_XA
 	bool
 
+config BR2_PACKAGE_MESA3D_USE_LLVM
+	bool "Enable LLVM usage"
+	default y
+	depends on BR2_PACKAGE_LLVM
+	select BR2_PACKAGE_LLVM_ENABLE_RTTI
+	help
+		Build optimized driver code which makes use of LLVM (e.g. llvmpipe).
+
+comment "optional llvm support depends on llvm"
+	depends on !BR2_PACKAGE_LLVM
+
 comment "Gallium drivers"
 
 config BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_ETNAVIV
diff --git a/package/mesa3d/mesa3d.mk b/package/mesa3d/mesa3d.mk
index 04a7d13b97..5076a9b930 100644
--- a/package/mesa3d/mesa3d.mk
+++ b/package/mesa3d/mesa3d.mk
@@ -57,6 +57,13 @@ MESA3D_CONF_OPTS += \
 	--disable-xa
 endif
 
+ifeq ($(BR2_PACKAGE_MESA3D_USE_LLVM),y)
+MESA3D_DEPENDENCIES += llvm
+MESA3D_CONF_OPTS += --enable-llvm
+else
+MESA3D_CONF_OPTS += --disable-llvm
+endif
+
 # Drivers
 
 #Gallium Drivers
@@ -214,6 +221,6 @@ MESA3D_CONF_OPTS += --disable-lmsensors
 endif
 
 # Avoid automatic search of llvm-config
-MESA3D_CONF_OPTS += --with-llvm-prefix=$(STAGING_DIR)/usr/bin
+MESA3D_CONF_OPTS += --with-llvm-prefix=$(STAGING_DIR)/usr
 
 $(eval $(autotools-package))
-- 
2.13.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D
  2017-06-16 20:41 [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D Adrian Perez de Castro
  2017-06-16 20:41 ` [Buildroot] [PATCH 1/2] llvm: new package Adrian Perez de Castro
  2017-06-16 20:41 ` [Buildroot] [PATCH 2/2] mesa3d: Allow optionally using LLVM in drivers Adrian Perez de Castro
@ 2017-07-01 12:52 ` Romain Naour
  2 siblings, 0 replies; 9+ messages in thread
From: Romain Naour @ 2017-07-01 12:52 UTC (permalink / raw)
  To: buildroot

Hi Adrian,

Le 16/06/2017 ? 22:41, Adrian Perez de Castro a ?crit :
> Hello everybody,
> 
> This set of patches adds an LLVM package. For now my main motivation is to
> enable support for llvmpipe in Mesa3D'd swrast Gallium driver, which we I am
> using in am embedded ARM device which does not provide a GPU, and software
> rendering is enough for a small 320x240 LCD framebuffer -- so that is tested
> and working.
> 
> So far the built LLVM enables only the code generation backend for the CPU of
> the target device, which fits the Mesa3D use-case. Having a llvm package in
> Buildroot is interesting for many reasons, and I see this as a first step, on
> top of which to build on later: target packages for new programming languages
> using Clang+LLVM as cross-toolchain, or enabling building programs written in
> Rust are just a few examples.
> 
> I'll be happy to iterate on these patches with your feedback (keep me CC'd,
> please), and have them upstream.

Thanks for this work!

I also tried to add llvm and clang in Buildroot but it's not finished yet.
See [1].
I successfully tested llvmpipe with a HD6310 graphic card and I also try to
enable libclc support (openCL).

I'll take a look at your patches and try to improve the llvm packaging.
First, I'll rebase the work on the latest llvm release 4.0.1.

Best regards,
Romain

[1] https://github.com/RomainNaour/buildroot/tree/clang-llvm-v4.0.0

> 
> Best regards,
> 
> --
>  Adri?n ?
> 
> Adrian Perez de Castro (2):
>   llvm: new package
>   mesa3d: Allow optionally using LLVM in drivers
> 
>  package/Config.in                                  |   1 +
>  ...-Clean-up-exported-values-update-for-shar.patch |  57 ++++++++
>  package/llvm/Config.in                             |  48 +++++++
>  package/llvm/llvm.hash                             |   2 +
>  package/llvm/llvm.mk                               | 145 +++++++++++++++++++++
>  package/mesa3d/Config.in                           |  11 ++
>  package/mesa3d/mesa3d.mk                           |   9 +-
>  7 files changed, 272 insertions(+), 1 deletion(-)
>  create mode 100644 package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
>  create mode 100644 package/llvm/Config.in
>  create mode 100644 package/llvm/llvm.hash
>  create mode 100644 package/llvm/llvm.mk
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Buildroot] [PATCH v2 1/2] llvm: new package
  2017-06-19 19:03   ` [Buildroot] [PATCH v2 " Adrian Perez de Castro
  2017-06-19 19:03     ` [Buildroot] [PATCH v2 2/2] mesa3d: Allow optionally using LLVM in drivers Adrian Perez de Castro
@ 2017-07-02 10:32     ` Romain Naour
  1 sibling, 0 replies; 9+ messages in thread
From: Romain Naour @ 2017-07-02 10:32 UTC (permalink / raw)
  To: buildroot

Hi Adrian,

Le 19/06/2017 ? 21:03, Adrian Perez de Castro a ?crit :
> Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
> 
> ---
> Changes v1 -> v2:
>     - Added missing Signed-off-by in patch.
>     - Renamed BR2_PACKAGE_HOST_LLVM_ARCH_SUPPORT to BR2_PACKAGE_LLVM_ARCH_SUPPORTS
>       and made its dependencies more readable.
>     - Fixed indentation of help texts in Config.in.
>     - Changed comment in Config.in to use the standard Buildroot wording.
>     - Handle converting Buildroot's target architecture to LLVM's in
>       Config.in instead of in llvm.mk.
>     - Change LLVM_LICENSE to use the SPDX license string.
>     - Use hooks in llvm.mk instead of appending commands to LLVM_*_CMDS.
>     - Fixed all the code style issues pointed out by
>       support/scripts/check-package.
> ---
>  package/Config.in                                  |   1 +
>  ...-Clean-up-exported-values-update-for-shar.patch |  58 +++++++++++
>  package/llvm/Config.in                             |  54 ++++++++++
>  package/llvm/llvm.hash                             |   2 +
>  package/llvm/llvm.mk                               | 116 +++++++++++++++++++++
>  5 files changed, 231 insertions(+)
>  create mode 100644 package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
>  create mode 100644 package/llvm/Config.in
>  create mode 100644 package/llvm/llvm.hash
>  create mode 100644 package/llvm/llvm.mk
> 
> diff --git a/package/Config.in b/package/Config.in
> index aeb7430c89..f8a9dcc307 100644
> --- a/package/Config.in
> +++ b/package/Config.in
> @@ -146,6 +146,7 @@ menu "Development tools"
>  	source "package/jo/Config.in"
>  	source "package/jq/Config.in"
>  	source "package/libtool/Config.in"
> +	source "package/llvm/Config.in"
>  	source "package/make/Config.in"
>  	source "package/patch/Config.in"
>  	source "package/pkgconf/Config.in"
> diff --git a/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> new file mode 100644
> index 0000000000..a687e60af7
> --- /dev/null
> +++ b/package/llvm/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch

The patch should be named
0001-llvm-config-Clean-up-exported-values-update-for-shar.patch

> @@ -0,0 +1,58 @@
> +From 628b899be14a6bab4b32dbd53aabd447dcc16cb7 Mon Sep 17 00:00:00 2001
> +From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
> +Date: Sat, 20 Aug 2016 23:47:41 +0200
> +Subject: [PATCH] llvm-config: Clean up exported values, update for shared
> + linking
> +
> +Gentoo-specific fixup for llvm-config, including:
> +- wiping build-specific CFLAGS, CXXFLAGS,
> +- making --src-root return invalid path (/dev/null).
> +
> +Thanks to Steven Newbury for the initial patch.
> +
> +Bug: https://bugs.gentoo.org/565358
> +Bug: https://bugs.gentoo.org/501684
> +
> +Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/llvm/files/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
> +
> +Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
> +
> +diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
> +index 744fa4e44d1..593788aaef3 100644
> +--- a/tools/llvm-config/CMakeLists.txt
> ++++ b/tools/llvm-config/CMakeLists.txt
> +@@ -32,8 +32,12 @@ get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
> + set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
> + set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
> + set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")

> +-set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
> +-set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")

> ++# Just use CMAKE_CPP_FLAGS for CFLAGS and CXXFLAGS, otherwise compiler
> ++# specific flags will be set when we don't know what compiler will be used
> ++# with external project utilising llvm-config.  C++ Standard is required.
> ++# TODO: figure out if we can remove -std=c++11 and move it to revdeps.

> ++set(LLVM_CFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
> ++set(LLVM_CXXFLAGS "${CMAKE_CPP_FLAGS} -std=c++11 ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")

The Gentoo bug is quite old now (2015) can you check if this part is still needed ?

With llvm-config build without this patch, -std=c++1y is present in cxxflags.

./test/llvm/host/usr/bin/llvm-config --cxxflags
-I/home/naourr/buildroot-test/test/llvm/host/usr/include -O2
-I/home/naourr/buildroot-test/test/llvm/host/usr/include -fPIC
-fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long
-Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment
-Werror=date-time -std=c++1y -ffunction-sections -fdata-sections -O2 -DNDEBUG
-fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

> + set(LLVM_BUILD_SYSTEM cmake)
> + set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
> + set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}")
> +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
> +index d780094861c..c61c72ff48c 100644
> +--- a/tools/llvm-config/llvm-config.cpp
> ++++ b/tools/llvm-config/llvm-config.cpp
> +@@ -549,7 +550,11 @@ int main(int argc, char **argv) {
> +       } else if (Arg == "--obj-root") {
> +         OS << ActivePrefix << '\n';
> +       } else if (Arg == "--src-root") {
> +-        OS << LLVM_SRC_ROOT << '\n';
> ++        if (IsInDevelopmentTree) {
> ++          OS << LLVM_SRC_ROOT << '\n';
> ++        } else {
> ++          OS << "/dev/null\n";
> ++        }

Indeed:
./test/llvm/host/usr/bin/llvm-config --src-root
/home/naourr/buildroot-test/test/llvm/build/host-llvm-4.0.1

Do you know which package using llvm use --src-root option ?

> +       } else if (Arg == "--ignore-libllvm") {
> +         LinkDyLib = false;
> +         LinkMode = BuiltSharedLibs ? LinkModeShared : LinkModeAuto;
> +-- 
> +2.11.0
> +
> diff --git a/package/llvm/Config.in b/package/llvm/Config.in
> new file mode 100644
> index 0000000000..f6145fd7f6
> --- /dev/null
> +++ b/package/llvm/Config.in
> @@ -0,0 +1,54 @@
> +config BR2_PACKAGE_LLVM_ARCH_SUPPORTS
> +	bool
> +	default y if BR2_arm || BR2_armeb
> +	default y if BR2_aarch64
> +	default y if BR2_i386 || BR2_x86_64
> +	default y if BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el
> +	default y if BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le
> +	default y if BR2_sparc
> +
> +config BR2_PACKAGE_LLVM_TARGET_ARCH
> +	string
> +	default "ARM" if BR2_arm || BR2_armeb
> +	default "AArch64" if BR2_aarch64
> +	default "X86" if BR2_i386 || BR2_x86_64
> +	default "Mips" if BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el
> +	default "PowerPC" if BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le
> +	default "Sparc" if BR2_sparc
> +
> +config BR2_PACKAGE_LLVM
> +	bool "llvm"

llvm needs at least gcc 4.8:
http://releases.llvm.org/4.0.1/docs/ReleaseNotes.html

> +	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
> +	depends on BR2_INSTALL_LIBSTDCPP
> +	depends on BR2_TOOLCHAIN_BUILDROOT_WCHAR
> +	select BR2_PACKAGE_LIBXML2

I don't see why libxml2 is selected here. llvm doesn't check for this library.

> +	select BR2_PACKAGE_ZLIB
> +	help
> +	  The LLVM Project is a collection of modular and reusable
> +	  compiler and toolchain technologies.
> +
> +	  http://llvm.org
> +
> +comment "llvm needs a toolchain w/ C++, wchar"
> +	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
> +
> +if BR2_PACKAGE_LLVM
> +
> +config BR2_PACKAGE_LLVM_ENABLE_FFI
> +	bool "Support libffi"
> +	select BR2_PACKAGE_LIBFFI
> +	help
> +	  Use libffi in the LLVM Interpreter in order to enable calling
> +	  external functions.
> +
> +config BR2_PACKAGE_LLVM_ENABLE_RTTI
> +	bool "C++: Support RTTI"
> +	help
> +	  Enable support for C++ Run-Time Type Information (RTTI)
> +
> +config BR2_PACKAGE_LLVM_ENABLE_EH
> +	bool "C++: Support exception handling"
> +	help
> +	  Enable support for C++ exception handling (try/catch)
> +
> +endif
> diff --git a/package/llvm/llvm.hash b/package/llvm/llvm.hash
> new file mode 100644
> index 0000000000..b11cd14bf4
> --- /dev/null
> +++ b/package/llvm/llvm.hash
> @@ -0,0 +1,2 @@
> +# Computed locally after checking the GPG signature:
> +sha256 8d10511df96e73b8ff9e7abbfb4d4d432edbdbe965f1f4f07afaf370b8a533be  llvm-4.0.0.src.tar.xz
> diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
> new file mode 100644
> index 0000000000..9d10f3a5c6
> --- /dev/null
> +++ b/package/llvm/llvm.mk
> @@ -0,0 +1,116 @@
> +################################################################################
> +#
> +# llvm
> +#
> +################################################################################
> +
> +LLVM_VERSION = 4.0.0
> +LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
> +LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
> +LLVM_LICENSE = NCSA
> +LLVM_LICENSE_FILES = LICENSE.TXT
> +LLVM_INSTALL_STAGING = YES
> +LLVM_DEPENDENCIES = libxml2 zlib host-python
> +
> +LLVM_TARGET_ARCH = $(call qstrip,$(BR2_PACKAGE_LLVM_TARGET_ARCH))
> +
> +# List of build options at:
> +#    http://llvm.org/docs/CMake.html
> +#
> +LLVM_CONF_OPTS = \
> +	-DLLVM_DEFAULT_TARGET_TRIPLE=$(GNU_TARGET_NAME) \
> +	-DLLVM_HOST_TRIPLE=$(GNU_TARGET_NAME) \
> +	-DLLVM_TARGETS_TO_BUILD=$(LLVM_TARGET_ARCH) \

I believe we should take into account other target like AMDGPU.
I've tested mesa3d with llvm shaders enabled for an HD6310 graphic card on a
x86_64 target.

> +	-DLLVM_TARGET_ARCH=$(LLVM_TARGET_ARCH) \
> +	-DLLVM_OPTIMIZED_TABLEGEN=YES \
> +	-DLLVM_ENABLE_ZLIB=YES \
> +	-DLLVM_INCLUDE_TOOLS=YES \
> +	-DLLVM_INCLUDE_UTILS=NO \
> +	-DLLVM_INCLUDE_EXAMPLES=NO \
> +	-DLLVM_INCLUDE_TESTS=NO \
> +	-DLLVM_BUILD_TESTS=NO \
> +	-DLLVM_BUILD_RUNTIME=NO \
> +	-DLLVM_ENABLE_PROJECTS=''
> +
> +# The Go bindings have no CMake rules at the moment, but better remove the
> +# check preventively. Building the Go and OCaml bindings is yet unsupported.
> +#
> +LLVM_CONF_OPTS += \
> +	-DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND \
> +	-DOCAMLFIND=OCAMLFIND-NOTFOUND
> +
> +# Building per-component shared libraries is NOT recommended by upstream.
> +# The all-in-one libLLVM-<version>.so is enabled with a different setting.

Indeed, there is a NOTE about this in docs/CMake.rst.

  .. note:: BUILD_SHARED_LIBS is only recommended for use by LLVM developers.
            If you want to build LLVM as a shared library, you should use the
            ``LLVM_BUILD_LLVM_DYLIB`` option.

> +LLVM_CONF_OPTS += \
> +	-DBUILD_SHARED_LIBS=NO \
> +	-DLLVM_BUILD_LLVM_DYLIB=$(if $(BR2_STATIC_LIBS),NO,YES)

I'm not sure we really want to support llvm for static build only.

> +
> +ifeq ($(BR2_PACKAGE_LLVM_ENABLE_FFI),y)
> +LLVM_DEPENDENCIES += libffi
> +LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=YES
> +else
> +LLVM_CONF_OPTS += -DLLVM_ENABLE_FFI=NO
> +endif
> +
> +ifeq ($(BR2_PACKAGE_LLVM_ENABLE_RTTI),y)
> +LLVM_CONF_OPTS += -DLLVM_ENABLE_RTTI=YES
> +else
> +LLVM_CONF_OPTS += -DLLVM_ENABLE_RTTI=NO
> +endif
> +
> +ifeq ($(BR2_PACKAGE_LLVM_ENABLE_EH),y)
> +LLVM_CONF_OPTS += -DLLVM_ENABLE_EH=YES
> +else
> +LLVM_CONF_OPTS += -DLLVM_ENABLE_EH=NO
> +endif
> +
> +# LLVM expects to always be built in a separate directory.
> +LLVM_SUPPORTS_IN_SOURCE_BUILD = NO
> +
> +# XXX: LLVM does include some support for building native tools. This is used
> +#      to build e.g. llvm-config, and a host-native llvm-tblgen if needed.
> +#      Unfortunately, Buildroot is overzealous about passing the parameters
> +#      needed for cross-building, and the CMake configuration for the native
> +#      tools ends up using the cross-toolchain. Once "cmake-package" has
> +#      defined LLVM_*_CMDS, this adds:
> +#
> +#        - A call to CMake which resets CMAKE_{C,CXX,ASM}_COMPILER with the
> +#          paths to the host-native ones. Note that using the *_NOCCACHE
> +#          variables is needed, otherwise CMake will choke.
> +#
> +#        - The file "BuildVariables.inc" is copied over from the cross-build
> +#          directory to the native one. This way a new "llvm-config" which
> +#          can run on the build host returns information about the target
> +#          build which gets installed in the sysroot. This is done as an
> +#          appended build command. Note that Make has to be re-invoked to
> +#          rebuild after copying the file over.
> +#
> +#        - Last but not least, "llvm-config" is copied into the sysroot with
> +#          the target triple prefix, because packages using sane build systems
> +#          will first try that.
> +#
> +
> +define LLVM_CONFIGURE_NATIVE_TOOLS_CMDS
> +	cd $(LLVM_BUILDDIR)/NATIVE && \
> +	PATH=$(BR_PATH) $(LLVM_CONF_ENV) $(BR2_CMAKE) $(LLVM_SRCDIR) \
> +		-DCMAKE_C_COMPILER='$(HOSTCC_NOCCACHE)' \
> +		-DCMAKE_ASM_COMPILER='$(HOSTCC_NOCCACHE)' \
> +		-DCMAKE_CXX_COMPILER='$(HOSTCXX_NOCCACHE)'
> +endef

I believe we should add a host-llvm package to provide llvm-tblgen and
llvm-config binaries, so we can use -DLLVM_TABLEGEN instead of theses hooks.

# Use native llvm-tblgen from host-llvm.
LLVM_CONF_OPTS += -DLLVM_TABLEGEN=$(HOST_DIR)/usr/bin/llvm-tblgen

> +
> +LLVM_POST_CONFIGURE_HOOKS += LLVM_CONFIGURE_NATIVE_TOOLS_CMDS
> +
> +define LLVM_REBUILD_NATIVE_LLVM_CONFIG_CMDS
> +	cp $(LLVM_BUILDDIR)/tools/llvm-config/BuildVariables.inc $(LLVM_BUILDDIR)/NATIVE/tools/llvm-config/BuildVariables.inc
> +	$(HOST_MAKE_ENV) $(LLVM_MAKE_ENV) $(LLVM_MAKE) $(LLVM_MAKE_OPTS) -C $(LLVM_BUILDDIR)/NATIVE llvm-config
> +endef
> +
> +LLVM_POST_BUILD_HOOKS += LLVM_REBUILD_NATIVE_LLVM_CONFIG_CMDS
> +
> +define LLVM_INSTALL_STAGING_NATIVE_LLVM_CONFIG_CMDS
> +	install -Dm755 $(LLVM_BUILDDIR)/NATIVE/bin/llvm-config $(STAGING_DIR)/usr/bin/llvm-config

You should use "$(INSTALL) -D -m 0755" here.

> +endef
> +
> +LLVM_POST_INSTALL_STAGING_HOOKS += LLVM_INSTALL_STAGING_NATIVE_LLVM_CONFIG_CMDS
> +
> +$(eval $(cmake-package))
> 

I'm working on a new patch series using llvm 4.0.1 including your changes, also
I'll speak with Thomas about it during the Summer Camp.

Best regards,
Romain

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-07-02 10:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-16 20:41 [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D Adrian Perez de Castro
2017-06-16 20:41 ` [Buildroot] [PATCH 1/2] llvm: new package Adrian Perez de Castro
2017-06-17 14:31   ` Thomas Petazzoni
2017-06-19 18:41     ` Adrian Perez de Castro
2017-06-19 19:03   ` [Buildroot] [PATCH v2 " Adrian Perez de Castro
2017-06-19 19:03     ` [Buildroot] [PATCH v2 2/2] mesa3d: Allow optionally using LLVM in drivers Adrian Perez de Castro
2017-07-02 10:32     ` [Buildroot] [PATCH v2 1/2] llvm: new package Romain Naour
2017-06-16 20:41 ` [Buildroot] [PATCH 2/2] mesa3d: Allow optionally using LLVM in drivers Adrian Perez de Castro
2017-07-01 12:52 ` [Buildroot] [PATCH 0/2] Adding LLVM + support for it in Mesa3D Romain Naour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox