summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-04-24 13:48:25 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-05-17 11:06:01 -0700
commit2a2240f41c210557d32717f7fd041a294562e1d1 (patch)
treea5ce8a2b990ac3eb558cba19d1db5978283213cb
parent05363d44a0dce99d296510c37f24e38627d127d2 (diff)
meson: Add support for wrapping llvm
For building on Windows (when not using cygwin), the assumption is that LLVM will have to be handled via a binary wrap. In this case the user wanting to use LLVM is this way will need to create a directory in subprojects (any name is fine), and pass that name via the -Dllvm-wrap option (for example, assuming subprojects/llvm, -Dllvm-wrap=llvm), which must have a meson.build file and the installed LLVM to link with (this can be either static or dynamic). There is documentation for what this needs to look like and how to define it.
-rw-r--r--docs/meson.html66
-rw-r--r--meson.build128
-rw-r--r--meson_options.txt6
-rw-r--r--src/gallium/drivers/swr/rasterizer/jitter/meson.build13
4 files changed, 154 insertions, 59 deletions
diff --git a/docs/meson.html b/docs/meson.html
index f394a22fc2..a736363c6c 100644
--- a/docs/meson.html
+++ b/docs/meson.html
@@ -124,6 +124,72 @@ dependency interface. It will search <code>$PATH</code> (or <code>%PATH%</code>
llvm-config, so using an LLVM from a non-standard path is as easy as
<code>PATH=/path/with/llvm-config:$PATH meson build</code>.
</p></dd>
+
+<dd><p>On windows (and in other cases), using llvm-config is either undesirable
+or impossible. Meson's solution for this is a
+<a href="http://mesonbuild.com/Wrap-dependency-system-manual.html">wrap</a>, in
+this case a "binary wrap". Follow the steps below:</p>
+<ul>
+ <li>Install the binaries and headers into a directory under the $mesa_src/subprojects</li>
+ <li>Add a meson build.build file to that directory (more on that later)</li>
+ <li>add -Dllvm-wrap=$directory to your meson configuration (where $directory is the the directory under subprojects</li>
+</ul>
+
+<p>The wrap file must define the following:</p>
+<ul>
+ <li>ext_llvm: a declare_dependency() object with include_directories, dependencies, and version set)</li>
+</ul>
+
+<p>It may also define:</p>
+<ul>
+ <li>irbuilder_h: a file() object pointing to llvm/IR/IRBuilder.h (for SWR)</li>
+</ul>
+
+<p>such a meson.build file might look like:</p>
+<pre>
+project('llvm', ['cpp'])
+
+cpp = meson.get_compiler('cpp')
+
+_deps = []
+_search = join_paths(meson.current_source_dir(), 'lib')
+foreach d : ['libLLVMCodeGen', 'libLLVMScalarOpts', 'libLLVMAnalysis',
+ 'libLLVMTransformUtils', 'libLLVMCore', 'libLLVMX86CodeGen',
+ 'libLLVMSelectionDAG', 'libLLVMipo', 'libLLVMAsmPrinter',
+ 'libLLVMInstCombine', 'libLLVMInstrumentation', 'libLLVMMC',
+ 'libLLVMGlobalISel', 'libLLVMObjectYAML', 'libLLVMDebugInfoPDB',
+ 'libLLVMVectorize', 'libLLVMPasses', 'libLLVMSupport',
+ 'libLLVMLTO', 'libLLVMObject', 'libLLVMDebugInfoCodeView',
+ 'libLLVMDebugInfoDWARF', 'libLLVMOrcJIT', 'libLLVMProfileData',
+ 'libLLVMObjCARCOpts', 'libLLVMBitReader', 'libLLVMCoroutines',
+ 'libLLVMBitWriter', 'libLLVMRuntimeDyld', 'libLLVMMIRParser',
+ 'libLLVMX86Desc', 'libLLVMAsmParser', 'libLLVMTableGen',
+ 'libLLVMFuzzMutate', 'libLLVMLinker', 'libLLVMMCParser',
+ 'libLLVMExecutionEngine', 'libLLVMCoverage', 'libLLVMInterpreter',
+ 'libLLVMTarget', 'libLLVMX86AsmParser', 'libLLVMSymbolize',
+ 'libLLVMDebugInfoMSF', 'libLLVMMCJIT', 'libLLVMXRay',
+ 'libLLVMX86AsmPrinter', 'libLLVMX86Disassembler',
+ 'libLLVMMCDisassembler', 'libLLVMOption', 'libLLVMIRReader',
+ 'libLLVMLibDriver', 'libLLVMDlltoolDriver', 'libLLVMDemangle',
+ 'libLLVMBinaryFormat', 'libLLVMLineEditor',
+ 'libLLVMWindowsManifest', 'libLLVMX86Info', 'libLLVMX86Utils']
+ _deps += cpp.find_library(d, dirs : _search)
+endforeach
+
+ext_llvm = declare_dependency(
+ include_directories : include_directories('include'),
+ dependencies : _deps,
+ version : '6.0.0',
+)
+
+irbuilder_h = files('include/llvm/IR/IRBuilder.h')
+</pre>
+
+<p>It is very important that version is defined and is accurate, if it is not,
+workarounds for the wrong version of LLVM might be used resulting in build
+failures.</p>
+
+</dd>
</dl>
<dl>
diff --git a/meson.build b/meson.build
index 43749e9628..78c3eb5918 100644
--- a/meson.build
+++ b/meson.build
@@ -1151,20 +1151,6 @@ if dep_libdrm.found()
endif
endif
-llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
-if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
- llvm_modules += ['amdgpu', 'bitreader', 'ipo']
- if with_gallium_r600
- llvm_modules += 'asmparser'
- endif
-endif
-if with_gallium_opencl
- llvm_modules += [
- 'all-targets', 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
- 'lto', 'option', 'objcarcopts', 'profiledata',
- ]
- # TODO: optional modules
-endif
if with_amd_vk or with_gallium_radeonsi or with_gallium_swr
_llvm_version = '>= 4.0.0'
@@ -1175,51 +1161,85 @@ else
endif
_llvm = get_option('llvm')
-if _llvm == 'auto'
- dep_llvm = dependency(
- 'llvm', version : _llvm_version, modules : llvm_modules,
- required : with_amd_vk or with_gallium_radeonsi or with_gallium_swr or with_gallium_opencl,
- )
- with_llvm = dep_llvm.found()
-elif _llvm == 'true'
- dep_llvm = dependency('llvm', version : _llvm_version, modules : llvm_modules)
- with_llvm = true
-else
- dep_llvm = null_dep
- with_llvm = false
-endif
-if with_llvm
- _llvm_version = dep_llvm.version().split('.')
- # Development versions of LLVM have an 'svn' or 'git' suffix, we don't want
- # that for our version checks.
- # svn suffixes are stripped by meson as of 0.43, and git suffixes are
- # strippped as of 0.44, but we support older meson versions.
-
- # 3 digits versions in LLVM only started from 3.4.1 on
- if dep_llvm.version().version_compare('>= 3.4.1')
- _llvm_patch = _llvm_version[2]
+llvm_wrap = get_option('llvm-wrap')
+if llvm_wrap != '' and _llvm != 'false'
+ dep_llvm = subproject(llvm_wrap).get_variable('ext_llvm')
+ if dep_llvm.version().version_compare(_llvm_version)
+ with_llvm = true
+ _ver = dep_llvm.version().split('.')
+ pre_args += [
+ '-DHAVE_LLVM=0x0@0@0@1@'.format(_ver[0], _ver[1]),
+ '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_ver[2]),
+ ]
+ elif _llvm == 'auto'
+ with_llvm = false
+ dep_llvm = null_dep
else
- _llvm_patch = '0'
+ error('LLVM wrap version is @0@, but components require @1@'.format(
+ dep_llvm.version(), _llvm_version))
endif
-
- if _llvm_patch.endswith('svn')
- _llvm_patch = _llvm_patch.split('s')[0]
- elif _llvm_patch.contains('git')
- _llvm_patch = _llvm_patch.split('g')[0]
+else
+ llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
+ if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
+ llvm_modules += ['amdgpu', 'bitreader', 'ipo']
+ if with_gallium_r600
+ llvm_modules += 'asmparser'
+ endif
endif
- pre_args += [
- '-DHAVE_LLVM=0x0@0@0@1@'.format(_llvm_version[0], _llvm_version[1]),
- '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
- ]
+ if with_gallium_opencl
+ llvm_modules += [
+ 'all-targets', 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
+ 'lto', 'option', 'objcarcopts', 'profiledata',
+ ]
+ # TODO: optional modules
+ endif
+
+ if _llvm == 'auto'
+ dep_llvm = dependency(
+ 'llvm', version : _llvm_version, modules : llvm_modules,
+ required : with_amd_vk or with_gallium_radeonsi or with_gallium_swr or with_gallium_opencl,
+ )
+ with_llvm = dep_llvm.found()
+ elif _llvm == 'true'
+ dep_llvm = dependency('llvm', version : _llvm_version, modules : llvm_modules)
+ with_llvm = true
+ else
+ dep_llvm = null_dep
+ with_llvm = false
+ endif
+ if with_llvm
+ _llvm_version = dep_llvm.version().split('.')
+ # Development versions of LLVM have an 'svn' or 'git' suffix, we don't want
+ # that for our version checks.
+ # svn suffixes are stripped by meson as of 0.43, and git suffixes are
+ # strippped as of 0.44, but we support older meson versions.
+
+ # 3 digits versions in LLVM only started from 3.4.1 on
+ if dep_llvm.version().version_compare('>= 3.4.1')
+ _llvm_patch = _llvm_version[2]
+ else
+ _llvm_patch = '0'
+ endif
+
+ if _llvm_patch.endswith('svn')
+ _llvm_patch = _llvm_patch.split('s')[0]
+ elif _llvm_patch.contains('git')
+ _llvm_patch = _llvm_patch.split('g')[0]
+ endif
+ pre_args += [
+ '-DHAVE_LLVM=0x0@0@0@1@'.format(_llvm_version[0], _llvm_version[1]),
+ '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
+ ]
- # LLVM can be built without rtti, turning off rtti changes the ABI of C++
- # programs, so we need to build all C++ code in mesa without rtti as well to
- # ensure that linking works.
- if dep_llvm.get_configtool_variable('has-rtti') == 'NO'
- cpp_args += '-fno-rtti'
+ # LLVM can be built without rtti, turning off rtti changes the ABI of C++
+ # programs, so we need to build all C++ code in mesa without rtti as well to
+ # ensure that linking works.
+ if dep_llvm.get_configtool_variable('has-rtti') == 'NO'
+ cpp_args += '-fno-rtti'
+ endif
+ elif with_amd_vk or with_gallium_radeonsi or with_gallium_swr
+ error('The following drivers require LLVM: Radv, RadeonSI, SWR. One of these is enabled, but LLVM is disabled.')
endif
-elif with_amd_vk or with_gallium_radeonsi or with_gallium_swr
- error('The following drivers require LLVM: Radv, RadeonSI, SWR. One of these is enabled, but LLVM is disabled.')
endif
dep_glvnd = null_dep
diff --git a/meson_options.txt b/meson_options.txt
index 5d3805e877..80af0224be 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -233,6 +233,12 @@ option(
description : 'Build with LLVM support.'
)
option(
+ 'llvm-wrap',
+ type : 'string',
+ value : '',
+ description : 'Use LLVM wrap dependency. This bypasses llvm-config, and is useful for cross compiling. This should be set to the value of the suproject. It expects an external_dependency called "ext_llvm"',
+)
+option(
'valgrind',
type : 'combo',
value : 'auto',
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/meson.build b/src/gallium/drivers/swr/rasterizer/jitter/meson.build
index 5c201990b5..7b6537d8b7 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/meson.build
+++ b/src/gallium/drivers/swr/rasterizer/jitter/meson.build
@@ -18,15 +18,18 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+if llvm_wrap != ''
+ _irbuilder_h = subproject('llvm').get_variable('irbuilder_h')
+else
+ _irbuilder_h = join_paths(
+ dep_llvm.get_configtool_variable('includedir'), 'llvm', 'IR', 'IRBuilder.h'
+ )
+endif
gen_builder_hpp = custom_target(
'gen_builder.hpp',
input : [
- swr_gen_llvm_ir_macros_py,
- join_paths(
- dep_llvm.get_configtool_variable('includedir'), 'llvm', 'IR',
- 'IRBuilder.h'
- )
+ swr_gen_llvm_ir_macros_py, _irbuilder_h,
],
output : 'gen_builder.hpp',
command : [