Nujufas
Nujufas

Reputation: 782

How can I specify the expected file extension generated by bazel cc_binary rule?

By default, the cc_binary rule of bazel produces an output file without any extension on Linux.

My compiler generates a .s19 file extension as output(I have extended the toolchain).

Is there a way to specify the output file's extension? I get a "Linking 'App-name' failed: not all outputs were created or valid" although the expected output file 'App-name.s19' is generated.

My second question is: In addition to an 'App-name.s19' file my compiler also generates a 'App-name.map' file. Is there a way to tell bazel to verify both 'App-name.s19' and 'App-name.map' files. i.e. verify multiple outputs generated by cc_binary.

Upvotes: 0

Views: 1181

Answers (1)

Fed
Fed

Reputation: 227

Question 1)

When configuring your toolchain you can load: artifact_name_pattern from @bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl and set artifact_name_patterns attribute of cc_common.create_cc_toolchain_config_info():

artifact_name_patterns = [
artifact_name_pattern(
    category_name = "executable",
    prefix = "",
    extension = ".s19",
),]

Question 2)

It seems that cc_binary doesn't support yet map files https://github.com/bazelbuild/bazel/issues/6718

A possible workaround would be to use a genrule in your BUILD file to compile your code and generate the mapfile,

genrule(
    name = "map",
    srcs = ["hello-world.cc"],
    outs = ["hello-world.exe","output.map"],
    output_to_bindir = 1,
    cmd= "/usr/bin/x86_64-w64-mingw32-gcc -o $(location hello-world.exe) $(location hello-world.cc) -Wl,-Map=\"$(location output.map)\" -lstdc++",
) 

or alternatively https://groups.google.com/g/bazel-discuss/c/A00d7Ui1f8s/m/vybgGEPIBwAJ

Upvotes: 1

Related Questions