Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native platform and namestyle #502

Open
KageKirin opened this issue Jun 12, 2020 · 7 comments
Open

Native platform and namestyle #502

KageKirin opened this issue Jun 12, 2020 · 7 comments

Comments

@KageKirin
Copy link
Contributor

Hi there,

I'm having a few issues with building generated projects on Windows, using Ninja (and clang), and as far as I have researched, it's linked to platform "native".

  • solution configuration: my solution configuration is pretty straightforward. In fact, it's based on GENie's configuration, without many additions. I'm not using toolchain.lua from BX (yet).

  • projgen: this one as well is basically projgen-windows from GENie's makefile:

    projgen-windows:
      $(SILENT) $(GENIE) --to=../build/$(PROJECT_TYPE).windows --os=windows $(GENIE_OPTIONS) $(PROJECT_TYPE)
  • the issue: the generated ninjafiles have .a as target extension for static libs, which should be .lib on Windows, even when compiling with GCC or Clang.

  • (what I found as) the cause:

    • in project.lua: premake.getnamestyle() searches for an existing value in premake.platforms["Native"] or premake.gettool() or returns posix.
    • premake.platforms["Native"] has no field for namestyle hence getnamestyle() returning posix.
    • posix in turn is then correctly used to retrieve the extensions for static libs

So far, I found an "easy" fix, namely to simply set namestyle.

		Native =
		{
			cfgsuffix       = "",
			namestyle       = os.is("windows") and "windows" or nil,
		},

This solves the issue at hand, but I think we could have a more flexible solution by exposing namestyle as API field. This way, it would be simple to set

configuration {"windows"}
namestyle "windows"
configuration {}

in the solution.

What do you think?
I can submit a PR of either my current solution or of the flexible solution.

Cheers.

@KageKirin KageKirin changed the title Question/Documentation: native platform and namestyle Native platform and namestyle Jun 12, 2020
@bkaradzic
Copy link
Owner

You can't decide about namestyle based on OS. For example generating project files on Windows OS for Linux. Or generating project files on Linux OS for MSVC Windows (.lib) vs. MinGW Windows (.a).

@bkaradzic
Copy link
Owner

Also whole OS is really deceptive because it's about where things are generated, not exactly for which platform which causes confusion all the time.

@KageKirin
Copy link
Contributor Author

Interestingly, os.get() / os.is() depend on the --os option if provided.

	function os.get()
		return _OPTIONS.os or _OS
	end

	function os.is(id)
		return (os.get():lower() == id:lower())
	end

IMHO, it's safe to assume that if you target Windows as OS by providing --os=windows you want Windows-style libs (.lib).

@KageKirin
Copy link
Contributor Author

Also, if we do it with an API field

configuration {"windows"}
namestyle "windows"
configuration {}

we can leave the configuration and its assumptions to the user.

@bkaradzic
Copy link
Owner

IMHO, it's safe to assume that if you target Windows as OS by providing --os=windows you want Windows-style libs (.lib).

This assumption is not true if you're building with MinGW on Windows. It's really toolchain specific.

@KageKirin
Copy link
Contributor Author

I see. It's my first time using a different toolchain than MSVC on Windows (namely clang + ninja), and obviously I'm running into all those small issues.

@bkaradzic
Copy link
Owner

For clang on Windows (unless one from MSVC, not sure if that's still supported) you should use .a for libraries, because the rest of toolchain expect that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@KageKirin @bkaradzic and others