Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 69 additions & 3 deletions shared/bazel/rules/halsim_library.bzl
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),
Copy link
Member

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.

Copy link
Contributor

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.

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",
)
62 changes: 8 additions & 54 deletions simulation/halsim_ds_socket/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,70 +1,30 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
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:halsim_library.bzl", "wpilib_halsim_extension")

cc_library(
name = "headers",
hdrs = glob(["src/main/native/include/**"]),
includes = ["src/main/native/include"],
)

wpilib_cc_library(
wpilib_halsim_extension(
name = "halsim_ds_socket",
srcs = glob(["src/main/native/cpp/**"]),
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 = [
":headers",
"//hal:wpiHal",
"//wpinet",
],
)

wpilib_cc_library(
name = "halsim_ds_socket_static",
srcs = glob(["src/main/native/cpp/**"]),
copts = [
"-DHALSIM_InitExtension=HALSIM_InitExtension_DS_SOCKET",
],
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 = [
":headers",
"//hal:wpiHal",
"//wpinet",
],
)

wpilib_cc_shared_library(
name = "shared/halsim_ds_socket",
auto_export_windows_symbols = False,
dynamic_deps = [
"//hal:shared/wpiHal",
"//wpinet:shared/wpinet",
"//wpiutil:shared/wpiutil",
],
visibility = ["//visibility:public"],
deps = [":halsim_ds_socket"],
)

wpilib_cc_static_library(
name = "static/halsim_ds_socket",
static_deps = [
"//hal:static/wpiHal",
"//wpinet:static/wpinet",
],
visibility = ["//visibility:public"],
deps = [":halsim_ds_socket_static"],
static_init_extension_name = "HALSIM_InitExtension_DS_SOCKET",
deps = [
":headers",
"//hal:wpiHal",
"//wpinet",
],
)

cc_test(
Expand All @@ -84,9 +44,3 @@ cc_binary(
":halsim_ds_socket",
],
)

package_minimal_cc_project(
name = "halsim_ds_socket",
maven_artifact_name = "halsim_ds_socket",
maven_group_id = "edu.wpi.first.halsim",
)
90 changes: 17 additions & 73 deletions simulation/halsim_gui/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,79 +1,33 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
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:halsim_library.bzl", "wpilib_halsim_extension")

wpilib_cc_library(
wpilib_halsim_extension(
name = "halsim_gui",
srcs = glob([
"src/main/native/cpp/*",
"src/main/native/include/*.h",
]),
include_license_files = True,
includes = ["src/main/native/include"],
linkopts = [
"-lm",
],
tags = [
"wpi-cpp-gui",
],
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 = [
"//glass:glassnt",
"//hal:wpiHal",
],
)

wpilib_cc_library(
name = "halsim_gui_static",
srcs = glob([
"src/main/native/cpp/*",
"src/main/native/include/*.h",
]),
copts = [
"-DHALSIM_InitExtension=HALSIM_InitExtension_GUI",
dynamic_deps = [
"//hal:shared/wpiHal",
"//wpimath:shared/wpimath",
"//datalog:shared/datalog",
"//ntcore:shared/ntcore",
],
include_license_files = True,
includes = ["src/main/native/include"],
linkopts = [
"-lm",
],
tags = [
"wpi-cpp-gui",
],
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 = [
"//glass:glassnt",
"//hal:wpiHal",
],
)

wpilib_cc_shared_library(
name = "shared/halsim_gui",
additional_linker_inputs = select({
# https://github.com/bazelbuild/bazel/issues/21893
shared_additional_linker_inputs = select({
"@platforms//os:osx": [
"//thirdparty/imgui_suite:glfw_src_darwin",
"//thirdparty/imgui_suite:imgui_src_darwin",
"//wpigui:wpigui-mac",
],
"//conditions:default": [],
}),
dynamic_deps = [
"//hal:shared/wpiHal",
"//wpimath:shared/wpimath",
"//datalog:shared/datalog",
"//ntcore:shared/ntcore",
],
user_link_flags = select({
# https://github.com/bazelbuild/bazel/issues/21893
shared_user_link_flags = select({
"@platforms//os:osx": [
"-Wl,-force_load,$(location //thirdparty/imgui_suite:glfw_src_darwin)",
"-Wl,-force_load,$(location //thirdparty/imgui_suite:imgui_src_darwin)",
Expand All @@ -95,24 +49,20 @@ wpilib_cc_shared_library(
],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
deps = [
":halsim_gui",
],
)

wpilib_cc_static_library(
name = "static/halsim_gui",
static_deps = [
"//hal:static/wpiHal",
"//wpimath:static/wpimath",
"//datalog:static/datalog",
"//ntcore:static/ntcore",
"//glass:static/glassnt",
],
visibility = ["//visibility:public"],
static_init_extension_name = "HALSIM_InitExtension_GUI",
tags = [
"wpi-cpp-gui",
],
deps = [
":halsim_gui_static",
"//glass:glassnt",
"//hal:wpiHal",
],
)

Expand Down Expand Up @@ -140,9 +90,3 @@ cc_binary(
":halsim_gui",
],
)

package_minimal_cc_project(
name = "halsim_gui",
maven_artifact_name = "halsim_gui",
maven_group_id = "edu.wpi.first.halsim",
)
42 changes: 3 additions & 39 deletions simulation/halsim_ws_client/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,57 +1,27 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_shared_library", "wpilib_cc_static_library")
load("//shared/bazel/rules:halsim_library.bzl", "wpilib_halsim_extension")
load("//shared/bazel/rules:packaging.bzl", "package_minimal_cc_project")

wpilib_halsim_extension(
name = "halsim_ws_client",
srcs = glob([
"src/main/native/cpp/*.cpp",
"src/main/native/include/*.h",
]),
deps = [
"//simulation/halsim_ws_core",
],
)

wpilib_halsim_extension(
name = "halsim_ws_client_static",
srcs = glob([
"src/main/native/cpp/*.cpp",
"src/main/native/include/*.h",
]),
copts = [
"-DHALSIM_InitExtension=HALSIM_InitExtension_WS_CLIENT",
],
deps = [
"//simulation/halsim_ws_core",
],
)

wpilib_cc_shared_library(
name = "shared/halsim_ws_client",
dynamic_deps = [
"//hal:shared/wpiHal",
"//wpinet:shared/wpinet",
"//wpiutil:shared/wpiutil",
],
visibility = ["//visibility:public"],
deps = [
":halsim_ws_client",
],
)

wpilib_cc_static_library(
name = "static/halsim_ws_client",
includes = ["src/main/native/include"],
static_deps = [
"//hal:static/wpiHal",
"//wpinet:static/wpinet",
"//wpiutil:static/wpiutil",
"//simulation/halsim_ws_core:static/halsim_ws_core",
],
visibility = ["//visibility:public"],
static_init_extension_name = "HALSIM_InitExtension_WS_CLIENT",
deps = [
":halsim_ws_client_static",
"//simulation/halsim_ws_core",
],
)

Expand All @@ -62,9 +32,3 @@ cc_binary(
":halsim_ws_client",
],
)

package_minimal_cc_project(
name = "halsim_ws_client",
maven_artifact_name = "halsim_ws_client",
maven_group_id = "edu.wpi.first.halsim",
)
Loading
Loading