[v2,2/4] buildtools: use macro to embed information in binaries

Message ID 1744680096-17683-3-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Superseded
Delegated to: David Marchand
Headers
Series allow pmdinfo to be inserted and parsed using MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andre Muezerie April 15, 2025, 1:21 a.m. UTC
The archiver tool from the MSVC toolset is lib.exe. It has different
parameters then it's GNU counterpart "ar".

buildtools\meson.build was updated to use lib.exe when MSVC compiler is
used. This is to allow the code to be built without requiring GNU "ar"
to be installed in that scenario.

Script gen-pmdinfo-cfile.py was updated to use the correct parameters
when using lib.exe.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 buildtools/gen-pmdinfo-cfile.py | 10 +++++++---
 buildtools/meson.build          |  4 +++-
 buildtools/pmdinfogen.py        |  5 +++--
 3 files changed, 13 insertions(+), 6 deletions(-)
  

Comments

Dmitry Kozlyuk April 15, 2025, 7:44 a.m. UTC | #1
On 15.04.2025 04:21, Andre Muezerie wrote:
> -_, tmp_root, ar, archive, output, *pmdinfogen = sys.argv
> +_, tmp_root, archiver, archive, output, *pmdinfogen = sys.argv
>   with tempfile.TemporaryDirectory(dir=tmp_root) as temp:
>       paths = []
> -    for name in subprocess.run([ar, "t", archive], stdout=subprocess.PIPE,
> +    if archiver == 'lib':
> +        archiver_options = ['/LIST', '/NOLOGO']
> +    else:
> +        archiver_options = ['t']
> +    for name in subprocess.run([archiver] + archiver_options + [archive], stdout=subprocess.PIPE,
>                                  check=True).stdout.decode().splitlines():
>           if os.path.exists(name):
>               paths.append(name)
>           else:
> -            subprocess.run([ar, "x", os.path.abspath(archive), name],
> +            subprocess.run([archiver, "x", os.path.abspath(archive), name],
>                              check=True, cwd=temp)
>               paths.append(os.path.join(temp, name))
>       subprocess.run(pmdinfogen + paths + [output], check=True)
Does `lib.exe` support `x`? Can't find this option in the doc:
https://learn.microsoft.com/en-us/cpp/build/reference/running-lib?view=msvc-170
  
Andre Muezerie April 15, 2025, 2:36 p.m. UTC | #2
On Tue, Apr 15, 2025 at 10:44:51AM +0300, Dmitry Kozlyuk wrote:
> On 15.04.2025 04:21, Andre Muezerie wrote:
> >-_, tmp_root, ar, archive, output, *pmdinfogen = sys.argv
> >+_, tmp_root, archiver, archive, output, *pmdinfogen = sys.argv
> >  with tempfile.TemporaryDirectory(dir=tmp_root) as temp:
> >      paths = []
> >-    for name in subprocess.run([ar, "t", archive], stdout=subprocess.PIPE,
> >+    if archiver == 'lib':
> >+        archiver_options = ['/LIST', '/NOLOGO']
> >+    else:
> >+        archiver_options = ['t']
> >+    for name in subprocess.run([archiver] + archiver_options + [archive], stdout=subprocess.PIPE,
> >                                 check=True).stdout.decode().splitlines():
> >          if os.path.exists(name):
> >              paths.append(name)
> >          else:
> >-            subprocess.run([ar, "x", os.path.abspath(archive), name],
> >+            subprocess.run([archiver, "x", os.path.abspath(archive), name],
> >                             check=True, cwd=temp)
> >              paths.append(os.path.join(temp, name))
> >      subprocess.run(pmdinfogen + paths + [output], check=True)
> Does `lib.exe` support `x`? Can't find this option in the doc:
> https://learn.microsoft.com/en-us/cpp/build/reference/running-lib?view=msvc-170

It does not. I'll update this in the next series.
  

Patch

diff --git a/buildtools/gen-pmdinfo-cfile.py b/buildtools/gen-pmdinfo-cfile.py
index 5fbd51658a..d1f1ea64fc 100644
--- a/buildtools/gen-pmdinfo-cfile.py
+++ b/buildtools/gen-pmdinfo-cfile.py
@@ -7,15 +7,19 @@ 
 import sys
 import tempfile
 
-_, tmp_root, ar, archive, output, *pmdinfogen = sys.argv
+_, tmp_root, archiver, archive, output, *pmdinfogen = sys.argv
 with tempfile.TemporaryDirectory(dir=tmp_root) as temp:
     paths = []
-    for name in subprocess.run([ar, "t", archive], stdout=subprocess.PIPE,
+    if archiver == 'lib':
+        archiver_options = ['/LIST', '/NOLOGO']
+    else:
+        archiver_options = ['t']
+    for name in subprocess.run([archiver] + archiver_options + [archive], stdout=subprocess.PIPE,
                                check=True).stdout.decode().splitlines():
         if os.path.exists(name):
             paths.append(name)
         else:
-            subprocess.run([ar, "x", os.path.abspath(archive), name],
+            subprocess.run([archiver, "x", os.path.abspath(archive), name],
                            check=True, cwd=temp)
             paths.append(os.path.join(temp, name))
     subprocess.run(pmdinfogen + paths + [output], check=True)
diff --git a/buildtools/meson.build b/buildtools/meson.build
index 1cd1ce02fd..11221f02ea 100644
--- a/buildtools/meson.build
+++ b/buildtools/meson.build
@@ -37,7 +37,9 @@  install_data([
 pmdinfo = py3 + files('gen-pmdinfo-cfile.py') + [meson.current_build_dir()]
 pmdinfogen = py3 + files('pmdinfogen.py')
 if host_machine.system() == 'windows'
-    if cc.get_id() == 'gcc'
+    if cc.get_id() == 'msvc'
+        pmdinfo += 'lib'
+    elif cc.get_id() == 'gcc'
         pmdinfo += 'ar'
     else
         pmdinfo += 'llvm-ar'
diff --git a/buildtools/pmdinfogen.py b/buildtools/pmdinfogen.py
index dfb89500c0..8eddbb798c 100755
--- a/buildtools/pmdinfogen.py
+++ b/buildtools/pmdinfogen.py
@@ -192,7 +192,7 @@  def dump(self, file):
         dumped = json.dumps(self.__dict__)
         escaped = dumped.replace('"', '\\"')
         print(
-            'const char %s_pmd_info[] __attribute__((used)) = "PMD_INFO_STRING= %s";'
+            'RTE_INCLUDE(const char, %s_pmd_info)[] = "PMD_INFO_STRING= %s";'
             % (self.name, escaped),
             file=file,
         )
@@ -252,7 +252,8 @@  def open_output(path):
 
 def write_header(output):
     output.write(
-        "static __attribute__((unused)) const char *generator = \"%s\";\n" % sys.argv[0]
+        "#include <rte_common.h>\n"
+        "static __rte_unused const char *generator = \"%s\";\n" % sys.argv[0]
     )