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

Handle CPU value darwin_arm64 #1739

Merged
merged 13 commits into from
May 19, 2022
Merged
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ register_toolchains(
"//tests:c2hs-toolchain",
"//tests:doctest-toolchain",
"//tests:protobuf-toolchain",
"//tests:protobuf-toolchain-osx_arm64",
)

nixpkgs_cc_configure(
Expand Down
4 changes: 2 additions & 2 deletions docs/pandoc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ toolchain(
toolchain(
name = "macos",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
# the amd64 tool also runs on arm64 under Rosetta
"@platforms//os:osx",
],
toolchain = "@macos_pandoc//:pandoc_toolchain",
toolchain_type = ":toolchain_type",
Expand Down
1 change: 1 addition & 0 deletions examples/arm/arm-cross.nix
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ in
};
cc-aarch64 = pkgs.buildEnv {
name = "cc-aarch64-env";
passthru = { isClang = false; };
paths =
[ prefixStrippedGCC
];
Expand Down
74 changes: 55 additions & 19 deletions haskell/gen_ghc_bindist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pprint
import sys
from urllib.request import urlopen
from distutils.version import StrictVersion

# All GHC versions we generate.
# `version` is the version number
Expand All @@ -15,6 +16,25 @@
# `ignore_prefixes` is the prefix of files to ignore
# `ignore_suffixes` is the suffix of files to ignore
VERSIONS = [
{ "version": "9.2.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks a lot for reviving this script!

"ignore_suffixes": [".bz2", ".lz", ".zip"] },
{ "version": "9.0.2",
"ignore_prefixes": ["ghc-9.0.2a"],
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
{ "version": "9.0.1",
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
{ "version": "8.10.7",
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
{ "version": "8.10.4" },
{ "version": "8.10.3" },
{ "version": "8.10.2" },
{ "version": "8.10.1",
"ignore_suffixes": [".lz"] },
{ "version": "8.8.4" },
{ "version": "8.8.3",
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
{ "version": "8.8.2" },
{ "version": "8.8.1" },
{ "version": "8.6.5" },
{ "version": "8.6.4" },
{ "version": "8.6.3" },
Expand All @@ -34,14 +54,16 @@

# All architectures we generate.
# bazel: bazel name
# upstream: download.haskell.org name
# upstream: list of download.haskell.org name
ARCHES = [
{ "bazel": "linux_amd64",
"upstream": "x86_64-deb8-linux", },
"upstream": ["x86_64-deb8-linux", "x86_64-deb9-linux", "x86_64-deb10-linux"], },
{ "bazel": "darwin_amd64",
"upstream": "x86_64-apple-darwin" },
"upstream": ["x86_64-apple-darwin"] },
{ "bazel": "darwin_arm64",
"upstream": ["aarch64-apple-darwin"] },
{ "bazel": "windows_amd64",
"upstream": "x86_64-unknown-mingw32" },
"upstream": ["x86_64-unknown-mingw32"] },
]


Expand Down Expand Up @@ -94,9 +116,13 @@ def parse_sha256_file(content, version, url):
def eprint(mes):
print(mes, file = sys.stderr)

def select_one(xs, ys):
"""Select a single item from xs, prefer the first item also in ys."""
items = [x for x in xs if x in ys]
return items[0] if items else xs[0]

# Main.
if __name__ == "__main__":

# Fetch all hashsum files
# grab : { version: { arch: sha256 } }
grab = {}
Expand All @@ -115,15 +141,19 @@ def eprint(mes):
errs = {}
for ver, hashes in grab.items():
real_arches = frozenset(hashes.keys())
needed_arches = frozenset([a['upstream'] for a in ARCHES])
upstreams = [select_one(a['upstream'], real_arches) for a in ARCHES]
needed_arches = frozenset(upstreams)
missing_arches = needed_arches.difference(real_arches)
if missing_arches:
errs[ver] = missing_arches
if errs:
for ver, missing in errs.items():
eprint("version {ver} is missing hashes for required architectures {arches}".format(
ver = ver,
arches = missing))
print(
"WARN: version {ver} is missing hashes for architectures {arches}".format(
ver = ver,
arches = ','.join(missing)),
file=sys.stderr
)

# fetch the arches we need and create the GHC_BINDISTS dict
# ghc_bindists : { version: { bazel_arch: (tarball_url, sha256_hash) } }
Expand All @@ -132,19 +162,25 @@ def eprint(mes):
# { bazel_arch: (tarball_url, sha256_hash) }
arch_dists = {}
for arch in ARCHES:
hashes[arch['upstream']]
arch_dists[arch['bazel']] = (
link_for_tarball(arch['upstream'], ver),
hashes[arch['upstream']]
)
upstream = select_one(arch['upstream'], hashes)

if upstream in hashes:
arch_dists[arch['bazel']] = (
link_for_tarball(upstream, ver),
hashes[upstream]
)
ghc_bindists[ver] = arch_dists

# Print to stdout. Be aware that you can't `> foo.bzl`,
# because that truncates the source file which is needed
# for bazel to run in the first place.
print(""" \
# Generated with `bazel run @rules_haskell//haskell:gen-ghc-bindist | sponge haskell/private/ghc_bindist_generated.bzl`
# To add a version or architecture, edit the constants in haskell/gen_ghc_bindist.py
print("""\
# Generated with `bazel run @rules_haskell//haskell:gen-ghc-bindist`
# To add a version or architecture, edit the constants in haskell/gen_ghc_bindist.py,
# regenerate the dict and copy it here.
GHC_BINDIST = \\""")
pprint.pprint(ghc_bindists)

print("{")
for version in sorted(ghc_bindists.keys(), key=StrictVersion):
print(' ', repr(version), end=': ')
print(pprint.pformat(ghc_bindists[version], indent=8), end=',\n')
print("}")
Loading