shithub: dav1d

Download patch

ref: d68a2fc18131191cf41a33ce8585df86f5c40dea
parent: d85fdf524dc88e0d9b3bb2bf4d45089c46d3abf0
author: Martin Storsjö <martin@martin.st>
date: Thu Sep 17 20:24:39 EDT 2020

meson: Use gas-preprocessor as generator, for targets that need it

Don't pass the .S assembly sources as C source files in this case,
as e.g. MSVC doesn't support them (and meson knows it doesn't, so
it refuses to proceed with an MSVC/gas-preprocessor wrapper script, as
meson detects it as MSVC - unless meson is hacked to allow passing .S
files to MSVC).

This allows building dav1d with MSVC for ARM targets without
hacks to meson. (Building in a pure MSVC setup with no other
compilers available does require a few new patches to gas-preprocessor
though.)

This has been postponed for quite some time, as compiling with
MSVC for non-x86 targets in meson has been problematic, as meson
used to require a working compiler for the build system as well,
and MSVC for all targets are named cl.exe, and you can't have one
for the cross target and the build machine first in the path at
the same time. This was recently fixed though, see
https://github.com/mesonbuild/meson/issues/4402 and
https://github.com/mesonbuild/meson/pull/6512.

This matches how gas-preprocessor is hooked up for e.g. OpenH264 in
https://github.com/cisco/openh264/commit/013c4566a219a1f0fd50a8186f2b11fd8c3efcfb.

--- a/meson.build
+++ b/meson.build
@@ -437,6 +437,28 @@
         ])
 endif
 
+use_gaspp = false
+if (is_asm_enabled and
+    (host_machine.cpu_family() == 'aarch64' or
+     host_machine.cpu_family().startswith('arm')) and
+    cc.get_argument_syntax() == 'msvc')
+    gaspp = find_program('gas-preprocessor.pl')
+    use_gaspp = true
+    gaspp_gen = generator(gaspp,
+        output: '@BASENAME@.obj',
+        arguments: [
+            '-as-type', 'armasm',
+            '-arch', host_machine.cpu_family(),
+            '--',
+            host_machine.cpu_family() == 'aarch64' ? 'armasm64' : 'armasm',
+            '-nologo',
+            '-I@0@'.format(dav1d_src_root),
+            '-I@0@/'.format(meson.current_build_dir()),
+            '@INPUT@',
+            '-c',
+            '-o', '@OUTPUT@'
+        ])
+endif
 
 # Generate config.h
 config_h_target = configure_file(output: 'config.h', configuration: cdata)
--- a/src/meson.build
+++ b/src/meson.build
@@ -82,7 +82,7 @@
 )
 
 # ASM specific sources
-libdav1d_nasm_objs = []
+libdav1d_asm_objs = []
 # Arch-specific flags
 arch_flags = []
 if is_asm_enabled
@@ -102,7 +102,7 @@
         )
         if (host_machine.cpu_family() == 'aarch64' or
             host_machine.cpu() == 'arm64')
-            libdav1d_sources += files(
+            libdav1d_sources_asm = files(
                 # itx.S is used for both 8 and 16 bpc.
                 'arm/64/itx.S',
                 'arm/64/looprestoration_common.S',
@@ -110,7 +110,7 @@
             )
 
             if dav1d_bitdepths.contains('8')
-                libdav1d_sources += files(
+                libdav1d_sources_asm += files(
                     'arm/64/cdef.S',
                     'arm/64/ipred.S',
                     'arm/64/loopfilter.S',
@@ -120,7 +120,7 @@
             endif
 
             if dav1d_bitdepths.contains('16')
-                libdav1d_sources += files(
+                libdav1d_sources_asm += files(
                     'arm/64/cdef16.S',
                     'arm/64/ipred16.S',
                     'arm/64/itx16.S',
@@ -130,12 +130,12 @@
                 )
             endif
         elif host_machine.cpu_family().startswith('arm')
-            libdav1d_sources += files(
+            libdav1d_sources_asm = files(
                 'arm/32/msac.S',
             )
 
             if dav1d_bitdepths.contains('8')
-                libdav1d_sources += files(
+                libdav1d_sources_asm += files(
                     'arm/32/cdef.S',
                     'arm/32/ipred.S',
                     'arm/32/itx.S',
@@ -146,11 +146,17 @@
             endif
 
             if dav1d_bitdepths.contains('16')
-                libdav1d_sources += files(
+                libdav1d_sources_asm += files(
                     'arm/32/mc16.S',
                 )
             endif
         endif
+
+        if use_gaspp
+            libdav1d_asm_objs = gaspp_gen.process(libdav1d_sources_asm)
+        else
+            libdav1d_sources += libdav1d_sources_asm
+        endif
     elif host_machine.cpu_family().startswith('x86')
 
         libdav1d_sources += files(
@@ -201,7 +207,7 @@
         endif
 
         # Compile the ASM sources with NASM
-        libdav1d_nasm_objs = nasm_gen.process(libdav1d_sources_asm)
+        libdav1d_asm_objs = nasm_gen.process(libdav1d_sources_asm)
     elif host_machine.cpu() == 'ppc64le'
         arch_flags = ['-maltivec', '-mvsx']
         libdav1d_sources += files(
@@ -291,7 +297,7 @@
 
 libdav1d = library('dav1d',
     libdav1d_sources,
-    libdav1d_nasm_objs,
+    libdav1d_asm_objs,
     libdav1d_rc_obj,
 
     objects : [
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -60,20 +60,27 @@
         checkasm_bitdepth_objs += checkasm_bitdepth_lib.extract_all_objects()
     endforeach
 
-    checkasm_nasm_objs = []
+    checkasm_asm_objs = []
+    checkasm_asm_sources = []
     if host_machine.cpu_family() == 'aarch64' or host_machine.cpu() == 'arm64'
-        checkasm_sources += files('checkasm/arm/checkasm_64.S')
+        checkasm_asm_sources += files('checkasm/arm/checkasm_64.S')
     elif host_machine.cpu_family().startswith('arm')
-        checkasm_sources += files('checkasm/arm/checkasm_32.S')
+        checkasm_asm_sources += files('checkasm/arm/checkasm_32.S')
     elif host_machine.cpu_family().startswith('x86')
-        checkasm_nasm_objs = nasm_gen.process(files('checkasm/x86/checkasm.asm'))
+        checkasm_asm_objs += nasm_gen.process(files('checkasm/x86/checkasm.asm'))
     endif
 
+    if use_gaspp
+        checkasm_asm_objs += gaspp_gen.process(checkasm_asm_sources)
+    else
+        checkasm_sources += checkasm_asm_sources
+    endif
+
     m_lib = cc.find_library('m', required: false)
 
     checkasm = executable('checkasm',
         checkasm_sources,
-        checkasm_nasm_objs,
+        checkasm_asm_objs,
 
         objects: [
             checkasm_bitdepth_objs,