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
19 changes: 19 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
load("@onedal//dev/bazel:release.bzl",
"release",
"release_include",
"release_extra_file",
)
load("@onedal//dev/bazel:scripts.bzl",
"generate_vars_sh",
"generate_pkgconfig",
)

generate_vars_sh(
name = "release_vars_sh",
out = "env/vars.sh",
)

generate_pkgconfig(
name = "release_pkgconfig",
out = "lib/pkgconfig/onedal.pc",
)

release(
Expand Down Expand Up @@ -37,4 +52,8 @@ release(
],
"//conditions:default": [],
}),
extra_files = [
release_extra_file(":release_vars_sh", "env/vars.sh"),
release_extra_file(":release_pkgconfig", "lib/pkgconfig/onedal.pc"),
],
)
23 changes: 23 additions & 0 deletions deploy/local/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#===============================================================================
# Copyright contributors to the oneDAL project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================

package(default_visibility = ["//visibility:public"])

exports_files([
"vars_lnx.sh",
"vars_mac.sh",
"vars_win.bat",
])
21 changes: 21 additions & 0 deletions deploy/pkg-config/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#===============================================================================
# Copyright contributors to the oneDAL project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================

package(default_visibility = ["//visibility:public"])

exports_files([
"pkg-config.cpp",
])
69 changes: 68 additions & 1 deletion dev/bazel/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ load("@onedal//dev/bazel:utils.bzl",
)
load("@onedal//dev/bazel/config:config.bzl",
"CpuInfo",
"VersionInfo",
)
load("@onedal//dev/bazel/cc:common.bzl",
onedal_cc_common = "common",
Expand Down Expand Up @@ -182,6 +183,19 @@ def _cc_dynamic_lib_impl(ctx):
compilation_context = onedal_cc_common.collect_and_merge_compilation_contexts(ctx.attr.deps)
linking_contexts = onedal_cc_common.collect_and_filter_linking_contexts(
ctx.attr.deps, ctx.attr.lib_tags)

# SONAME linker flags: resolved via select() in macro (_make_soname_linkopts),
# stored as a string list in soname_linkopts attr, and passed to the linker here.
# If not set by macro, falls back to empty list (no SONAME).
soname_linkopts = ctx.attr.soname_linkopts
# If lib_name is set and version info available, build SONAME from config version.
# This ensures SONAME is always in sync with @config//:version.binary_major.
if ctx.attr.lib_name and not soname_linkopts and ctx.attr._version_info:
vi = ctx.attr._version_info[VersionInfo]
if vi.binary_major:
soname = "lib{}.so.{}".format(ctx.attr.lib_name, vi.binary_major)
soname_linkopts = ["-Wl,-soname,{}".format(soname)]
Comment on lines +189 to +197
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The fallback logic on lines 191-197 will always generate a Linux-specific SONAME flag ('-Wl,-soname,...') without platform checking. This could cause build failures on Windows or macOS if the macro doesn't provide soname_linkopts. The fallback should either use the same select() pattern as the macro or be removed entirely to ensure consistent platform handling. Consider removing this fallback and requiring the macro to always set soname_linkopts (even if empty).

Suggested change
# If not set by macro, falls back to empty list (no SONAME).
soname_linkopts = ctx.attr.soname_linkopts
# If lib_name is set and version info available, build SONAME from config version.
# This ensures SONAME is always in sync with @config//:version.binary_major.
if ctx.attr.lib_name and not soname_linkopts and ctx.attr._version_info:
vi = ctx.attr._version_info[VersionInfo]
if vi.binary_major:
soname = "lib{}.so.{}".format(ctx.attr.lib_name, vi.binary_major)
soname_linkopts = ["-Wl,-soname,{}".format(soname)]
# If not set by macro, this remains empty (no SONAME flags are added here).
soname_linkopts = ctx.attr.soname_linkopts

Copilot uses AI. Check for mistakes.

linking_context, dynamic_lib = onedal_cc_link.dynamic(
owner = ctx.label,
name = ctx.attr.lib_name,
Expand All @@ -190,6 +204,7 @@ def _cc_dynamic_lib_impl(ctx):
feature_configuration = feature_config,
linking_contexts = linking_contexts,
def_file = ctx.file.def_file,
user_link_flags = soname_linkopts,
)
default_info = DefaultInfo(
files = depset([ dynamic_lib ]),
Expand All @@ -200,18 +215,70 @@ def _cc_dynamic_lib_impl(ctx):
)
return [default_info, cc_info]

cc_dynamic_lib = rule(
def _make_soname_linkopts(lib_name, binary_major):
"""Return platform-aware SONAME linker flags via select().

Must be called from a macro (not a rule impl) because select() is not
allowed inside rule implementation functions.

On Linux, embeds -Wl,-soname,lib<name>.so.<binary_major> into the link.
On Windows and macOS, returns an empty list (handled by other mechanisms).
"""
if not lib_name or not binary_major:
return []
soname = "lib{}.so.{}".format(lib_name, binary_major)
return select({
"@platforms//os:linux": ["-Wl,-soname,{}".format(soname)],
# macOS: -install_name is set by the toolchain via install_name_tool.
# Windows: DLL versioning uses PE resources, not SONAME.
"//conditions:default": [],
})

_cc_dynamic_lib = rule(
implementation = _cc_dynamic_lib_impl,
attrs = {
"lib_name": attr.string(),
"lib_tags": attr.string_list(),
"deps": attr.label_list(mandatory=True),
"def_file": attr.label(allow_single_file=True),
# Platform-resolved SONAME linker flags, set by the cc_dynamic_lib macro.
"soname_linkopts": attr.string_list(
default = [],
doc = "Linker flags for SONAME embedding. Use cc_dynamic_lib macro which sets this automatically.",
),
"_version_info": attr.label(
default = "@config//:version",
providers = [VersionInfo],
),
},
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
fragments = ["cpp"],
)

def cc_dynamic_lib(name, lib_name = "", lib_tags = [], deps = [], def_file = None,
binary_major = None, **kwargs):
"""Build a oneDAL shared library with proper SONAME embedding.

Args:
name: Bazel target name.
lib_name: Output library name (e.g. "onedal_core" → libonedal_core.so).
lib_tags: Module tags to collect from deps.
deps: Dependencies.
def_file: Optional .def file for Windows symbol export.
binary_major: Binary ABI major version for SONAME (e.g. "2").
If not set, falls back to no SONAME flag.
"""
soname_linkopts = _make_soname_linkopts(lib_name, binary_major)
_cc_dynamic_lib(
name = name,
lib_name = lib_name,
lib_tags = lib_tags,
deps = deps,
def_file = def_file,
soname_linkopts = soname_linkopts,
**kwargs
)


def _cc_exec_impl(ctx):
if not ctx.attr.deps:
Expand Down
3 changes: 2 additions & 1 deletion dev/bazel/cc/link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ def _link(owner, name, actions, cc_toolchain,

def _dynamic(owner, name, actions, cc_toolchain,
feature_configuration, linking_contexts,
def_file=None):
def_file=None, user_link_flags=[]):
unpacked_linking_context, linking_outputs = _link(
owner, name, actions, cc_toolchain,
feature_configuration, linking_contexts,
def_file,
user_link_flags = user_link_flags,
)
library_to_link = linking_outputs.library_to_link
if not (library_to_link and library_to_link.resolved_symlink_dynamic_library):
Expand Down
38 changes: 26 additions & 12 deletions dev/bazel/config/config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,25 @@ VersionInfo = provider(
"build",
"buildrev",
"status",
# Binary ABI version (distinct from product version).
# Used for SONAME and shared library symlinks.
# Matches Make's MAJORBINARY / MINORBINARY variables.
"binary_major",
"binary_minor",
],
)

def _version_info_impl(ctx):
return [
VersionInfo(
major = ctx.attr.major,
minor = ctx.attr.minor,
update = ctx.attr.update,
build = ctx.attr.build,
buildrev = ctx.attr.buildrev,
status = ctx.attr.status,
major = ctx.attr.major,
minor = ctx.attr.minor,
update = ctx.attr.update,
build = ctx.attr.build,
buildrev = ctx.attr.buildrev,
status = ctx.attr.status,
binary_major = ctx.attr.binary_major,
binary_minor = ctx.attr.binary_minor,
)
]

Expand All @@ -144,6 +151,10 @@ version_info = rule(
"build": attr.string(mandatory=True),
"buildrev": attr.string(mandatory=True),
"status": attr.string(mandatory=True),
# ABI binary version — used for SONAME and symlinks.
# Must match MAJORBINARY/MINORBINARY in makefile.
"binary_major": attr.string(mandatory=True),
"binary_minor": attr.string(mandatory=True),
},
)

