Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolchain config Windows #16247

Open
Josar opened this issue Sep 10, 2022 · 5 comments
Open

Toolchain config Windows #16247

Josar opened this issue Sep 10, 2022 · 5 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)

Comments

@Josar
Copy link

Josar commented Sep 10, 2022

Description of the bug:

I try to get MinGw to work on Windows.
I try to use the local installed MinGw and configure it as toolchain. This is only the first step to understand how an embedded toolchain could be set up. But i fail when triyng to follow this tutorial and try to adapt it.

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load(
    "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
    "feature",
    "flag_group",
    "flag_set",
    "tool_path",
    "action_config",
    "tool",
)

all_link_actions = [
    ACTION_NAMES.cpp_link_executable,
    ACTION_NAMES.cpp_link_dynamic_library,
    ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]

def _impl(ctx):
    tool_paths = [
        tool_path(
            name = "gcc",
            path = "false",
            #path = "C:\\MinGW\\bin\\gcc.exe", # Error 1
            #path = "C:/MinGW/bin/gcc.exe", # Error 2
        ),
        tool_path(
            name = "ld",
            path = "false",
            #path = "C:\\MinGW\\bin\\ld.exe",  # Error 1
            #path = "C:/MinGW/bin/ld.exe",  # Error 2
        ),
        tool_path(
            name = "ar",
            path = "false",
        ),
        tool_path(
            name = "cpp",
            path = "false",
        ),
        tool_path(
            name = "gcov",
            path = "false",
        ),
        tool_path(
            name = "nm",
            path = "false",
        ),
        tool_path(
            name = "objdump",
            path = "false",
        ),
        tool_path(
            name = "strip",
            path = "false",
        ),
    ]

    features = [
        feature(
            name = "default_linker_flags",
            enabled = True,
            flag_sets = [
                flag_set(
                    actions = all_link_actions,
                    flag_groups = ([
                        flag_group(
                            flags = [
                                "-lstdc++",
                            ],
                        ),
                    ]),
                ),
            ],
        ),
    ]

    action_configs = [
        action_config (
            action_name = ACTION_NAMES.c_compile,
            tools = [
                # NEW label type tool field introduced in #10967
                tool(
                    # tool = ctx.executable.my_ld),
                    path = "C:\\MinGW\\bin\\gcc.exe" 
                )
            ],
        ),
        action_config (
            action_name = ACTION_NAMES.cpp_link_executable,
            tools = [
                # NEW label type tool field introduced in #10967
                tool(
                    # tool = ctx.executable.my_ld,
                    path = "C:\\MinGW\\bin\\ld.exe"
                )
            ],
        ),
    ]

    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        features = features, # NEW
        cxx_builtin_include_directories = [
            "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include",
            "C:\\MinGW\\include",
        ],
        toolchain_identifier = "local",
        host_system_name = "local",
        target_system_name = "local",
        target_cpu = "k8",
        target_libc = "unknown",
        compiler = "mingw",
        abi_version = "unknown",
        abi_libc_version = "unknown",
        tool_paths = tool_paths,
        action_configs = action_configs,
    )

cc_toolchain_config = rule(
    implementation = _impl,
    attrs = {},
    provides = [CcToolchainConfigInfo],
)

Trying to change the path to #Error 2

D:\BazelBuild\examples\cpp-tutorial\stage1>bazelisk build --config=mingw_config --cpu=x86 //main:hello-world
Starting local Bazel server and connecting to it...
INFO: Analyzed target //main:hello-world (38 packages loaded, 162 targets configured).
INFO: Found 1 target...
ERROR: D:/bazelbuild/examples/cpp-tutorial/stage1/main/BUILD:3:10: Compiling main/hello-world.cc failed: missing input file '//toolchain:empty'
ERROR: D:/bazelbuild/examples/cpp-tutorial/stage1/main/BUILD:3:10: Compiling main/hello-world.cc failed: 1 input file(s) do not exist
Target //main:hello-world failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: D:/bazelbuild/examples/cpp-tutorial/stage1/main/BUILD:3:10 Compiling main/hello-world.cc failed: 1 input file(s) do not exist
INFO: Elapsed time: 2.897s, Critical Path: 0.03s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

when i try to provide the path to the tool_path.path i get # error 1.

