[Mesa-dev] [PATCH 1/6] meson: Build i965 and dri stack

Dylan Baker dylan at pnwbakers.com
Wed Oct 4 21:58:12 UTC 2017


Quoting Eric Anholt (2017-10-04 14:25:30)
> Dylan Baker <dylan at pnwbakers.com> writes:
> 
> > This gets pretty much the entire classic tree building, as well as
> > i965, including the various glapis. There are some workarounds for bugs
> > that are fixed in meson 0.43.0, which is due out on October 8th.
> >
> > I have tested this with piglit using glx.
> >
> > Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
> 
> I didn't do a side-by-side diff or anything, but this looks pretty
> good.  A few comments...
> 
> > diff --git a/bin/install_megadrivers.py b/bin/install_megadrivers.py
> > new file mode 100755
> > index 00000000000..50a4323a6e8
> > --- /dev/null
> > +++ b/bin/install_megadrivers.py
> > @@ -0,0 +1,68 @@
> > +#!/usr/bin/env python
> > +# encoding=utf-8
> > +# Copyright © 2017 Intel Corporation
> > +
> > +# Permission is hereby granted, free of charge, to any person obtaining a copy
> > +# of this software and associated documentation files (the "Software"), to deal
> > +# in the Software without restriction, including without limitation the rights
> > +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> > +# copies of the Software, and to permit persons to whom the Software is
> > +# furnished to do so, subject to the following conditions:
> > +
> > +# The above copyright notice and this permission notice shall be included in
> > +# all copies or substantial portions of the Software.
> > +
> > +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> > +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> > +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> > +# SOFTWARE.
> > +
> > +"""Script to install megadriver symlinks for meson."""
> > +
> > +import argparse
> > +import errno
> > +import os
> > +import shutil
> > +
> > +
> > +def main():
> > +    parser = argparse.ArgumentParser()
> > +    parser.add_argument('megadriver')
> > +    parser.add_argument('libdir')
> > +    parser.add_argument('drivers', nargs='+')
> > +    args = parser.parse_args()
> > +
> > +    to = os.path.join(os.environ.get('MESON_INSTALL_DESTDIR_PREFIX'), args.libdir)
> > +
> > +    cross_found = False
> > +
> > +    if not os.path.exists(to):
> > +        os.makedirs(to)
> > +    from_ = args.megadriver
> > +
> > +    for each in args.drivers:
> > +        final = os.path.join(to, each)
> > +        if os.path.exists(final):
> > +            os.unlink(final)
> > +        print('installing {} to {}'.format(args.megadriver, to))
> > +        try:
> > +            os.link(from_, final)
> > +        except OSError as e:
> > +            if e.errno == errno.EXDEV:
> > +                if cross_found:
> > +                    raise Exception('Something went very wrong.')
> > +                # if we hit this then we're trying to link from one filesystem,
> > +                # which is obviously invalid. Instead copy the first binary,
> > +                # then set that as the from so that the hard links will work
> > +                shutil.copy(from_, final)
> > +                from_ = final
> > +                cross_found = True
> > +            else:
> > +                raise
> 
> The old megadrivers install method would install under the build target
> name ("libmesa_dri_drivers.so"), link from that to the names we need,
> then remove libmesa_dri_drivers.so.  I like the sound of that -- no
> weird error handling like this, and if the developer decides to do
> something silly to the build target in the tree, it doesn't have
> surprise effects on the installed copy.  (I was worred about strip,
> though it does look like strip makes a new inode)
> 
> Would that be hard to do?

Not at all, and in fact that sounds better than what I did, which was not think
about cross device linking, and then do this after I tried to install to /tmp
and said, "hey..."

I'll fix that for v2

