mayabazelmaya-api

Rename bazel output (extension) after build


I see there's a thread where this has been discussed already, but a bit vaguely:

Can I instruct bazel to emit a ".elf" suffix to executables?

Unfortunately that doesn't help in my case. I am trying to compile plugins for Autodesk Maya on windows using Bazel, so my output needs to be a .dll file with custom extension .mll. Here's an example code of how my BUILD file is setup:

cc_binary(
    name = "myPlugin.dll",  # can't rename this to .mll, otherwise bazel won't build
    srcs = glob(
        [
            "myPlugin.h",
            "myPlugin.cpp",
        ]
    ),
    deps = [
        "@maya_repo//:Foundation",
        "@maya_repo//:OpenMaya",
    ],
    linkopts = [
        "-export:initializePlugin",
        "-export:uninitializePlugin",
    ],
    linkshared = True,
)

Everything compiles, but I can't seem to find a way to rename the extension to .mll, I tried documenting on genrules but I couldn't make it work.

Could someone point me in the right direction?


Solution

  • genrule(
       name = "plugin_mll",
       srcs = ["myPlugin.dll"],
       outs = ["myPlugin.mll"],
       cmd = "cp $(location myPlugin.dll) $(location myPlugin.mll)",
    )
    

    or with the Make variables:

    genrule(
       name = "plugin_mll",
       srcs = ["myPlugin.dll"],
       outs = ["myPlugin.mll"],
       cmd = "cp $< $@",
    )
    

    and then run bazel build //path/to/package:plugin_mll to invoke the genrule, or bazel build //path/to/package:myPlugin.mll to build the file target directly.