diff --git a/bazel/carbon_rules/defs.bzl b/bazel/carbon_rules/defs.bzl index a612e21d408a..2f6eaba1f891 100644 --- a/bazel/carbon_rules/defs.bzl +++ b/bazel/carbon_rules/defs.bzl @@ -5,7 +5,6 @@ """Provides rules for building Carbon files using the toolchain.""" load("@bazel_skylib//rules:run_binary.bzl", "run_binary") -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import") def carbon_binary(name, srcs): """Compiles a Carbon binary. @@ -34,14 +33,21 @@ def carbon_binary(name, srcs): srcs = srcs, outs = [out], ) - cc_import( - name = "%s.objs" % name, - objects = [src + ".compile" for src in srcs], - ) # For now, we assume that the prelude doesn't produce any necessary object # code, and don't include the .o files for //core/prelude... in the final # linked binary. # # TODO: This will need to be revisited eventually. - cc_binary(name = name, deps = ["%s.objs" % name]) + objs = [s + ".o" for s in srcs] + run_binary( + name = name + ".link", + tool = "//toolchain/driver:carbon", + args = (["link"] + + ["$(location %s)" % s for s in objs] + + ["--output=$(location %s)" % name]), + srcs = objs, + outs = [name], + # `link` has a dependency on ld, which should be in /usr/bin. + env = {"PATH": "/usr/bin"}, + )