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

Don't hardcode platforms in toolchain anymore #597

Merged
merged 3 commits into from
Jan 22, 2019
Merged

Conversation

mboes
Copy link
Member

@mboes mboes commented Jan 19, 2019

Our toolchain implementation was incomplete. We used to assume x86_64 as
the architecture, and never set any platform constraints. We now make it
possible to do so in new attributes to haskell_toolchain. This has
important implications. It means that we no longer should define a single
toolchain that states different constraints depending on the host platform.
We now instead have multiple toolchains in scope, one for each operating
system. Which properly declared constraints, the toolchain resolution
mechanism can select the right one.

As a side effect, ghc_bindist is now easier to use. Users don't need
to write a separate toolchain declaration and toolchain registration
in addition to the declaring the bindist anymore. The next step after
this PR will be to introduce convenience functions to add external
dependencies for all known bindists, and all known GHC's in Nixpkgs.
That sounds overkill, but the toolchain resolution mechanism makes
this fine. And it's how we'll finally make it seamless for some
developers to use bindists while others on the same project can use
Nixpkgs without having to make edits to the WORKSPACE.

Our toolchain implementation was incomplete. We used to assume x86_64
as the architecture, and never set any platform constraints. We now
make it possible to do so in new attributes to `haskell_toolchain`.
This has important implications. It means that we no longer should
define a single toolchain that states different constraints depending
on the host platform. We now instead have multiple toolchains in
scope, one for each operating system. Which properly declared
constraints, the toolchain resolution mechanism can select the right
one.

There is another change in this commit, which we couldn't keep
separate because it was co-dependent to the above change if we want to
stay green. `ghc_bindist` now itself defines a toolchain (no need to
define one separately), and also itself registers it. So `ghc_bindist`
is now easier to use. A side effect of this is that the toolchain
definition for Windows moves into an external dependency, where it
won't bother anyone. If we define the Windows toolchain in `//tests`,
then we'll be fetching and building it even on Linux whenever someone
says `bazel build //tests/...`.

We'll eventually also make Nixpkgs toolchains equally easy to define.
@mboes mboes requested review from guibou and aherrmann January 19, 2019 22:47
@mboes mboes force-pushed the per-platform-toolchains branch from 75ab640 to 9255a61 Compare January 19, 2019 22:58
Copy link
Contributor

@guibou guibou left a comment

Choose a reason for hiding this comment

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

LGTM. However there are a few cases which list only darwin, linux, but no windows. I know windows is a work in progress, but perhaps a comment (TODO or XXX) with a few words about the future window work at the right position may help.

WORKSPACE Outdated
name = "threaded-rts",
srcs = glob(
["lib/ghc-*/rts/libHSrts_thr-ghc*." + ext for ext in [
"so",
Copy link
Contributor

Choose a reason for hiding this comment

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

no .dll?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a copy/paste of the existing ghc.BUILD. Any improvement here would be an orthogonal change.

version = ghc_version,
)

register_toolchains(
"//tests:ghc",
"//tests:ghc_linux",
"//tests:ghc_osx",
Copy link
Contributor

Choose a reason for hiding this comment

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

no ghc_window?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. See the commit messages as for why. Windows uses ghc_bindist and that rule self registers.

version = ghc_version,
)
for os, tools, locale_archive in [
("linux", "@hackage-ghc//:bin", "@glibc_locales//:locale-archive"),
Copy link
Contributor

Choose a reason for hiding this comment

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

No "window" either?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. See commit messages as for why.

srcs = glob([
"bin/*",
]),
srcs = glob(["bin/*"]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Cosmetic only, or I missed something?

WORKSPACE Outdated
@@ -28,7 +28,34 @@ load(
haskell_nixpkgs_package(
name = "ghc",
attribute_path = "haskellPackages.ghc",
build_file = "//haskell:ghc.BUILD",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that //haskell:ghc.BUILD is now only used for ghc_bindist? Shouldn't the name change?

Copy link
Member Author

Choose a reason for hiding this comment

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

With the latest commit in the series, we no longer need to duplicate much of the content of this file. So we're back to using //haskell:ghc.BUILD here as before.

@mboes mboes force-pushed the per-platform-toolchains branch 2 times, most recently from 274e5ae to a3160fb Compare January 19, 2019 23:15
mboes added 2 commits January 20, 2019 23:36
We want the toolchain definition to be tucked away in a separate
repository, that way `bazel build //...` will not match it (and e.g.
build the Windows toolchain even on Linux). At the same time, we don't
want the definition in the bindist repository, because then we need to
download the bindist first before we can see the toolchain definition.
The solution is to add the toolchain definition in its own special
repository.
@mboes mboes force-pushed the per-platform-toolchains branch from fcf2195 to 8a1908e Compare January 20, 2019 22:42
Copy link
Member

@aherrmann aherrmann left a comment

Choose a reason for hiding this comment

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

LGTM

@mboes mboes merged commit 40543c5 into master Jan 22, 2019
@mboes mboes deleted the per-platform-toolchains branch January 22, 2019 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants