Repository: conan-io/conan (python)

Issue:
[bug] Feedback for experimental Premake Generator (wxsqlite3)
### Describe the bug

Thank you for introducing the new Premake generator in [this pull request](https://github.com/conan-io/conan/pull/17898). I tested it by creating a recipe for [wxsqlite3](https://github.com/utelle/wxsqlite3) and encountered a few issues along the way. If it's not ready for testing yet, please let me know.

Prerequisites:

OS: Windows
Conan Version: 31b7ff0937738b958d1c7cb8ce8ca5373f69364c (Git Commit Hash)

For reproducing you need to install [Premake 5.0.0-beta6](https://github.com/conan-io/conan-center-index/pull/27418) (this is a later version than the one in CCI). And my [wxsqlite3-recipe](https://github.com/Werni2A/conan-center-index/tree/test-premake-wxsqlite3/recipes/wxsqlite3).

I wanted to bring to your attention that I encountered two issues while running conan create on my wxsqlite3 recipe. I've addressed them with the patch file provided below.

The first issue is that Conan generates paths with backslashes, which are interpreted as escape characters—this seems to be a bug. The second issue involves a missing path or file; I'm unsure of the proper fix for this, so I opted to hardcode the value needed for my setup. I'm not sure if there is a way to configure this in my recipe rather than adjusting the conan executable.

```bash
# Install latest conan version with Premake support
uv tool install git+https://github.com/conan-io/conan --upgrade

# Install new Premake version from MR https://github.com/conan-io/conan-center-index/pull/27418
conan create recipes/premake/5.x --build missing --version 5.0.0-beta6

# Note that we require a few hacks in the Conan executable, therefore go to your conan clone
# patch it and install the patched version
git apply 0001-fix-Premake-compile-issues-during-wxsqlite3-build.patch
uv tool install --force --refresh path/to/patched/conan

conan create recipes/wxsqlite3/all --build missing --version 4.10.8
```

**`0001-fix-Premake-compile-issues-during-wxsqlite3-build.patch`**:
```patch
From 7ba6bfe4d1ecb68b5097e307c17ad8ae3b524674 Mon Sep 17 00:00:00 2001
From: Dominik Wernberger <dominik.wernberger@rohde-schwarz.com>
Date: Mon, 30 Jun 2025 15:56:52 +0200
Subject: [PATCH] fix: Premake compile issues during wxsqlite3 build

---
 conan/tools/microsoft/msbuild.py | 2 +-
 conan/tools/premake/premake.py   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/conan/tools/microsoft/msbuild.py b/conan/tools/microsoft/msbuild.py
index 4f4dd52e1..427a6592c 100644
--- a/conan/tools/microsoft/msbuild.py
+++ b/conan/tools/microsoft/msbuild.py
@@ -34,7 +34,7 @@ class MSBuild:
         #    msvc_arch.update(platforms)
         arch = conanfile.settings.get_safe("arch")
         # MSVC default platform for VS projects is "x86", not "Win32" (but CMake default is "Win32")
-        msvc_platform = msvc_platform_from_arch(arch) if arch != "x86" else "x86"
+        msvc_platform = "Win64"
         if conanfile.settings.get_safe("os") == "WindowsCE":
             msvc_platform = conanfile.settings.get_safe("os.platform")
         #: Defines the platform name, e.g., ``ARM`` if ``settings.arch == "armv7"``.
diff --git a/conan/tools/premake/premake.py b/conan/tools/premake/premake.py
index 606808063..7500d836e 100644
--- a/conan/tools/premake/premake.py
+++ b/conan/tools/premake/premake.py
@@ -66,7 +66,7 @@ class Premake:
         """
         if self._premake_conan_toolchain.exists():
             content = Template(self._premake_file_template).render(
-                premake_conan_toolchain=self._premake_conan_toolchain, luafile=self.luafile
+                premake_conan_toolchain=self._premake_conan_toolchain.as_posix(), luafile=self.luafile
             )
             conan_luafile = Path(self._conanfile.build_folder) / self.filename
             save(self._conanfile, conan_luafile, content)
-- 
2.40.1.windows.1


```


### How to reproduce it

_No response_

Pull request:
Preamke generator: fix some issues with windows paths and MSBuild
Changelog: Feature: Allow defining a custom platform on Premake generator for Windows
Docs: omit

Fixes #18570

Docs generated by autoclass (sphinx) 

- [x] Refer to the issue that supports this Pull Request.
- [x] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [x] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop2/.github/CONTRIBUTING.md).
- [x] I've followed the PEP8 style guides for Python code.
- [x] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one.


Patch:
diff --git a/conan/tools/premake/premake.py b/conan/tools/premake/premake.py
index 606808063..2d90af900 100644
--- a/conan/tools/premake/premake.py
+++ b/conan/tools/premake/premake.py
@@ -66,7 +66,7 @@ class Premake:
         """
         if self._premake_conan_toolchain.exists():
             content = Template(self._premake_file_template).render(
-                premake_conan_toolchain=self._premake_conan_toolchain, luafile=self.luafile
+                premake_conan_toolchain=self._premake_conan_toolchain.as_posix(), luafile=self.luafile
             )
             conan_luafile = Path(self._conanfile.build_folder) / self.filename
             save(self._conanfile, conan_luafile, content)
@@ -98,7 +98,7 @@ class Premake:
         # --verbose does not print compilation commands but internal Makefile progress logic
         return " verbose=1" if verbosity == "verbose" else ""
 
-    def build(self, workspace, targets=None):
+    def build(self, workspace, targets=None, msbuild_platform=None):
         """
         Depending on the action, this method will run either ``msbuild`` or ``make`` with ``N_JOBS``.
         You can specify ``N_JOBS`` through the configuration line ``tools.build:jobs=N_JOBS``
@@ -106,11 +106,14 @@ class Premake:
 
         :param workspace: ``str`` Specifies the solution to be compiled (only used by ``MSBuild``).
         :param targets: ``List[str]`` Declare the projects to be built (None to build all projects).
+        :param msbuild_platform: ``str`` Specify the platform for the internal MSBuild generator (only used by ``MSBuild``).
         """
         if not self._premake_conan_toolchain.exists():
-            raise ConanException(f"Premake.build() method requires PrmakeToolchain to work properly")
+            raise ConanException("Premake.build() method requires PrmakeToolchain to work properly")
         if self.action.startswith("vs"):
             msbuild = MSBuild(self._conanfile)
+            if msbuild_platform:
+                msbuild.platform = msbuild_platform
             msbuild.build(sln=f"{workspace}.sln", targets=targets)
         else:
             build_type = str(self._conanfile.settings.build_type)


Test patch:
diff --git a/test/integration/toolchains/premake/test_premake.py b/test/integration/toolchains/premake/test_premake.py
index b6faeef54..b1ca86e29 100644
--- a/test/integration/toolchains/premake/test_premake.py
+++ b/test/integration/toolchains/premake/test_premake.py
@@ -2,6 +2,7 @@ import textwrap
 
 from conan.test.utils.tools import TestClient
 
+
 def test_premake_args_without_toolchain():
     c = TestClient()
     conanfile = textwrap.dedent("""
@@ -19,8 +20,14 @@ def test_premake_args_without_toolchain():
                 premake.configure()
                 """)
     c.save({"conanfile.py": conanfile})
-    c.run("build . -s compiler=msvc -s compiler.version=193 -s compiler.runtime=dynamic")
-    assert 'conanfile.py: Running premake5 --file="myproject.lua" vs2022 --myarg=myvalue!!' in c.out
+    c.run(
+        "build . -s compiler=msvc -s compiler.version=193 -s compiler.runtime=dynamic"
+    )
+    assert (
+        'conanfile.py: Running premake5 --file="myproject.lua" vs2022 --myarg=myvalue!!'
+        in c.out
+    )
+
 
 def test_premake_build_without_toolchain():
     tc = TestClient()
@@ -98,3 +105,37 @@ def test_premake_build_with_targets():
     assert 'conanfile.premake5.lua" gmake --arch=arm64!!' in tc.out
     assert "Running make config=release app test -j42!!" in tc.out
 
+
+def test_premake_msbuild_platform():
+    tc = TestClient()
+    windows_profile = textwrap.dedent("""
+        [settings]
+        arch=x86_64
+        build_type=Release
+        compiler=msvc
+        compiler.cppstd=14
+        compiler.runtime=dynamic
+        compiler.version=194
+        os=Windows
+    """)
+
+    conanfile = textwrap.dedent(
+        """
+        from conan import ConanFile
+        from conan.tools.premake import Premake, PremakeToolchain
+
+        class Pkg(ConanFile):
+            settings = "os", "compiler", "build_type", "arch"
+            generators = "PremakeToolchain"
+            def run(self, cmd, *args, **kwargs):
+                self.output.info(f"Running {cmd}!!")
+            def build(self):
+                premake = Premake(self)
+                premake.configure()
+                premake.build(workspace="App", msbuild_platform="Win64")
+                """
+    )
+    tc.save({"conanfile.py": conanfile, "win": windows_profile})
+    tc.run("build . -pr win")
+    assert 'conanfile.premake5.lua" vs2022 --arch=x86_64!!' in tc.out
+    assert 'Running msbuild.exe "App.sln" -p:Configuration="Release" -p:Platform=Win64!!' in tc.out