Expand Down Expand Up @@ -209,12 +220,15 @@ def _declare_onedal_config_impl(repo_ctx):
Label("@onedal//dev/bazel/config:config.tpl.BUILD"),
substitutions = {
"%{auto_cpu}": auto_cpu,
"%{version_major}": "2026",
"%{version_minor}": "0",
"%{version_update}": "0",
"%{version_build}": utils.datestamp(repo_ctx),
"%{version_buildrev}": "work",
"%{version_status}": "P",
"%{version_major}": "2026",
"%{version_minor}": "0",
"%{version_update}": "0",
"%{version_build}": utils.datestamp(repo_ctx),
"%{version_buildrev}": "work",
"%{version_status}": "P",
# Binary ABI version — must match MAJORBINARY/MINORBINARY in makefile.ver
"%{version_binary_major}": "3",
"%{version_binary_minor}": "0",
},
)

Expand Down
4 changes: 4 additions & 0 deletions dev/bazel/config/config.tpl.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ version_info(
build = "%{version_build}",
buildrev = "%{version_buildrev}",
status = "%{version_status}",
# Binary ABI version for SONAME and shared library symlinks.
# Must match MAJORBINARY/MINORBINARY in makefile.
binary_major = "%{version_binary_major}",
binary_minor = "%{version_binary_minor}",
)

config_flag(
Expand Down
1 change: 1 addition & 0 deletions dev/bazel/daal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def daal_static_lib(name, lib_tags=["daal"], **kwargs):
)

def daal_dynamic_lib(name, lib_tags=["daal"], **kwargs):
"""Build a oneDAL shared library with SONAME automatically set from @config//:version."""
cc_dynamic_lib(
name = name,
lib_tags = lib_tags,
Expand Down
Loading
Loading