diff --git a/.bazelrc b/.bazelrc index 0a7d286..0273ccb 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,4 @@ -import %workspace%/remote.bazelrc +# import %workspace%/remote.bazelrc test --extra_toolchains @nasm_test_toolchains//:all test --test_output=errors diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc index e69de29..ace7bcb 100644 --- a/.github/workflows/ci.bazelrc +++ b/.github/workflows/ci.bazelrc @@ -0,0 +1 @@ +import %workspace%/remote.bazelrc diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 75a76ba..8743a40 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -35,10 +35,11 @@ jobs: uname -a bazel query --output=build "@platforms//host:host" bazel mod show_extension rules_nasm//nasm:extensions.bzl%nasm - bazel test //... --google_credentials="${{ steps.auth.outputs.credentials_file_path }}" --${{ matrix.bzlmod }} + bazel --bazelrc=${GITHUB_WORKSPACE}/.github/workflows/ci.bazelrc test //... --google_credentials="${{ steps.auth.outputs.credentials_file_path }}" --${{ matrix.bzlmod }} - name: Smoke working-directory: e2e/smoke env: USE_BAZEL_VERSION: ${{ matrix.bazel_version }} - run: - bazel test //... --google_credentials="${{ steps.auth.outputs.credentials_file_path }}" --${{ matrix.bzlmod }} + run: | + ln -s ${GITHUB_WORKSPACE}/remote.bazelrc remote.bazelrc + bazel --bazelrc=${GITHUB_WORKSPACE}/.github/workflows/ci.bazelrc test //... --google_credentials="${{ steps.auth.outputs.credentials_file_path }}" --${{ matrix.bzlmod }} diff --git a/docs/README.md b/docs/README.md index 6d68039..f2ba43a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,7 +9,7 @@ Public rules definitions for nasm.
load("@rules_nasm//nasm:defs.bzl", "nasm_binary") -nasm_binary(name, src, includes, kwargs) +nasm_binary(name, src, hdrs, preincs, kwargs)@@ -21,7 +21,8 @@ nasm_binary(name, src | :------------- | :------------- | :------------- | | name |
-
| none | | src |-
| none | -| includes |-
| `None` | +| hdrs |-
| `None` | +| preincs |-
| `None` | | kwargs |-
| none | @@ -32,7 +33,7 @@ nasm_binary(name, srcload("@rules_nasm//nasm:defs.bzl", "nasm_library") -nasm_library(name, src, includes, kwargs) +nasm_library(name, src, hdrs, preincs, kwargs)Wrap nasm_library with a CC provider. @@ -49,7 +50,8 @@ corresponding provider, and captures any additional dependencies. | :------------- | :------------- | :------------- | | name |
-
| none | | src |-
| none | -| includes |-
| `None` | +| hdrs |-
| `None` | +| preincs |-
| `None` | | kwargs |-
| none | @@ -60,7 +62,7 @@ corresponding provider, and captures any additional dependencies.load("@rules_nasm//nasm:defs.bzl", "nasm_test") -nasm_test(name, src, size, includes, kwargs) +nasm_test(name, src, size, hdrs, preincs, kwargs)Assemble and execute a test assembly program. @@ -73,7 +75,8 @@ Assemble and execute a test assembly program. | name |
-
| none | | src |-
| none | | size |-
| `None` | -| includes |-
| `None` | +| hdrs |-
| `None` | +| preincs |-
| `None` | | kwargs |-
| none | diff --git a/e2e/diamond/.bazelrc b/e2e/diamond/.bazelrc index 8f53b33..e6ea3aa 100644 --- a/e2e/diamond/.bazelrc +++ b/e2e/diamond/.bazelrc @@ -1,4 +1,2 @@ -import %workspace%/../../remote.bazelrc - build --remote_cache=https://storage.googleapis.com/rules-nasm-bazel-cache test --remote_cache=https://storage.googleapis.com/rules-nasm-bazel-cache diff --git a/e2e/diamond/remote.bazelrc b/e2e/diamond/remote.bazelrc new file mode 120000 index 0000000..0225ea8 --- /dev/null +++ b/e2e/diamond/remote.bazelrc @@ -0,0 +1 @@ +/home/morgan/code/rules_nasm/remote.bazelrc \ No newline at end of file diff --git a/e2e/smoke/.bazelrc b/e2e/smoke/.bazelrc index 8f53b33..e6ea3aa 100644 --- a/e2e/smoke/.bazelrc +++ b/e2e/smoke/.bazelrc @@ -1,4 +1,2 @@ -import %workspace%/../../remote.bazelrc - build --remote_cache=https://storage.googleapis.com/rules-nasm-bazel-cache test --remote_cache=https://storage.googleapis.com/rules-nasm-bazel-cache diff --git a/nasm/private/rules/binary.bzl b/nasm/private/rules/binary.bzl index 27653ab..903f8d7 100644 --- a/nasm/private/rules/binary.bzl +++ b/nasm/private/rules/binary.bzl @@ -4,11 +4,12 @@ load(":library.bzl", "nasm_library") -def nasm_binary(name, src, includes=None, **kwargs): +def nasm_binary(name, src, hdrs=None, preincs=None, **kwargs): nasm_library( name = name + "_lib", src = src, - includes = includes, + hdrs = hdrs, + preincs = preincs, ) native.cc_binary( diff --git a/nasm/private/rules/library.bzl b/nasm/private/rules/library.bzl index 2af6a8a..2f363d4 100644 --- a/nasm/private/rules/library.bzl +++ b/nasm/private/rules/library.bzl @@ -2,12 +2,13 @@ """Rules for assembling object files.""" -# load("@rules_cc//cc:defs.bzl", "cc_library") +NASM_EXTENSIONS = [".asm", ".nasm", ".s", ".i"] def _nasm_library_impl(ctx): """Implement nasm library object.""" src = ctx.file.src - inputs = depset([src], transitive=[depset(ctx.files.includes)]) + preincs = ctx.files.preincs + inputs = depset([src] + preincs, transitive=[depset(ctx.files.hdrs)]) out = ctx.actions.declare_file(ctx.label.name + '.o') nasm_info = ctx.toolchains["//nasm:toolchain_type"] @@ -16,6 +17,7 @@ def _nasm_library_impl(ctx): args.add_all(nasm_info.args) args.add("-I", src.dirname + "/") args.add("-o", out) + args.add_all(preincs, before_each="-p") args.add(src) ctx.actions.run( mnemonic = "NasmAssemble", @@ -31,13 +33,14 @@ def _nasm_library_impl(ctx): _nasm_library_inner = rule( implementation = _nasm_library_impl, attrs = { - "src": attr.label(allow_single_file = [".asm"]), - "includes": attr.label_list(allow_files = [".asm"]), + "src": attr.label(allow_single_file = NASM_EXTENSIONS), + "hdrs": attr.label_list(allow_files = NASM_EXTENSIONS), + "preincs": attr.label_list(allow_files = NASM_EXTENSIONS), }, toolchains = ["//nasm:toolchain_type"], ) -def nasm_library(name, src, includes = None, **kwargs): +def nasm_library(name, src, hdrs=None, preincs=None, **kwargs): """Wrap nasm_library with a CC provider. Assembled object files should be usable as C compilation units. @@ -48,7 +51,8 @@ def nasm_library(name, src, includes = None, **kwargs): _nasm_library_inner( name = "%s_asm"%name, src = src, - includes = includes, + hdrs = hdrs, + preincs = preincs, ) native.cc_library( diff --git a/nasm/private/rules/test.bzl b/nasm/private/rules/test.bzl index d6eab17..1b86d18 100644 --- a/nasm/private/rules/test.bzl +++ b/nasm/private/rules/test.bzl @@ -4,13 +4,14 @@ load(":library.bzl", "nasm_library") -def nasm_test(name, src, size=None, includes=None, **kwargs): +def nasm_test(name, src, size=None, hdrs=None, preincs=None, **kwargs): """Assemble and execute a test assembly program.""" nasm_library( name = name + "_lib", src = src, - includes = includes, + hdrs = hdrs, + preincs = preincs, ) native.cc_test( diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index 424a7c2..8881424 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -56,7 +56,16 @@ nasm_test( name = "includes_test", size = "small", src = "includes_main.asm", - includes = [ + hdrs = [ "includes_inc.asm", ], ) + +nasm_test( + name = "preincludes_test", + size = "small", + src = "preincs_main.asm", + preincs = [ + "includes_inc.asm" + ], +) diff --git a/tests/preincs_main.asm b/tests/preincs_main.asm new file mode 100644 index 0000000..933cb44 --- /dev/null +++ b/tests/preincs_main.asm @@ -0,0 +1,23 @@ +; Copyright (c) 2024 Morgan Wajda-Levie. +; +; Reference a macro that is not defined in this file or any included +; file. +BITS 64 + +%ifidn __OUTPUT_FORMAT__, macho64 + %define MAIN _main +%else + %define MAIN main +%endif + +global MAIN + +section .text +MAIN: + xor rax, rax + MYAD rdx, 4, 1 + cmp rdx, 5 + je equal + mov rax, 1 +equal: + ret