Skip to content

Commit

Permalink
revert most
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Sep 24, 2024
1 parent a98f2d5 commit be30658
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 685 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ common --noincompatible_disallow_empty_glob

# Don't try and auto detect the cc toolchain, as we use our own gcc toolchains.
common:linux --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
common:windows --platforms @zig_sdk//platform:windows_amd64 --extra_toolchains @zig_sdk//toolchain:windows_amd64
common:windows --sandbox_add_mount_pair=C:\Temp
common --incompatible_enable_proto_toolchain_resolution

build:windows --sandbox_add_mount_pair=C:\Temp

# Tell Bazel to pass the right flags for llvm-ar, not libtool, only needed on linux.
# See https://github.com/bazelbuild/bazel/blob/5c75d0acec21459bbb13520817e3806e1507e907/tools/cpp/unix_cc_toolchain_config.bzl#L1000-L1024
# TODO: maybe drop once we upgrade llvm toolchain, https://github.com/bazel-contrib/toolchains_llvm/pull/229
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ jobs:
- uses: actions/checkout@v4
# Bootstrap: the first time we release for windows, we don't have a windows version of Aspect CLI to build with
# So use environment variables to defeat the .bazeliskrc file.
- run: bazel build @com_github_smacker_go_tree_sitter//python
- run: bazel build //:for_all_platforms
- run: bazel build //release:aspect_windows_amd64
- run: cp bazel-out/x64_windows-fastbuild-ST-2c60814c3ef7/bin/cmd/aspect/aspect_/aspect.exe aspect_windows_amd64.exe
- name: smoke test
run: ./aspect_windows_amd64.exe --help
Expand Down
24 changes: 0 additions & 24 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
Expand Down Expand Up @@ -124,26 +123,3 @@ alias(
name = "format",
actual = "//tools:format",
)


PLATFORMS = [
# "@zig_sdk//platform:darwin_amd64",
# "@zig_sdk//platform:darwin_arm64",
# "@zig_sdk//libc_aware/platform:linux_arm64_musl",
# "@zig_sdk//libc_aware/platform:linux_amd64_musl",
"@toolchains_llvm//platforms:windows-x86_64",
]

[
platform_transition_filegroup(
name = "for_" + platform.split(":")[1],
srcs = ["//cmd/aspect"],
target_platform = platform,
)
for platform in PLATFORMS
]

filegroup(
name = "for_all_platforms",
srcs = ["for_" + platform.split(":")[1] for platform in PLATFORMS],
)
65 changes: 38 additions & 27 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,15 @@ load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains"

zig_toolchains()

http_archive(
name = "toolchains_llvm",
sha256 = "c304fc9286c6fa2acb6dcea8961dc0d526a076f8cb64da4763c36aebcf5cff56",
strip_prefix = "toolchains_llvm-v1.1.2",
canonical_id = "v1.1.2",
url = "https://github.com/bazel-contrib/toolchains_llvm/releases/download/v1.1.2/toolchains_llvm-v1.1.2.tar.gz",
patches = ["//patches:llvm+windows.patch"],
patch_args = ["-p1"]
)

load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")

bazel_toolchain_dependencies()

load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")

