diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-03-08 17:24:49 +0200 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-03-08 22:00:07 +0200 |
commit | 20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec (patch) | |
tree | 473281e5fc8b256827ce1a678573444e1aa5f669 /tools | |
parent | Generate src/conf.h (diff) | |
download | kernel-20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec.tar.xz |
Bazel build
Diffstat (limited to 'tools')
-rw-r--r-- | tools/BUILD.bazel | 6 | ||||
-rw-r--r-- | tools/configure_file.bzl | 29 | ||||
-rw-r--r-- | tools/make_iso.bzl | 41 | ||||
-rw-r--r-- | tools/qemu.bzl | 33 |
4 files changed, 109 insertions, 0 deletions
diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel new file mode 100644 index 0000000..fddb974 --- /dev/null +++ b/tools/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["//visibility:public"]) + +py_binary( + name = "make_iso", + srcs = ["make_iso.py"], +) diff --git a/tools/configure_file.bzl b/tools/configure_file.bzl new file mode 100644 index 0000000..8fdd75c --- /dev/null +++ b/tools/configure_file.bzl @@ -0,0 +1,29 @@ +load("//:project_config.bzl", "version") +load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain") + +def configure_file(**kwargs): + _configure_file( + source_file = "{name}.h".format(**kwargs), + **kwargs + ) + +def _configure_file_impl(ctx): + cc_toolchain = find_cc_toolchain(ctx) + + ctx.actions.expand_template( + template = ctx.file.template, + output = ctx.outputs.source_file, + substitutions = { + "{VERSION}": '"{}"'.format(version()), + "{CC}": '"{} " __VERSION__'.format(cc_toolchain.compiler), + }, + ) + +_configure_file = rule( + attrs = { + "template": attr.label(allow_single_file = True), + "source_file": attr.output(mandatory = True), + }, + toolchains = use_cc_toolchain(), + implementation = _configure_file_impl, +) diff --git a/tools/make_iso.bzl b/tools/make_iso.bzl new file mode 100644 index 0000000..5ff20f5 --- /dev/null +++ b/tools/make_iso.bzl @@ -0,0 +1,41 @@ +def make_iso(**kwargs): + _make_iso( + image = "{name}.iso".format(**kwargs), + **kwargs + ) + +def _make_iso_impl(ctx): + inputs = [] + outputs = [] + args = ctx.actions.args() + + args.add("-c", ctx.file.bootloader.path) + inputs.append(ctx.file.bootloader) + args.add("-k", ctx.file.kernel.path) + inputs.append(ctx.file.kernel) + + args.add("-o", ctx.outputs.image.path) + outputs.append(ctx.outputs.image) + + ctx.actions.run( + inputs = inputs, + outputs = outputs, + arguments = [args], + executable = ctx.executable._generator, + progress_message = "Generating ISO image %s" % ctx.label.name, + ) + +_make_iso = rule( + attrs = { + "bootloader": attr.label(allow_single_file = True), + "kernel": attr.label(allow_single_file = True), + "image": attr.output(), + "_generator": attr.label( + default = Label(":make_iso"), + executable = True, + allow_files = True, + cfg = "exec", + ), + }, + implementation = _make_iso_impl, +) diff --git a/tools/qemu.bzl b/tools/qemu.bzl new file mode 100644 index 0000000..9493306 --- /dev/null +++ b/tools/qemu.bzl @@ -0,0 +1,33 @@ +load("//toolchains:i386_qemu.bzl", qemu_i386 = "qemu_wrapper") + +def qemu(**kwargs): + _qemu( + wrapper_content = select({ + "@platforms//cpu:i386": qemu_i386(), + "//conditions:default": "/bin/false", + }), + **kwargs + ) + +def _qemu_impl(ctx): + print(ctx) + print(ctx.attr) + + wrapper = ctx.actions.declare_file("%s_wrapper" % ctx.label.name) + wrapper_content = ctx.attr.wrapper_content.format( + cdrom = ctx.file.cdrom.basename, + ) + ctx.actions.write(wrapper, wrapper_content, is_executable = True) + + runfiles = ctx.runfiles(files = [ctx.file.cdrom]) + + return [DefaultInfo(executable = wrapper, runfiles = runfiles)] + +_qemu = rule( + implementation = _qemu_impl, + attrs = { + "cdrom": attr.label(allow_single_file = True), + "wrapper_content": attr.string(), + }, + executable = True, +) |