-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
Adds a new toolset driver
flag to signal driver compatibility.
#2260
base: master
Are you sure you want to change the base?
Conversation
This allows external consumers of those toolsets to know what kind of driver the tool uses. This can be important in some cases, like in Ninja, which provides some dependency handling features that need to change depending if the compiler is GCC or MSVC-like. The problem is that due to this information, the Ninja generator ends up having hardcoded logic for this depending on the toolset, https://github.com/jimon/premake-ninja/blob/master/ninja.lua#L401. But this is not extensible to other modules that define their own toolset (like the Emscripten module).
Can you provide an example of how this is intended to be used? Based on what you have linked, it seems like the conditions would still exist but the Clang/GCC condition would reduce to a single check. That's not really a good enough improvement to me to justify this change. |
local driver
if toolset.shared and toolset.shared.driver then
driver = toolset.shared.driver
end
if toolset == p.tools.msc or driver == "msvc" then To note, I left the original checks in the Ninja module even with the changes from this PR for backwards compatibility. The main issue is that if third-party modules like the With this change, Emscripten can just do: emcc.shared = table.merge(clang.shared, {}) And the Ninja module will automatically know that its driver is GCC-compatible and be able to generate the correct code. It really has nothing to do with cleaning up code but just allowing proper extensibility. |
You could achieve pretty much the same result by changing Ninja from Having a really quick glance at the Ninja code, it seems like there's two differences between the MSVC and GCC versions. The Perhaps starting with sharing the |
Well that was one of my first solutions, but I don't think it's ideal, because it just assumes that everything that is not MSVC will be GCC-like, which may not be the case, for instance D or other languages like Zig. Or even if you provide a toolset that is based on extending This That is not just an imaginary possibility as some compilers are not GCC-driver compatible (for instance Haxe), but you still want to be able for it to be able to emit Make-style
So I've actually done that in the last few days, however unless your compilation model is C/C++ like, then the entire rules are not really applicable, just like in the
In this specific PR,
Yes, I think some further factoring here should be done, but that is a different problem and seems unrelated to the issue at hand here. As it stands, I still think the solution proposed in this PR is the best technical one, in that its quite simple (the bulk is just 3 lines) |
Then you might need to explain what the issue is because I'm not getting it from what you've said and linked. To me, it seems like the issue is that the branch conditions are too strict, you want to loosen them and I'm saying just get rid of them. How is getting rid of them not the solution? |
The main issue is if you have your own "derived" toolset, that extends one of Premake core toolsets, then external code cannot know if its based on GCC or MSVC-style driver. The solution you proposed, from what I understand, does: if toolset == p.tools.msc then
else
-- assume gcc style here
end But that assumption is not correct, as as I explained in my previous comment, has issues and can lead to broken assumptions. As far as I can tell, the only robust solution is for a toolset to define itself if its driver is based on MSVC or GCC-style flags. |
Okay, it looks like we're misunderstanding each other a bit here. The main solution I've been talking about is getting rid of both the Here's what I'm seeing: if toolset == p.tools.msc then
p.outln("CFLAGS=" .. all_cflags)
p.outln("rule cc")
p.outln(" command = " .. cc .. " $CFLAGS" .. " /nologo /showIncludes -c /Tc$in /Fo$out")
p.outln(" description = cc $out")
p.outln(" deps = msvc")
p.outln("")
-- More rules
elseif toolset == p.tools.clang or toolset == p.tools.gcc then
-- pch stuff
p.outln("CFLAGS=" .. all_cflags)
p.outln("rule cc")
p.outln(" command = " .. cc .. " $CFLAGS" .. force_include_pch .. " -x c -MF $out.d -c -o $out $in")
p.outln(" description = cc $out")
p.outln(" depfile = $out.d")
p.outln(" deps = gcc")
p.outln("")
-- More rules
end Why can't these be merged into a single path? Something like this? -- pch stuff
p.outln("CFLAGS=" .. all_cflags)
p.outln("rule cc")
p.outln(" command = " .. cc .. " $CFLAGS" .. force_include_pch .. toolset.getccinoutflags(cfg, "$in", "$out.d", "$out"))
p.outln(" description = cc $out")
p.outln(" depfile = $out.d")
p.outln(" deps = " .. ninja.getdepsname(cfg, toolset)) -- This seems like it requires knowledge of Ninja? So, it shouldn't live in the toolset.
p.outln("")
-- More rules |
This allows external consumers of those toolsets to know what kind of driver the tool uses.
This can be important in some cases, like in Ninja, which provides some dependency handling features that need to change depending if the compiler is GCC or MSVC-like.
The problem is that due to lack of this information, the Ninja generator ends up having hardcoded logic for this depending on the toolset, https://github.com/jimon/premake-ninja/blob/master/ninja.lua#L401.
Which this is not extensible to other modules that define their own toolset (like the Emscripten module).