-
-
Notifications
You must be signed in to change notification settings - Fork 640
Usages and Uses API #2432
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
Merged
nickclark2016
merged 1 commit into
premake:master
from
nickclark2016:feature/better-dependencies
Mar 2, 2025
Merged
Usages and Uses API #2432
nickclark2016
merged 1 commit into
premake:master
from
nickclark2016:feature/better-dependencies
Mar 2, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
redorav
reviewed
Feb 20, 2025
redorav
reviewed
Feb 20, 2025
Jarod42
reviewed
Feb 21, 2025
c619cf2 to
04943ab
Compare
Jarod42
approved these changes
Feb 21, 2025
samsinsane
requested changes
Feb 26, 2025
Member
samsinsane
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8836603 to
7fa8361
Compare
samsinsane
approved these changes
Mar 2, 2025
7fa8361 to
0b23f92
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Solved
Currently, there is no standardized way to handle exposing properties to dependent projects in Premake. Users have been required to build their own mechanisms for sharing properties or rely on third party modules, like premake-usage. This PR attempts to remedy this by providing a standardized solution to project dependency management in Premake ahead of the 5.0 stable release.
Proposed API
This PR uses the API implemented by premake-usage and extends it with CMake-like words of power. At a high level, a
usagecontainer defines a set of properties to be consumed at a later point, and ausesfield consumes a set ofusageblocks.In the current implementation, a
usagemay only be defined from within the scope of a project when no filters are active. Similarly, ausesblock may only be defined from within the scope of a project, but it may be applied while filters are active.The following is an example of two projects with the proposed API:
In the above example,
Awill only receive theA_PRIVATE_MACROdefine, asAdoes not consume theMyUsageusage. ProjectBwill only receiveA_MACRO_IN_A_USAGE, as it only consumes the usageMyUsage. Properties defined at a project level are explicitly not inherited by theusagecontaining them.CMake provides some extremely useful functionality in the form of their
PRIVATE,PUBLIC, andINTERFACEkeywords. This proposal and PR leverages these words of power in ways that match their meanings in CMake to make implemented Premake scripts based off of CMake easier.PUBLIC- A usage block with this name will be applied to both the project defining theusageand any project consuming it viauses.PRIVATE- A usage block with this name will only be applied to the project defining theusageand is inaccessible to other projects.INTERFACE- A usage block with this name will only be applied to the project consuming theusage.This slightly changes how we think of
uses, as we could have many projects defining these blocks within the same Premake build. To access these blocks, scripts should specify the project name in theuseslist.In this case,
Ahas theA_PUBLICandA_PRIVATEdefines applied to it, whileBhas theA_PUBLICandA_INTERFACEdefines applied to it.Transitive Dependencies
By default, dependencies consumed via
usesare not applied transitively. However, this is quite trivial to enforce viaPUBLICusages. By specifying ausesfield in thePUBLICusage block, the usage can be applied to dependency chains indefinitely.Other Notes
The
usesfield will not automatically applylinksanddependsonrelationships between projects. In order to enforce this, authors of projects can utilizeINTERFACEblocks to add these relationships like so:For non-magic names, the behavior of
usesis not well specified when there are multiple of the same name. There is further discussion in the Further Development section.Known Limitations and Further Development
Token expansion is an area of concern. In the current iteration of this functionality, avoiding path tokens in custom build commands within usage blocks is recommended until that behavior can be agreed upon and refined.
The primary target of further development would be to allow "usage" blocks at any scope (global, workspace, group).
There is also room for improvements with
usageresolution inuses. Currently, the behavior ofusesis not well defined if there are multipleusageblocks with the same name (excluding the names of power). To resolve this, one of the following options may be viable (these are not mutually exclusive of each other and not an exhaustive list of options):usesis appliedoperator::, to select a specificusagewhen there is ambiguity. (Example::workspace:project:usage