> > diff --git a/meson.build b/meson.build
> > index 5de64acefd6..1824a7ea184 100644
> > --- a/meson.build
> > +++ b/meson.build
> 
> > @@ -204,7 +255,39 @@ endif
> >  
> >  # TODO: cross-compiling. I don't think this is relavent to meson
> >  
> > -# TODO: assembly support. mesa and vc4
> > +# FIXME: enable asm when cross compiler
> > +# This is doable (autotools does it), but it's not of immediate concern
> > +if meson.is_cross_build()
> > +  message('Cross compiling, disabling asm')
> > +  with_asm = false
> > +endif
> > +
> > +with_asm_arch = ''
> > +if with_asm
> > +  # TODO: SPARC and PPC
> > +  if target_machine.cpu_family() == 'x86'
> > +    if ['linux', 'bsd'].contains(target_machine.system()) # FIXME: hurd?
> > +      with_asm_arch = 'x86'
> > +      pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
> > +                   '-DUSE_SSE_ASM']
> > +    endif
> > +  elif target_machine.cpu_family() == 'x86_64'
> > +    if target_machine.system() == 'linux'
> > +      with_asm_arch = 'x86_64'
> > +      pre_args += ['-DUSE_X86_64_ASM']
> > +    endif
> > +  elif target_machine.cpu_family() == 'arm'
> > +    if target_machine.system() == 'linux'
> > +      with_asm_arch = 'arm'
> > +      pre_args += ['-DUSE_ARM_ASM']
> > +    endif
> > +  elif target_machine.cpu_family() == 'aarch64'
> > +    if target_machine.system() == 'linux'
> > +      with_asm_arch = 'aarch64'
> > +      pre_args += ['-DUSE_AARCH64_ASM']
> > +    endif
> > +  endif
> > +endif
> 
> Generally one uses host_machine for "the system my build products will
> be run on".  It should be the same as target_machine for us, though.

Gah, a few of these slipped through... I'll fix that

