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

Create cookie file for toolchain packages #10782

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

gridbugs
Copy link
Collaborator

This fixes two issues with cookies for toolchain packages:

Prior to this change, dune expected toolchain cookies to be created inside the toolchains directory, ie. outside of the project. The machinery for creating cookies only works within the build directory, so cookies for toolchain packages were never created. The location of the cookie had to be the same as the location of the installed package, in what dune referred to as the package's "target_dir". The fix is to decouply these two locations by adding a new path "prefix" to packages, corresponding to the "--prefix" argument of most configure scripts. This allows toolchain packages to have a "target_dir" within the build directory, and for a cookie file to be created within its "target_dir", while still allowing the package to be installed outside the project inside its "prefix", inside the toolchains directory.

The second issue is that the contents of the cookie was based on the package's "target_dir", and thus cookies for toolchain packages would be empty (toolchain packages are now installed in the package's "prefix" dir instead). Dune makes the distinction between the "paths" and "write_paths" of a package, the latter being the unsandboxed final install paths of the package, and it's the "target_dir" within a package's "write_paths" that is traversed (in the absence of a .install file) to determine the contents of the package's cookie. The fix was to detect the case where the "paths" of a package contains a prefix referring outside the build directory, and in such a case, traverse the directory at that path rather than the one at "target_dir".

Toolchains still don't completely work, as in some cases build tools are unable to find binaries installed by the compiler package, however manual inspection shows that the cookie is being created for toolchain packages and contains the expected contents. Fixes for the remaining issues will come in later changes.

match build_command with
| None | Some Dune -> Memo.return build_command
| Some (Action action) ->
let+ installed = Fs_memo.dir_exists prefix in
Copy link
Member

Choose a reason for hiding this comment

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

Note that doing this check at rule generation time at is wrong as I've mentioned. Doesn't prevent this PR from being merged, but you should work on pushing these checks to action execution.

(* If the toolchain is already installed, just create an empty
config.cache file so other packages see that the compiler package
is installed. *)
Dune_lang.Action.Run
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why you moved this from Pkg_toolchain? I'd really prefer to keep this feature as isolated as possible. I realize, we can't fully accomplish that, but we should at least try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not a strong reason, no. I'll move it back.

This fixes two issues with cookies for toolchain packages:

Prior to this change, dune expected toolchain cookies to be created
inside the toolchains directory, ie. outside of the project. The
machinery for creating cookies only works within the build directory,
so cookies for toolchain packages were never created. The location of
the cookie had to be the same as the location of the installed
package, in what dune referred to as the package's "target_dir". The
fix is to decouply these two locations by adding a new path "prefix"
to packages, corresponding to the "--prefix" argument of most
configure scripts. This allows toolchain packages to have a
"target_dir" within the build directory, and for a cookie file to be
created within its "target_dir", while still allowing the package to
be installed outside the project inside its "prefix", inside the
toolchains directory.

The second issue is that the contents of the cookie was based on the
package's "target_dir", and thus cookies for toolchain packages would
be empty (toolchain packages are now installed in the package's
"prefix" dir instead). Dune makes the distinction between the "paths"
and "write_paths" of a package, the latter being the unsandboxed final
install paths of the package, and it's the "target_dir" within a
package's "write_paths" that is traversed (in the absence of a
<package>.install file) to determine the contents of the package's
cookie. The fix was to detect the case where the "paths" of a package
contains a prefix referring outside the build directory, and in such a
case, traverse the directory at that path rather than the one at
"target_dir".

Toolchains still don't completely work, as in some cases build tools
are unable to find binaries installed by the compiler package, however
manual inspection shows that the cookie is being created for toolchain
packages and contains the expected contents. Fixes for the remaining
issues will come in later changes.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
@gridbugs gridbugs force-pushed the toolchain-cookies branch from 88c87a5 to cccb665 Compare July 31, 2024 02:28
@gridbugs gridbugs merged commit b0c495c into ocaml:main Jul 31, 2024
25 of 27 checks passed
@gridbugs gridbugs deleted the toolchain-cookies branch July 31, 2024 02:31
anmonteiro pushed a commit to anmonteiro/dune that referenced this pull request Nov 17, 2024
This fixes two issues with cookies for toolchain packages:

Prior to this change, dune expected toolchain cookies to be created
inside the toolchains directory, ie. outside of the project. The
machinery for creating cookies only works within the build directory,
so cookies for toolchain packages were never created. The location of
the cookie had to be the same as the location of the installed
package, in what dune referred to as the package's "target_dir". The
fix is to decouply these two locations by adding a new path "prefix"
to packages, corresponding to the "--prefix" argument of most
configure scripts. This allows toolchain packages to have a
"target_dir" within the build directory, and for a cookie file to be
created within its "target_dir", while still allowing the package to
be installed outside the project inside its "prefix", inside the
toolchains directory.

The second issue is that the contents of the cookie was based on the
package's "target_dir", and thus cookies for toolchain packages would
be empty (toolchain packages are now installed in the package's
"prefix" dir instead). Dune makes the distinction between the "paths"
and "write_paths" of a package, the latter being the unsandboxed final
install paths of the package, and it's the "target_dir" within a
package's "write_paths" that is traversed (in the absence of a
<package>.install file) to determine the contents of the package's
cookie. The fix was to detect the case where the "paths" of a package
contains a prefix referring outside the build directory, and in such a
case, traverse the directory at that path rather than the one at
"target_dir".

Toolchains still don't completely work, as in some cases build tools
are unable to find binaries installed by the compiler package, however
manual inspection shows that the cookie is being created for toolchain
packages and contains the expected contents. Fixes for the remaining
issues will come in later changes.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants