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

Allow arbitrary Cabal tools #987

Merged
merged 1 commit into from
Jul 11, 2019
Merged

Allow arbitrary Cabal tools #987

merged 1 commit into from
Jul 11, 2019

Conversation

mboes
Copy link
Member

@mboes mboes commented Jul 6, 2019

Cabal has a whitelist of tools, for which we can supply a path
explicitly using --with-PROG, where PROG is the name of the tool.
But in practice Setup.hs scripts and the build process in general
sometimes use other tools that are not part of the whitelist. For
example, postgresql-libpq calls pg_config during configuration.
Unlike the whitelist, these tools can only be supplied by ensuring
they are reachable from the PATH. So we extend the PATH to make
this true, hoping that not too much else is exposed as a side effect.

We could avoid undeclared inputs leaking, but

  1. we can't do this without a hefty performance cost on Windows (no
    symlinks),
  2. in practice this should be the responsibility of the workspace
    rules for each dependency to expose just what we want,
  3. Cabal rules are not hermetic to begin with, because they need all
    manner of standard utilities.

Adding a test for this would be awkward, and the feature is at a low
risk of regression (since it's already partially tested), so I didn't write one. Testing would require
making all of @stackage, and hence most tests, depend on Nixpkgs. We
don't want that, because of bindist builds.

@mboes mboes requested review from aspiwack and aherrmann July 6, 2019 19:47
@mboes mboes force-pushed the more-cabal-tools branch 4 times, most recently from cd2442d to e1c2e2c Compare July 7, 2019 14:33
do
if [[ -n "$entry" ]]
then
new_path="$new_path${new_path:+:}$(realpath -m "$entry")"
Copy link
Member

Choose a reason for hiding this comment

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

As far as I can tell realpath doesn't exist on macos, so this will probably fail on non nixpkgs macos. This can also be done in bash, similar to here

Copy link
Member Author

Choose a reason for hiding this comment

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

macOS+Nix shouldn't be a problem, but bare macOS, yes. A pure bash solution is better. I found this on the Internet:

realpath() {
    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

which I understand better than the code you link to.

Copy link
Member

Choose a reason for hiding this comment

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

The linked code does essentially the same thing, with the difference that it keeps relative paths relative. In that case it matters more, as the outputs of ./configure are outputs of the configure step and inputs to later build steps, so absolute paths would certainly leak into cache keys. Here it should matter less, as PATH should typically not end up in the built library/binary.

@mboes mboes force-pushed the more-cabal-tools branch from e1c2e2c to 37601b4 Compare July 8, 2019 08:38
@mboes
Copy link
Member Author

mboes commented Jul 8, 2019

@aherrmann PTAL

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.

Looks good to me.

Copy link
Member

@aspiwack aspiwack left a comment

Choose a reason for hiding this comment

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

Thanks, I'll test it out this week.

# Remove any relative entries, because we'll be changing CWD shortly.
LD_LIBRARY_PATH=$(canonicalize_path $LD_LIBRARY_PATH)
LIBRARY_PATH=$(canonicalize_path $LIBRARY_PATH)
PATH=$(canonicalize_path $PATH)
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit surprised that we have to do the absolute name resolution in Bash. I would have thought Bazel would give us tools to do so.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any Bazel supplied absolute paths would wreak havoc on the action cache. Nix gets away with this because the store is always in the same location. But the Bazel cache and the action execution sandbox could be anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Oh! I get it! It could be quite terrible for shared cache too.

That being said, these global names should not be a dependency nor an output of the target, so I'm not sure it would matter for this particular case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I meant for any shared cache. In general there will be paths to inputs going in one or more of the above 3 environment variables.

@mboes mboes added the merge-queue merge on green CI label Jul 10, 2019
Cabal has a whitelist of tools, for which we can supply a path
explicitly using `--with-PROG`, where `PROG` is the name of the tool.
But in practice `Setup.hs` scripts and the build process in general
sometimes use other tools that are not part of the whitelist. For
example, `postgresql-libpq` calls `pg_config` during configuration.
Unlike the whitelist, these tools can only be supplied by ensuring
they are reachable from the `PATH`. So we extend the `PATH` to make
this true, hoping that not too much else is exposed as a side effect.

We could avoid undeclared inputs leaking, but

1. we can't do this without a hefty performance cost on Windows (no
   symlinks),
2. in practice this should be the responsibility of the workspace
   rules for each dependency to expose just what we want,
3. Cabal rules are not hermetic to begin with, because they need all
   manner of standard utilities.

Adding a test for this would be awkward, and the feature is at a low
risk of regression, so I didn't write one. Testing would require
making all of `@stackage`, and hence most tests, depend on Nixpkgs. We
don't want that, because of bindist builds.
@mboes mboes force-pushed the more-cabal-tools branch from ae876b4 to 257f1c5 Compare July 11, 2019 22:23
@mergify mergify bot merged commit 56ade9f into master Jul 11, 2019
@mergify mergify bot deleted the more-cabal-tools branch July 11, 2019 22:59
@mergify mergify bot removed the merge-queue merge on green CI label Jul 11, 2019
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