[v4,1/4] build: unblock the use of the MSVC compiler

Message ID 1691778287-15746-2-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series enable use of the MSVC compiler |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing fail build patch failure

Commit Message

Tyler Retzlaff Aug. 11, 2023, 6:24 p.m. UTC
  Detect when MSVC toolset is available and tweak toolchain arguments
where the meson build system offers no abstraction.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 config/meson.build     | 23 +++++++++++++++--------
 config/x86/meson.build | 10 ++++++----
 lib/meson.build        | 13 ++++++++++---
 3 files changed, 31 insertions(+), 15 deletions(-)
  

Comments

Bruce Richardson Aug. 14, 2023, 8:27 a.m. UTC | #1
On Fri, Aug 11, 2023 at 11:24:44AM -0700, Tyler Retzlaff wrote:
> Detect when MSVC toolset is available and tweak toolchain arguments
> where the meson build system offers no abstraction.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  config/meson.build     | 23 +++++++++++++++--------
>  config/x86/meson.build | 10 ++++++----
>  lib/meson.build        | 13 ++++++++++---
>  3 files changed, 31 insertions(+), 15 deletions(-)
> 
> diff --git a/config/meson.build b/config/meson.build
> index d822371..b6c7d48 100644
> --- a/config/meson.build
> +++ b/config/meson.build
> @@ -16,7 +16,8 @@ endforeach
>  
>  # MS linker requires special treatment.
>  # TODO: use cc.get_linker_id() with Meson >= 0.54
> -is_ms_linker = is_windows and (cc.get_id() == 'clang')
> +is_ms_compiler = is_windows and (cc.get_id() == 'msvc')
> +is_ms_linker = is_windows and (cc.get_id() == 'clang' or is_ms_compiler)

Question out of interest, what other linker option do we have on windows?
When is the second part of this conditional false?

/Bruce
  
Dmitry Kozlyuk Aug. 14, 2023, 9:07 a.m. UTC | #2
2023-08-14 09:27 (UTC+0100), Bruce Richardson:
> On Fri, Aug 11, 2023 at 11:24:44AM -0700, Tyler Retzlaff wrote:
> > Detect when MSVC toolset is available and tweak toolchain arguments
> > where the meson build system offers no abstraction.
> > 
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> > ---
> >  config/meson.build     | 23 +++++++++++++++--------
> >  config/x86/meson.build | 10 ++++++----
> >  lib/meson.build        | 13 ++++++++++---
> >  3 files changed, 31 insertions(+), 15 deletions(-)
> > 
> > diff --git a/config/meson.build b/config/meson.build
> > index d822371..b6c7d48 100644
> > --- a/config/meson.build
> > +++ b/config/meson.build
> > @@ -16,7 +16,8 @@ endforeach
> >  
> >  # MS linker requires special treatment.
> >  # TODO: use cc.get_linker_id() with Meson >= 0.54
> > -is_ms_linker = is_windows and (cc.get_id() == 'clang')
> > +is_ms_compiler = is_windows and (cc.get_id() == 'msvc')
> > +is_ms_linker = is_windows and (cc.get_id() == 'clang' or is_ms_compiler)  
> 
> Question out of interest, what other linker option do we have on windows?
> When is the second part of this conditional false?

MinGW: GCC    + GNU ld (the second conditional is false)
Clang: clang  + link.exe
MSVC:  cl.exe + link.exe
  
Bruce Richardson Aug. 14, 2023, 9:12 a.m. UTC | #3
On Mon, Aug 14, 2023 at 12:07:34PM +0300, Dmitry Kozlyuk wrote:
> 2023-08-14 09:27 (UTC+0100), Bruce Richardson:
> > On Fri, Aug 11, 2023 at 11:24:44AM -0700, Tyler Retzlaff wrote:
> > > Detect when MSVC toolset is available and tweak toolchain arguments
> > > where the meson build system offers no abstraction.
> > > 
> > > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > > Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> > > ---
> > >  config/meson.build     | 23 +++++++++++++++--------
> > >  config/x86/meson.build | 10 ++++++----
> > >  lib/meson.build        | 13 ++++++++++---
> > >  3 files changed, 31 insertions(+), 15 deletions(-)
> > > 
> > > diff --git a/config/meson.build b/config/meson.build
> > > index d822371..b6c7d48 100644
> > > --- a/config/meson.build
> > > +++ b/config/meson.build
> > > @@ -16,7 +16,8 @@ endforeach
> > >  
> > >  # MS linker requires special treatment.
> > >  # TODO: use cc.get_linker_id() with Meson >= 0.54
> > > -is_ms_linker = is_windows and (cc.get_id() == 'clang')
> > > +is_ms_compiler = is_windows and (cc.get_id() == 'msvc')
> > > +is_ms_linker = is_windows and (cc.get_id() == 'clang' or is_ms_compiler)  
> > 
> > Question out of interest, what other linker option do we have on windows?
> > When is the second part of this conditional false?
> 
> MinGW: GCC    + GNU ld (the second conditional is false)
> Clang: clang  + link.exe
> MSVC:  cl.exe + link.exe

