Skip to content

Commit

Permalink
Move worker code to external repository
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Nov 7, 2024
1 parent cc041b6 commit ae47d3f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 943 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "haskell/worker/impl"]
path = haskell/worker/impl
url = [email protected]:MercuryTechnologies/ghc-persistent-worker
12 changes: 7 additions & 5 deletions decls/haskell_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ load("@prelude//linking:types.bzl", "Linkage")
load(":common.bzl", "LinkableDepType", "buck", "prelude_rule")
load(":haskell_common.bzl", "haskell_common")
load(":native_common.bzl", "native_common")
load("@prelude//haskell/worker/worker.bzl", "worker_libs")
load("@prelude//haskell/worker/worker.bzl", "worker_libs", "worker_srcs", "worker_flags")

haskell_binary = prelude_rule(
name = "haskell_binary",
Expand Down Expand Up @@ -67,8 +67,9 @@ haskell_binary = prelude_rule(
"linker_flags": attrs.list(attrs.arg(), default = []),
"platform": attrs.option(attrs.string(), default = None),
"platform_linker_flags": attrs.list(attrs.tuple(attrs.regex(), attrs.list(attrs.arg())), default = []),
"_worker_srcs": attrs.list(attrs.source(), default = ["@prelude//haskell/worker:Main.hs", "@prelude//haskell/worker:Worker.hs"]),
"_worker_deps": attrs.list(attrs.dep(), default = ["@prelude//haskell/worker:{}".format(pkg) for pkg in worker_libs])
"_worker_srcs": attrs.list(attrs.source(), default = worker_srcs),
"_worker_deps": attrs.list(attrs.dep(), default = ["@prelude//haskell/worker:{}".format(pkg) for pkg in worker_libs]),
"_worker_compiler_flags": attrs.list(attrs.string(), default = worker_flags),
}
),
)
Expand Down Expand Up @@ -191,8 +192,9 @@ haskell_library = prelude_rule(
"linker_flags": attrs.list(attrs.arg(), default = []),
"platform": attrs.option(attrs.string(), default = None),
"platform_linker_flags": attrs.list(attrs.tuple(attrs.regex(), attrs.list(attrs.arg())), default = []),
"_worker_srcs": attrs.list(attrs.source(), default = ["@prelude//haskell/worker:Main.hs", "@prelude//haskell/worker:Worker.hs"]),
"_worker_deps": attrs.list(attrs.dep(), default = ["@prelude//haskell/worker:{}".format(pkg) for pkg in worker_libs])
"_worker_srcs": attrs.list(attrs.source(), default = worker_srcs),
"_worker_deps": attrs.list(attrs.dep(), default = ["@prelude//haskell/worker:{}".format(pkg) for pkg in worker_libs]),
"_worker_compiler_flags": attrs.list(attrs.string(), default = worker_flags),
}
),
)
Expand Down
2 changes: 2 additions & 0 deletions haskell/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def _common_compile_module_args(
) -> CommonCompileModuleArgs:
command = cmd_args(ghc_wrapper)
command.add("--ghc", haskell_toolchain.compiler)
command.add("--ghc-dir", haskell_toolchain.ghc_dir)

# Some rules pass in RTS (e.g. `+RTS ... -RTS`) options for GHC, which can't
# be parsed when inside an argsfile.
Expand Down Expand Up @@ -700,6 +701,7 @@ def _compile_module(
compile_cmd.add("-fwrite-if-simplified-core")
if enable_th:
compile_cmd.add("-fprefer-byte-code")
compile_cmd.add("-fpackage-db-byte-code")

compile_cmd.add(cmd_args(dependency_modules.reduce("packagedb_deps").keys(), prepend = "--buck2-package-db"))

Expand Down
14 changes: 12 additions & 2 deletions haskell/haskell.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ worker = anon_rule(
"enable_profiling": attrs.default_only(attrs.bool(default = False)),
"external_tools": attrs.list(attrs.dep(), default = []),
"link_group_map": LINK_GROUP_MAP_ATTR,
"linker_flags": attrs.list(attrs.string(), default = ["-threaded", "-rtsopts", "-with-rtsopts=-N", "-O2",]),
"linker_flags": attrs.list(attrs.string(), default = []),
"platform_deps": attrs.list(attrs.dep(), default = []),
"srcs": attrs.list(attrs.source()),
"srcs_deps": attrs.dict(attrs.string(), attrs.dep(), default = {}),
Expand Down Expand Up @@ -1521,9 +1521,19 @@ def _persistent_worker(ctx: AnalysisContext) -> WorkerInfo | None:
"_ghc_wrapper": ctx.attrs._ghc_wrapper,
"_haskell_toolchain": ctx.attrs._haskell_toolchain,
"deps": ctx.attrs._worker_deps,
"link_style": "static",
"link_style": "shared",
"name": "prelude//haskell:worker",
"srcs": ctx.attrs._worker_srcs,
"compiler_flags": ctx.attrs._worker_compiler_flags + [
"-O2",
],
"linker_flags": ctx.attrs._worker_compiler_flags + [
"-dynamic",
"-rtsopts=all",
"-with-rtsopts=-K512M -H -I5 -T",
"-threaded",
"-O2",
],
},
)
return WorkerInfo(worker_target.artifact("worker"))
Expand Down
1 change: 1 addition & 0 deletions haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ HaskellToolchainInfo = provider(
"script_template_processor": provider_field(typing.Any, default = None),
"packages": provider_field(typing.Any, default = None),
"use_worker": provider_field(bool, default = False),
"ghc_dir": provider_field(typing.Any, default = None),
},
)

Expand Down
3 changes: 3 additions & 0 deletions haskell/tools/ghc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def main():
parser.add_argument(
"--ghc", required=True, type=str, help="Path to the Haskell compiler GHC."
)
parser.add_argument(
"--ghc-dir", type=str, help="Worker option"
)
parser.add_argument(
"--abi-out",
required=True,
Expand Down
3 changes: 0 additions & 3 deletions haskell/worker/BUCK
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
load(":worker.bzl", "worker_libs")

export_file("Main.hs", visibility = ["PUBLIC"])
export_file("Worker.hs", visibility = ["PUBLIC"])

[haskell_toolchain_library(name = pkg, visibility = ["PUBLIC"]) for pkg in worker_libs]
272 changes: 0 additions & 272 deletions haskell/worker/Main.hs

This file was deleted.

Loading

0 comments on commit ae47d3f

Please sign in to comment.