-
Notifications
You must be signed in to change notification settings - Fork 666
[bazel] Add sugar wrappers for halsim extensions #8165
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
Open
pjreiniger
wants to merge
1
commit into
wpilibsuite:2027
Choose a base branch
from
bzlmodRio:bazel_halsim_sugar_wrapper
base: 2027
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−282
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,85 @@ | ||
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library") | ||
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library") | ||
load("//shared/bazel/rules:packaging.bzl", "package_minimal_cc_project") | ||
load("//shared/bazel/rules:publishing.bzl", "host_architectures") | ||
|
||
def wpilib_halsim_extension( | ||
name, | ||
static_init_extension_name, | ||
deps = [], | ||
dynamic_deps = [], | ||
static_deps = [], | ||
shared_additional_linker_inputs = [], | ||
shared_user_link_flags = [], | ||
**kwargs): | ||
""" | ||
Helper wrapper for creating a HALSIM extension. Provides some of the default argments for creating the library. | ||
Helper wrapper for creating a HALSIM extension. Builds the base, static, and shared libraries as well as sets up publishing | ||
This provides the following outputs: | ||
<name> - Base library | ||
<name>_static - Used to help the static library creation. Uses the same compilation args as the base library, plus defining `HALSIM_InitExtension` | ||
shared/<name> - Shared library | ||
static/<name> - Static library | ||
<name>-cpp_publish.publish - Publishing target. | ||
Params: | ||
name: Name of the base library. | ||
deps: Dependencies, used in creating the base and static base library | ||
dynamic_deps: cc_shared_libraries used for linking the shared library | ||
static_deps: cc_static_libraries used for linking the static library | ||
linkopts: Linker arguments used for creating the base library | ||
shared_additional_linker_inputs - See cc_shared_library.additional_linker_inputs | ||
shared_user_link_flags - See cc_shared_library.user_link_flags | ||
kwargs: Remaining arguments forwarded to the base and static base libraries. | ||
""" | ||
wpilib_cc_library( | ||
name = name, | ||
includes = ["src/main/native/include"], | ||
include_license_files = True, | ||
target_compatible_with = select({ | ||
"@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": ["@platforms//:incompatible"], | ||
"@rules_bzlmodrio_toolchains//constraints/is_systemcore:systemcore": ["@platforms//:incompatible"], | ||
"//conditions:default": [], | ||
}), | ||
visibility = ["//visibility:public"], | ||
deps = deps, | ||
**kwargs | ||
) | ||
|
||
wpilib_cc_library( | ||
name = "{}_static".format(name), | ||
copts = [ | ||
"-DHALSIM_InitExtension=" + static_init_extension_name, | ||
], | ||
include_license_files = True, | ||
target_compatible_with = select({ | ||
"@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": ["@platforms//:incompatible"], | ||
"@rules_bzlmodrio_toolchains//constraints/is_systemcore:systemcore": ["@platforms//:incompatible"], | ||
"//conditions:default": [], | ||
}), | ||
visibility = ["//visibility:public"], | ||
deps = deps, | ||
**kwargs | ||
) | ||
|
||
wpilib_cc_shared_library( | ||
name = "shared/{}".format(name), | ||
auto_export_windows_symbols = False, | ||
dynamic_deps = dynamic_deps, | ||
additional_linker_inputs = shared_additional_linker_inputs, | ||
user_link_flags = shared_user_link_flags, | ||
visibility = ["//visibility:public"], | ||
deps = [":{}".format(name)], | ||
) | ||
|
||
wpilib_cc_static_library( | ||
name = "static/{}".format(name), | ||
static_deps = static_deps, | ||
visibility = ["//visibility:public"], | ||
deps = [":{}_static".format(name)], | ||
) | ||
|
||
package_minimal_cc_project( | ||
name = name, | ||
architectures = host_architectures, | ||
maven_artifact_name = name, | ||
maven_group_id = "edu.wpi.first.halsim", | ||
) |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Even after reading the docstring I'm confused what the difference between
:static/foo
and:foo_static
are meant to be, given they have the same visibility.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.
Naming can probably be improved. The idea is as follows:
When you build a static extension, nothing special needs to happen. When you are building a dynamic halsim extension, you need
"-DHALSIM_InitExtension=" + static_init_extension_name,
to define some special symbols to help load the shared library. To do that, you need to build the code twice, once without the define, another time with.I bet we could mark the _static version as private.