Skip to content
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

feat: add include paths of transitive deps for Fortran rules #171

Merged
merged 1 commit into from
Apr 29, 2024
Merged
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
20 changes: 18 additions & 2 deletions rules_fortran/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _fortran_binary_impl(ctx):
objects = _compile(
actions = ctx.actions,
defines = ctx.attr.defines,
deps = ctx.attr.deps,
feature_configuration = feature_configuration,
fopts = ctx.attr.fopts,
fortran_toolchain = fortran_toolchain,
Expand Down Expand Up @@ -118,6 +119,7 @@ def _fortran_library_impl(ctx):
objects = _compile(
actions = ctx.actions,
defines = ctx.attr.defines,
deps = ctx.attr.deps,
feature_configuration = feature_configuration,
fopts = ctx.attr.fopts,
fortran_toolchain = fortran_toolchain,
Expand All @@ -140,6 +142,7 @@ def _fortran_library_impl(ctx):
),
OutputGroupInfo(
archive = depset([output]),
includes = ctx.files.includes,
),
]

Expand Down Expand Up @@ -167,6 +170,7 @@ def _get_configuration(ctx):
def _compile(
actions,
defines,
deps,
feature_configuration,
fopts,
fortran_toolchain,
Expand All @@ -178,8 +182,17 @@ def _compile(
actions.declare_file(paths.replace_extension(src.path, ".o"))
for src in srcs
]
deps_includes = []
for dep in deps:
if hasattr(dep.output_groups, "includes"):
deps_includes.append(dep.output_groups.includes)
deps_includes = depset(direct = [], transitive = deps_includes)
deps_includes_flags = [
"-I{}".format(inc.dirname)
for inc in deps_includes.to_list()
]
defines_flags = ["-D{}".format(define) for define in defines]
flags = defines_flags + compile_flags + fopts
flags = defines_flags + compile_flags + fopts + deps_includes_flags
command = """\
set -o errexit -o nounset -o pipefail

Expand All @@ -200,7 +213,10 @@ set -o errexit -o nounset -o pipefail
)
actions.run_shell(
command = command,
inputs = depset(srcs + includes),
inputs = depset(
direct = srcs + includes,
transitive = [deps_includes],
),
outputs = objects,
tools = fortran_toolchain.all_files,
)
Expand Down
Loading