Skip to content

Ninja Exporter MVP#2548

Closed
nickclark2016 wants to merge 5 commits intopremake:masterfrom
nickclark2016:feature/ninja-exporter
Closed

Ninja Exporter MVP#2548
nickclark2016 wants to merge 5 commits intopremake:masterfrom
nickclark2016:feature/ninja-exporter

Conversation

@nickclark2016
Copy link
Member

What does this PR do?

Implements a Ninja exporter module. Supports C and C++, as well as custom build events.

How does this PR change Premake's behavior?

No breaking changes

Anything else we should know?

Sorry in advance

Did you check all the boxes?

  • Focus on a single fix or feature; remove any unrelated formatting or code changes
  • Add unit tests showing fix or feature works; all tests pass
  • Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • Follow our coding conventions
  • Minimize the number of commits
  • Align documentation to your changes

You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!

@nickclark2016 nickclark2016 requested a review from a team November 27, 2025 03:58
@Jarod42
Copy link
Contributor

Jarod42 commented Nov 27, 2025

Setup my UTs for that one https://github.com/Jarod42/premake-sample-projects/actions/runs/19731306147/job/56532783308

It fails for following test projects:

 01-include-define-and-buildoptions Generation // FIXED
 03-prepost-build Generation
 04-defines Generation
 buildaction_copy Execution
 buildaction_none Generation
 compileas Generation
 custom-rule Generation
 customcommand Generation
 customcommand-with-buildaction-copy Generation
 dependson Generation
 entrypoint Generation // FIXED
 includedirsafter Generation
 linkgroups Generation
 pch Generation
 per-file-config Generation
 prelink Execution
 tokens Generation
 undefines Generation

KO:
03-prepost-build Generation
04-defines Generation
buildaction_copy Execution
buildaction_none Generation
compileas Generation
custom-rule Generation
customcommand Generation
customcommand-with-buildaction-copy Generation
dependson Generation
includedirsafter Generation
linkgroups Generation
pch Generation
per-file-config Generation
prelink Execution
tokens Generation
undefines Generation

In addition, the second consecutive build didn't trigger a "nothing to do" from ninja, but

[1/1] Phony target

@tritao
Copy link
Contributor

tritao commented Nov 27, 2025

Is this based on the existing https://github.com/jimon/premake-ninja or from scratch implementation?

@Jarod42
Copy link
Contributor

Jarod42 commented Nov 27, 2025

@tritao: I would say scratch implementation from the code.

return msc.tools[tool]
end


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes from this file seems unrelated to ninja

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to unify tooling fetches from Ninja

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to come from merge (conflict?) resolution.
Shown diff seems to be space/EOL change, or reordering only.

@nickclark2016
Copy link
Member Author

Is this based on the existing https://github.com/jimon/premake-ninja or from scratch implementation?

99% from scratch

@nickclark2016 nickclark2016 force-pushed the feature/ninja-exporter branch 12 times, most recently from 17000e7 to ff541b6 Compare November 30, 2025 05:24
_p("")
end

function m.prebuildcommandsrule(cfg, toolset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there reason that "rule" is singular for this one whereas most of other use plural?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an oversight here. Will fix.

@nickclark2016 nickclark2016 force-pushed the feature/ninja-exporter branch 2 times, most recently from 3773922 to fce9cc6 Compare December 1, 2025 00:13
@nickclark2016 nickclark2016 force-pushed the feature/ninja-exporter branch 3 times, most recently from 1bc1de2 to 7a9dd91 Compare December 1, 2025 04:52
_p("rule prelink")
_p(" command = $prelinkcommands")
-- Use shell wrapper based on target system's shell to ensure proper command execution
local shell = _OPTIONS.shell or iif(cfg.system == p.WINDOWS, "cmd", "posix")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above you use os.shell(), but here and below you don't?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging code. This is gonna be backed out in a future change.

---

--
-- Check that prebuild commands use cmd /c on Windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't align with the test.

---

--
-- Check that prelink commands use cmd /c on Windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

---

--
-- Check that postbuild commands use cmd /c on Windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, these tests used to do that. Missed updating the comments


-- The command should have quotes around paths
local captured = premake.captured()
test.istrue(captured:find('copy /B /Y', 1, true) ~= nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be testing what the test name and the comments suggest is being tested.

@nickclark2016 nickclark2016 force-pushed the feature/ninja-exporter branch 2 times, most recently from fce9cc6 to a73d125 Compare December 1, 2025 14:20
end
end

function m.defaultTarget(wks)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


-- The custom build should have the dependencies phony as an implicit dependency
test.capture [[
build obj/Debug/App/data.cpp: custom data.in | bin/Debug/App.dependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, you create extra file for dependencies (not sure why), should it goes in 'obj' instead of 'bin' directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good call. That should probably go in there. I can probably rework it to get rid of the file itself and use phonies here

test.capture [[
build bin/Debug/ProjectC: link obj/Debug/ProjectC/c.o | bin/Debug/ProjectA bin/Debug/ProjectB
ldflags = $ldflags_ProjectC_Debug
]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we depend on output or the phony Project_Debug which would include postbuild action?

@nickclark2016
Copy link
Member Author

Closing to fix more issues, get it in a better state before review.

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

Successfully merging this pull request may close these issues.

4 participants