llvm_toolchain(
name = "llvm_toolchain",
llvm_versions = {
"": "15.0.7",
"windows-x86_64": "18.1.1"
}
register_toolchains(
"@zig_sdk//toolchain:linux_amd64_musl",
"@zig_sdk//toolchain:linux_arm64_musl",
# "@zig_sdk//toolchain:darwin_amd64",
# "@zig_sdk//toolchain:darwin_arm64",
# "@zig_sdk//toolchain:windows_amd64",
# "@zig_sdk//toolchain:windows_arm64",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")

llvm_register_toolchains()


http_archive(
name = "bazel_features",
sha256 = "2cd9e57d4c38675d321731d65c15258f3a66438ad531ae09cb8bb14217dc8572",
Expand Down Expand Up @@ -127,6 +107,36 @@ filegroup(
)
"""


load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")

llvm_toolchain(
name = "llvm_toolchain",
llvm_version = "14.0.0",
sha256 = {
"darwin-aarch64": "1b8975db6b638b308c1ee437291f44cf8f67a2fb926eb2e6464efd180e843368",
"linux-x86_64": "564fcbd79c991e93fdf75f262fa7ac6553ec1dd04622f5d7db2a764c5dc7fac6",
},
strip_prefix = {
"darwin-aarch64": "clang+llvm-14.0.0-arm64-apple-darwin",
"linux-x86_64": "clang+llvm-14.0.0-x86_64-linux-gnu",
},
sysroot = {
"darwin-aarch64": "@sysroot_darwin_universal//:sysroot",
"darwin-x86_64": "@sysroot_darwin_universal//:sysroot",
"linux-aarch64": "@org_chromium_sysroot_linux_arm64//:sysroot",
"linux-x86_64": "@org_chromium_sysroot_linux_x86_64//:sysroot",
},
urls = {
"darwin-aarch64": ["https://github.com/aspect-forks/llvm-project/releases/download/aspect-release-14.0.0/clang+llvm-14.0.0-arm64-apple-darwin.tar.xz"],
"linux-x86_64": ["https://github.com/aspect-forks/llvm-project/releases/download/aspect-release-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu.tar.xz"],
},
)

load("//platforms/toolchains:defs.bzl", "register_llvm_toolchains")

register_llvm_toolchains()

http_archive(
name = "org_chromium_sysroot_linux_arm64",
build_file_content = _SYSROOT_LINUX_BUILD_FILE,
Expand All @@ -151,6 +161,7 @@ http_archive(
urls = ["https://s3.us-east-2.amazonaws.com/static.aspect.build/sysroots/MacOSX11.3.sdk.tar.xz"],
)


http_archive(
name = "io_bazel_rules_go",
sha256 = "67b4d1f517ba73e0a92eb2f57d821f2ddc21f5bc2bd7a231573f11bd8758192e",
Expand Down
36 changes: 36 additions & 0 deletions patches/com_grail_bazel_toolchain.001.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/toolchain/BUILD.llvm_repo b/toolchain/BUILD.llvm_repo
index a09616e..95f9280 100644
--- a/toolchain/BUILD.llvm_repo
+++ b/toolchain/BUILD.llvm_repo
@@ -19,7 +19,7 @@ exports_files(glob([
"bin/*",
"lib/*",
"include/*",
-]))
+], allow_empty = True))

## LLVM toolchain files

@@ -45,12 +45,12 @@ filegroup(
srcs = glob([
"include/**/c++/**",
"lib/clang/*/include/**",
- ]),
+ ], allow_empty = True),
)

filegroup(
name = "bin",
- srcs = glob(["bin/**"]),
+ srcs = glob(["bin/**"], allow_empty = True),
)

filegroup(
@@ -67,6 +67,7 @@ filegroup(
"lib/libclang*.a",
"lib/liblld*.a",
],
+ allow_empty = True,
),
# Do not include the .dylib files in the linker sandbox because they will
# not be available at runtime. Any library linked from the toolchain should
183 changes: 183 additions & 0 deletions patches/com_grail_bazel_toolchain.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
diff --git a/toolchain/BUILD.llvm_repo b/toolchain/BUILD.llvm_repo
index 94a1a98..a09616e 100644
--- a/toolchain/BUILD.llvm_repo
+++ b/toolchain/BUILD.llvm_repo
@@ -36,6 +36,7 @@ filegroup(
name = "ld",
srcs = [
"bin/ld.lld",
+ "bin/ld64.lld",
],
)

diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl
index da1e330..dc0da9f 100644
--- a/toolchain/cc_toolchain_config.bzl
+++ b/toolchain/cc_toolchain_config.bzl
@@ -112,8 +112,6 @@ def cc_toolchain_config(
"-fdebug-prefix-map={}=__bazel_toolchain_llvm_repo__/".format(toolchain_path_prefix),
]

- is_xcompile = not (host_os == target_os and host_arch == target_arch)
-
# Default compiler flags:
compile_flags = [
"--target=" + target_system_name,
@@ -149,12 +147,17 @@ def cc_toolchain_config(
# unused symbols are not stripped.
link_libs = []

+ use_lld = True
+
# Linker flags:
- if host_os == "darwin" and not is_xcompile:
- # lld is experimental for Mach-O, so we use the native ld64 linker.
- # TODO: How do we cross-compile from Linux to Darwin?
- use_lld = False
+ if target_os == "darwin":
+ ld = "ld64.lld"
+ ld_path = toolchain_path_prefix + "/bin/" + ld
+ compile_flags.append("-mmacosx-version-min=12.0")
link_flags.extend([
+ "-mmacosx-version-min=12.0",
+ "-Wl,-platform_version,macos,12.0,12.0",
+ "--ld-path=" + ld_path,
"-headerpad_max_install_names",
# This will issue a warning on macOS ventura; see:
# https://github.com/python/cpython/issues/97524
@@ -163,98 +166,19 @@ def cc_toolchain_config(
"dynamic_lookup",
])
else:
- # Note that for xcompiling from darwin to linux, the native ld64 is
- # not an option because it is not a cross-linker, so lld is the
- # only option.
- use_lld = True
+ ld = "ld.lld"
+ ld_path = toolchain_path_prefix + "/bin/" + ld
link_flags.extend([
- "-fuse-ld=lld",
+ "--ld-path=" + ld_path,
"-Wl,--build-id=md5",
"-Wl,--hash-style=gnu",
"-Wl,-z,relro,-z,now",
])

- # Flags related to C++ standard.
- # The linker has no way of knowing if there are C++ objects; so we
- # always link C++ libraries.
- cxx_standard = compiler_configuration["cxx_standard"]
- stdlib = compiler_configuration["stdlib"]
- if stdlib == "builtin-libc++" and is_xcompile:
- stdlib = "stdc++"
- if stdlib == "builtin-libc++":
- cxx_flags = [
- "-std=" + cxx_standard,
- "-stdlib=libc++",
- ]
- if use_lld:
- # For single-platform builds, we can statically link the bundled
- # libraries.
- link_flags.extend([
- "-l:libc++.a",
- "-l:libc++abi.a",
- "-l:libunwind.a",
- # Compiler runtime features.
- "-rtlib=compiler-rt",
- # To support libunwind.
- "-lpthread",
- "-ldl",
- ])
- else:
- # The only known mechanism to static link libraries in ld64 is to
- # not have the corresponding .dylib files in the library search
- # path. The link time sandbox does not include the .dylib files, so
- # anything we pick up from the toolchain should be statically
- # linked. However, several system libraries on macOS dynamically
- # link libc++ and libc++abi, so static linking them becomes a problem.
- # We need to ensure that they are dynamic linked from the system
- # sysroot and not static linked from the toolchain, so explicitly
- # have the sysroot directory on the search path and then add the
- # toolchain directory back after we are done.
- link_flags.extend([
- "-L{}/usr/lib".format(compiler_configuration["sysroot_path"]),
- "-lc++",
- "-lc++abi",
- ])
-
- # Let's provide the path to the toolchain library directory
- # explicitly as part of the search path to make it easy for a user
- # to pick up something. This also makes the behavior consistent with
- # targets when a user explicitly depends on something like
- # libomp.dylib, which adds this directory to the search path, and would
- # (unintentionally) lead to static linking of libraries from the
- # toolchain.
- link_flags.extend([
- "-L{}lib".format(toolchain_path_prefix),
- ])
- elif stdlib == "libc++":
- cxx_flags = [
- "-std=" + cxx_standard,
- "-stdlib=libc++",
- ]
-
- link_flags.extend([
- "-l:c++.a",
- "-l:c++abi.a",
- ])
- elif stdlib == "stdc++":
- cxx_flags = [
- "-std=" + cxx_standard,
- "-stdlib=libstdc++",
- ]
-
- link_flags.extend([
- "-l:libstdc++.a",
- ])
- elif stdlib == "none":
- cxx_flags = [
- "-nostdlib",
- ]
-
- link_flags.extend([
- "-nostdlib",
- ])
- else:
- fail("Unknown value passed for stdlib: {stdlib}".format(stdlib = stdlib))
+ link_flags.extend([
+ "-pthread",
+ "-ldl",
+ ])

opt_link_flags = ["-Wl,--gc-sections"] if target_os == "linux" else []

@@ -325,7 +249,7 @@ def cc_toolchain_config(
"dwp": tools_path_prefix + "llvm-dwp",
"gcc": wrapper_bin_prefix + "cc_wrapper.sh",
"gcov": tools_path_prefix + "llvm-profdata",
- "ld": tools_path_prefix + "ld.lld" if use_lld else _host_tools.get_and_assert(host_tools_info, "ld"),
+ "ld": tools_path_prefix + ld if use_lld else _host_tools.get_and_assert(host_tools_info, "ld"),
"llvm-cov": tools_path_prefix + "llvm-cov",
"llvm-profdata": tools_path_prefix + "llvm-profdata",
"nm": tools_path_prefix + "llvm-nm",
@@ -342,6 +266,8 @@ def cc_toolchain_config(
# `lld` is being used as the linker.
supports_start_end_lib = use_lld

+ cxx_flags = []
+
# Replace flags with any user-provided overrides.
if compiler_configuration["compile_flags"] != None:
compile_flags = _fmt_flags(compiler_configuration["compile_flags"], toolchain_path_prefix)
diff --git a/toolchain/internal/common.bzl b/toolchain/internal/common.bzl
index 37bff8c..286efbf 100644
--- a/toolchain/internal/common.bzl
+++ b/toolchain/internal/common.bzl
@@ -21,6 +21,7 @@ host_tool_features = struct(
toolchain_tools = [
"clang-cpp",
"ld.lld",
+ "ld64.lld",
"llvm-ar",
"llvm-dwp",
"llvm-profdata",
Loading

0 comments on commit be30658

Please sign in to comment.