Thanks. I'd forgottena bout mingw!
  

Patch

diff --git a/config/meson.build b/config/meson.build
index d822371..b6c7d48 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -16,7 +16,8 @@  endforeach
 
 # MS linker requires special treatment.
 # TODO: use cc.get_linker_id() with Meson >= 0.54
-is_ms_linker = is_windows and (cc.get_id() == 'clang')
+is_ms_compiler = is_windows and (cc.get_id() == 'msvc')
+is_ms_linker = is_windows and (cc.get_id() == 'clang' or is_ms_compiler)
 
 # set the major version, which might be used by drivers and libraries
 # depending on the configuration options
@@ -129,12 +130,14 @@  endif
 dpdk_conf.set('RTE_MACHINE', cpu_instruction_set)
 machine_args = []
 
-# ppc64 does not support -march= at all, use -mcpu and -mtune for that
-if host_machine.cpu_family().startswith('ppc')
-    machine_args += '-mcpu=' + cpu_instruction_set
-    machine_args += '-mtune=' + cpu_instruction_set
-else
-    machine_args += '-march=' + cpu_instruction_set
+if not is_ms_compiler
+    # ppc64 does not support -march= at all, use -mcpu and -mtune for that
+    if host_machine.cpu_family().startswith('ppc')
+        machine_args += '-mcpu=' + cpu_instruction_set
+        machine_args += '-mtune=' + cpu_instruction_set
+    else
+        machine_args += '-march=' + cpu_instruction_set
+    endif
 endif
 
 toolchain = cc.get_id()
@@ -253,7 +256,11 @@  if cc.get_id() == 'clang' and dpdk_conf.get('RTE_ARCH_64') == false
 endif
 
 # add -include rte_config to cflags
-add_project_arguments('-include', 'rte_config.h', language: 'c')
+if is_ms_compiler
+    add_project_arguments('/FI', 'rte_config.h', language: 'c')
+else
+    add_project_arguments('-include', 'rte_config.h', language: 'c')
+endif
 
 # enable extra warnings and disable any unwanted warnings
 # -Wall is added by default at warning level 1, and -Wextra
diff --git a/config/x86/meson.build b/config/x86/meson.build
index 54345c4..38cc1e3 100644
--- a/config/x86/meson.build
+++ b/config/x86/meson.build
@@ -24,10 +24,12 @@  if cc.has_argument('-mavx512f')
     endif
 endif
 
-# we require SSE4.2 for DPDK
-if cc.get_define('__SSE4_2__', args: machine_args) == ''
-    message('SSE 4.2 not enabled by default, explicitly enabling')
-    machine_args += '-msse4'
+if not is_ms_compiler
+    # we require SSE4.2 for DPDK
+    if cc.get_define('__SSE4_2__', args: machine_args) == ''
+        message('SSE 4.2 not enabled by default, explicitly enabling')
+        machine_args += '-msse4'
+    endif
 endif
 
 base_flags = ['SSE', 'SSE2', 'SSE3','SSSE3', 'SSE4_1', 'SSE4_2']
diff --git a/lib/meson.build b/lib/meson.build
index 92cbd6b..7da3698 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -230,9 +230,16 @@  foreach l:libraries
                 output: '@0@_exports.def'.format(libname))
         lk_deps += [def_file]
 
-        lk_args = ['-Wl,/def:' + def_file.full_path()]
-        if meson.version().version_compare('<0.54.0')
-            lk_args += ['-Wl,/implib:lib\\librte_' + l + '.dll.a']
+        if is_ms_compiler
+            lk_args = ['/def:' + def_file.full_path()]
+            if meson.version().version_compare('<0.54.0')
+                lk_args += ['/implib:lib\\librte_' + l + '.dll.a']
+            endif
+        else
+            lk_args = ['-Wl,/def:' + def_file.full_path()]
+            if meson.version().version_compare('<0.54.0')
+                lk_args += ['-Wl,/implib:lib\\librte_' + l + '.dll.a']
+            endif
         endif
     else
         if is_windows