Use the driver to link. (#3987)

Rather than cc_binary, try using link from #3922
This commit is contained in:
Jon Ross-Perkins
2024-05-24 22:00:11 +00:00
committed by GitHub
parent 74469aaa23
commit 534b737871
+12 -6
View File
@@ -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"},
)