> 
> > @@ -259,14 +342,14 @@ if cc.links('static char unused() { return 5; } int main() { return 0; }',
> >  endif
> >  
> >  # check for dl support
> > +# This is really only required for megadrivers
> 
> Huh?  We use dlopen in all the loaders, unrelated to megadrivers.
> 
> >  if cc.has_function('dlopen')
> >    dep_dl = []
> >  else
> >    dep_dl = cc.find_library('dl')
> >  endif
> > -
> > -if not cc.has_function('dladdr', dependencies : dep_dl)
> > -  error('dl library doesn\'t have dladdr')
> > +if cc.has_function('dladdr', dependencies : dep_dl)
> > +  pre_args += '-DHAVE_DLADDR'
> >  endif
> 
> Oh, I think you meant that comment here.

I think I screwed this up after rebasing on Matt's s3tc work.
I'll fix that too

> 
> > diff --git a/src/compiler/glsl/tests/meson.build b/src/compiler/glsl/tests/meson.build
> > new file mode 100644
> > index 00000000000..054c529387a
> > --- /dev/null
> > +++ b/src/compiler/glsl/tests/meson.build
> > @@ -0,0 +1,76 @@
> > +# Copyright © 2017 Intel Corporation
> > +
> > +# Permission is hereby granted, free of charge, to any person obtaining a copy
> > +# of this software and associated documentation files (the "Software"), to deal
> > +# in the Software without restriction, including without limitation the rights
> > +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> > +# copies of the Software, and to permit persons to whom the Software is
> > +# furnished to do so, subject to the following conditions:
> > +
> > +# The above copyright notice and this permission notice shall be included in
> > +# all copies or substantial portions of the Software.
> > +
> > +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> > +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> > +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> > +# SOFTWARE.
> > +
> > +glsl_blob_test = executable(
> > +  'blob_test',
> > +  'blob_test.c',
> > +  c_args : [c_vis_args, c_msvc_compat_args, no_override_init_args],
> > +  include_directories : [inc_common, inc_glsl],
> > +  link_with : [libglsl],
> > +)
> > +
> > +glsl_cache_test = executable(
> > +  'cache_test',
> > +  'cache_test.c',
> > +  c_args : [c_vis_args, c_msvc_compat_args, no_override_init_args],
> > +  include_directories : [inc_common, inc_glsl],
> > +  link_with : [libglsl],
> > +  dependencies : [dep_clock, dep_thread],
> > +)
> > +
> > +glsl_general_ir_test = executable(
> > +  'general_ir_test',
> > +  ['array_refcount_test.cpp', 'builtin_variable_test.cpp',
> > +   'invalidate_locations_test.cpp', 'general_ir_test.cpp',
> > +   'lower_int64_test.cpp', 'opt_add_neg_to_sub_test.cpp', 'varyings_test.cpp',
> > +   ir_expression_operation_h],
> > +  cpp_args : [cpp_vis_args, cpp_msvc_compat_args],
> > +  include_directories : [inc_common, inc_glsl],
> > +  link_with : [libglsl, libgtest, libglsl_standalone, libglsl_util],
> > +  dependencies : [dep_clock, dep_thread],
> > +)
> > +
> > +glsl_uniform_initializer_test = executable(
> > +  'uniform_initializer_test',
> > +  ['copy_constant_to_storage_tests.cpp', 'set_uniform_initializer_tests.cpp',
> > +   'uniform_initializer_utils.cpp', 'uniform_initializer_utils.h',
> > +   ir_expression_operation_h],
> > +  cpp_args : [cpp_vis_args, cpp_msvc_compat_args],
> > +  include_directories : [inc_common, inc_glsl],
> > +  link_with : [libglsl, libgtest, libglsl_util],
> > +  dependencies : [dep_thread],
> > +)
> > +
> > +glsl_sampler_types_test = executable(
> > +  'sampler_types_test',
> > +  ['sampler_types_test.cpp', ir_expression_operation_h],
> > +  cpp_args : [cpp_vis_args, cpp_msvc_compat_args],
> > +  include_directories : [inc_common, inc_glsl],
> > +  link_with : [libglsl, libgtest, libglsl_util],
> > +  dependencies : [dep_thread],
> > +)
> > +
> > +test('blob_test', glsl_blob_test)
> > +test('cache_test', glsl_cache_test)
> > +test('general_ir_test', glsl_general_ir_test)
> > +test('uniform_initializer_test', glsl_uniform_initializer_test)
> > +test('sampler_types_test', glsl_sampler_types_test)
> 
> General style thing: instead of making temporary names for the
> executable()s, you could just
> 
> test('blob_test', executable('blob_test', ...))
> 
> > +
> > +# TODO: figure out how to get the shell based tests to work?
> 
> The xserver's tests/meson.build has some examples.
> 
> > diff --git a/src/mapi/glapi/gen/meson.build b/src/mapi/glapi/gen/meson.build
> > index 3612f1f6416..f4c1343202c 100644
> > --- a/src/mapi/glapi/gen/meson.build
> > +++ b/src/mapi/glapi/gen/meson.build
> 
> > +
> > +glapi_gen_depends = files(
> > +  'gl_XML.py',
> > +  'glX_XML.py',
> > +  'license.py',
> > +  'static_data.py',
> > +  'typeexpr.py',
> > +) + api_xml_files
> > +
> > +glx_gen_depends = files(
> > +  'glX_API.xml',
> > +  'glX_XML.py',
> > +  'glX_proto_common.py',
> > +) + api_xml_files
> > +
> > +glapi_mapi_tmp_h = custom_target(
> > +  'glapi_mapi_tmp.h',
> > +  input : ['../../mapi_abi.py', 'gl_and_es_API.xml'],
> > +  output : 'glapi_mapi_tmp.h',
> > +  command : [prog_python2, '@INPUT0@', '--printer', 'glapi', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +gl_procs_h = custom_target(
> > +  'gl_procs.h',
> > +  input : ['gl_procs.py', 'gl_and_es_API.xml'],
> > +  output : 'gl_procs.h',
> > +  command : [prog_python2, '@INPUT0@', '-c', '-f', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glapitemp_h = custom_target(
> > +  'glapitemp.h',
> > +  input : ['gl_apitemp.py', 'gl_and_es_API.xml'],
> > +  output : 'glapitemp.h',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glapitable_h = custom_target(
> > +  'glapitable.h',
> > +  input : ['gl_table.py', 'gl_and_es_API.xml'],
> > +  output : 'glapitable.h',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glapi_gentable_c = custom_target(
> > +  'glapi_gentable.c',
> > +  input : ['gl_gentable.py', 'gl_and_es_API.xml'],
> > +  output : 'glapi_gentable.c',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +main_enums_c = custom_target(
> > +  'enums.c',
> > +  input : ['gl_enums.py', files('../registry/gl.xml')],
> > +  output : 'enums.c',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  capture : true,
> > +)
> > +
> > +main_api_exec_c = custom_target(
> > +  'api_exec.c',
> > +  input : ['gl_genexec.py', 'gl_and_es_API.xml'],
> > +  output : 'api_exec.c',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : files('apiexec.py') + glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +main_marshal_generated_c = custom_target(
> > +  'marshal_generated.c',
> > +  input : ['gl_marshal.py', 'gl_and_es_API.xml'],
> > +  output : 'marshal_generated.c',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : files('marshal_XML.py') + glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glx_indirect_c = custom_target(
> > +  'indirect.c',
> > +  input : ['glX_proto_send.py', 'gl_API.xml'],
> > +  output : 'indirect.c',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'proto'],
> > +  depend_files : glx_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glx_indirect_h = custom_target(
> > +  'indirect.h',
> > +  input : ['glX_proto_send.py', 'gl_API.xml'],
> > +  output : 'indirect.h',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'init_h'],
> > +  depend_files : glx_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glx_indirect_init_c = custom_target(
> > +  'indirect_init.c',
> > +  input : ['glX_proto_send.py', 'gl_API.xml'],
> > +  output : 'indirect_init.c',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'init_c'],
> > +  depend_files : glx_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glx_indirect_size_h = custom_target(
> > +  'indirect_size.h',
> > +  input : ['glX_proto_size.py', 'gl_API.xml'],
> > +  output : 'indirect_size.h',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'size_h',
> > +             '--header-tag', '_INDIRECT_SIZE_H_'],
> > +  depend_files : glx_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glx_indirect_size_c = custom_target(
> > +  'indirect_size.c',
> > +  input : ['glX_proto_size.py', 'gl_API.xml'],
> > +  output : 'indirect_size.c',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'size_c'],
> > +  depend_files : glx_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glapi_x86_s = custom_target(
> > +  'glapi_x86.S',
> > +  input : ['gl_x86_asm.py', gl_and_es_api_files],
> > +  output : 'glapi_x86.S',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glapi_x86_64_s = custom_target(
> > +  'glapi_x86-64.S',
> > +  input : ['gl_x86-64_asm.py', gl_and_es_api_files],
> > +  output : 'glapi_x86-64.S',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> > +
> > +glapi_sparc_s = custom_target(
> > +  'glapi_sparc.S',
> > +  input : ['gl_SPARC_asm.py', gl_and_es_api_files],
> > +  output : 'glapi_sparc.S',
> > +  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@'],
> > +  depend_files : glapi_gen_depends,
> > +  capture : true,
> > +)
> 
> It feels like some arrays and for loops could really help this file.

If it wasn't for mesa classic and mesa gallium most of these (at least the .c
and .S files) could be done with generators, which is what I did originally, but
that would cause each file to be regenerated in every target that used it, or
twice. I'll see what I can do about a loop. 

> 
> > diff --git a/src/mapi/shared-glapi/tests/check_table.cpp b/src/mapi/shared-glapi/tests/check_table.cpp
> > index 02d313c22d3..6eb98f11f1a 100644
> > --- a/src/mapi/shared-glapi/tests/check_table.cpp
> > +++ b/src/mapi/shared-glapi/tests/check_table.cpp
> > @@ -25,7 +25,11 @@
> >  #include "../../../mesa/main/glheader.h"
> >  
> >  #include "glapi/glapi.h"
> > -#include "glapi/glapitable.h"
> > +#ifdef MESON
> > +# include "glapitable.h"
> > +#else
> > +# include "glapi/glapitable.h"
> > +#endif
> >  
> >  struct name_offset {
> >     const char *name;
> 
> This seems strange.  Are we missing an include_directories()?

The autotools build works hard to put output in specific folders, meson assumes
that you don't care about what folder they're in and you'll include the target
in your sources list to set the includes properly. We could probably also fix
this by including glapi in the autotools and android builds (maybe scons too?).

I forgot about this little hack actually... I'll definitely fix this for v2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20171004/232c5705/attachment-0001.sig>


More information about the mesa-dev mailing list