D:\BazelBuild\examples\cpp-tutorial\stage1>bazel build --config=mingw_config //main:hello-world
Analyzing: target //main:hello-world (0 packages loaded, 0 targets configured)
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ConfiguredTargetKey{label=//toolchain:x86_toolchain_config, config=BuildConfigurationValue.Key[02e79dd9de174d25399e85bf1b0833ded09d49738442a403231bf1994cd72e28]}' (requested by nodes 'ConfiguredTargetKey{label=//toolchain:x86_toolchain, config=BuildConfigurationValue.Key[02e79dd9de174d25399e85bf1b0833ded09d49738442a403231bf1994cd72e28]}')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:674)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:382)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: net.starlark.java.eval.Starlark$UncheckedEvalException: IllegalStateException thrown during Starlark evaluation (//toolchain:x86_toolchain_config)
        at <starlark>.create_cc_toolchain_config_info(<builtin>:0)
        at <starlark>._impl(D:/bazelbuild/examples/cpp-tutorial/stage1/toolchain/cc_toolchain_config.bzl:73)
Caused by: java.lang.IllegalStateException: com.google.protobuf.TextFormat$ParseException: 4:16: Invalid escape sequence: '\M'
        at com.google.devtools.build.lib.rules.cpp.CppActionConfigs.getLegacyActionConfigs(CppActionConfigs.java:1372)
        at com.google.devtools.build.lib.rules.cpp.CcModule.ccToolchainConfigInfoFromStarlark(CcModule.java:1250)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at net.starlark.java.eval.MethodDescriptor.call(MethodDescriptor.java:162)
        at net.starlark.java.eval.BuiltinFunction.fastcall(BuiltinFunction.java:77)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:619)
        at net.starlark.java.eval.Eval.evalCall(Eval.java:672)
        at net.starlark.java.eval.Eval.eval(Eval.java:489)
        at net.starlark.java.eval.Eval.execReturn(Eval.java:249)
        at net.starlark.java.eval.Eval.exec(Eval.java:288)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
        at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:66)
        at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:191)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:619)
        at com.google.devtools.build.lib.analysis.starlark.StarlarkRuleConfiguredTargetUtil.buildRule(StarlarkRuleConfiguredTargetUtil.java:99)
        at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:353)
...

When i try to provide it by the actions i get this.

D:\BazelBuild\examples\cpp-tutorial\stage1_toolchain_1>bazelisk build --config=asmjs //main:hello-world
Starting local Bazel server and connecting to it...
INFO: Analyzed target //main:hello-world (38 packages loaded, 162 targets configured).
INFO: Found 1 target...
ERROR: D:/bazelbuild/examples/cpp-tutorial/stage1_toolchain_1/main/BUILD:3:10: Compiling main/hello-world.cc failed: missing input file '//toolchain:empty'
ERROR: D:/bazelbuild/examples/cpp-tutorial/stage1_toolchain_1/main/BUILD:3:10: Compiling main/hello-world.cc failed: 1 input file(s) do not exist
Target //main:hello-world failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: D:/bazelbuild/examples/cpp-tutorial/stage1_toolchain_1/main/BUILD:3:10 Compiling main/hello-world.cc failed: 1 input file(s) do not exist
INFO: Elapsed time: 3.749s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
FAILED: Build did NOT complete successfully

What went wrong?
If you could point my to the right direction it would be great.

A second questions would be, is there any tutorial thats shows how to use local installed tools/exe, without wrapping it in a script?

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which operating system are you running Bazel on?

Windows 11

What is the output of bazel info release?

release 5.3.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

My own question. https://stackoverflow.com/questions/73614004/use-local-mingw-as-toolchain-on-windows

Any other information, logs, or outputs that you want to share?

No response

@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) type: support / not a bug (process) and removed type: bug untriaged labels Oct 26, 2022
@crillion
Copy link

crillion commented Oct 27, 2022

I have had this problem on windows. I experienced the crash too. it seems that bazel interprets the backslashes as escape characters. by converting them to normal slashes (as in the unix/linux platform) it works... and it give to me other errors (but at least that problem is passed). Maybe the bazel developers will fix this sooner or later...

@chickenandpork
Copy link

chickenandpork commented Nov 7, 2022

missing input file '//toolchain:empty'

This seems to be a default value added to something after the tutorial was written.

I created a blank file "toolchain/empty" and it seems to satisfy.

@Josar
Copy link
Author

Josar commented Apr 12, 2023

BUILD

filegroup(name = "empty")

This seems to expect a file named empty. So adding a blank file to the folder of the BUILD file solves that. Thanks @chickenandpork.

Or declaring the srcs with an empty array also solves this.

filegroup(
    name = "empty",
    srcs = [],
)

@Fasten90
Copy link

missing input file '//toolchain:empty'

This seems to be a default value added to something after the tutorial was written.

I created a bank file "toolchain/empty" and it seems to satisfy.

In this case this ticket is a similar topic to the
#12856

Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added stale Issues or PRs that are stale (no activity for 30 days) and removed stale Issues or PRs that are stale (no activity for 30 days) labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)
Projects
None yet
Development

No branches or pull requests

6 participants