Przeglądaj źródła

Use the driver to link. (#3987)

Rather than cc_binary, try using link from #3922
Jon Ross-Perkins 1 rok temu
rodzic
commit
534b737871
1 zmienionych plików z 12 dodań i 6 usunięć
  1. 12 6
      bazel/carbon_rules/defs.bzl

+ 12 - 6
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"},
+    )