Skip to content
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ jobs:
- name: CPU Info
run: |
lscpu || true
- run: bazel test //...
# Test twice, once with path stripping + path mapping, and once without
- run: |
bazel test //...
bazel test --experimental_output_paths=strip //...
5 changes: 4 additions & 1 deletion mojo/mojo_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ load("//mojo/private:utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo", "format_
def _format_include(arg):
return ["-I", arg.dirname]

def _format_root(arg):
return arg.dirname

def _mojo_library_implementation(ctx):
mojo_toolchain = ctx.toolchains["//:toolchain_type"].mojo_toolchain_info
build_env = getattr(ctx.toolchains["//:toolchain_type"], "build_env", {})
Expand Down Expand Up @@ -43,7 +46,7 @@ def _mojo_library_implementation(ctx):
args.add("--experimental-export-fixit", fixits_file)

file_args.add_all(import_paths, map_each = format_import)
file_args.add(root_directory)
file_args.add_all([ctx.files.srcs[0]], map_each = _format_root)
ctx.actions.run(
executable = mojo_toolchain.mojo,
inputs = depset(ctx.files.srcs + ctx.files.additional_compiler_inputs, transitive = [transitive_mojodeps]),
Expand Down
37 changes: 37 additions & 0 deletions tests/generated/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Regression test to ensure mojo_library and mojo_binary targets work with generated sources

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//mojo:mojo_binary.bzl", "mojo_binary")
load("//mojo:mojo_library.bzl", "mojo_library")

genrule(
name = "srcs",
outs = [
"__init__.mojo",
"main.mojo",
],
cmd = """cat << 'EOF' > $(location main.mojo)
def main():
pass
EOF
touch $(location __init__.mojo)
""",
)

mojo_library(
name = "lib",
srcs = [":__init__.mojo"],
)

mojo_binary(
name = "bin",
srcs = [":main.mojo"],
)

build_test(
name = "build_targets",
targets = [
":lib",
":bin",
],
)
Loading