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

fix(pkg): add stub for shGetFolderPath #9486

Conversation

Alizter
Copy link
Collaborator

@Alizter Alizter commented Dec 13, 2023

Building packages on windows results in error described here:

This is due to a missing stub. This PR adds that missing stub.

  • update fork

@dra27 Could you take a look at this? I've plucked your code from the opam stubs, but there were some warnings about WCHAR being incompatible with the expected type for SHGetFolderPath. Turns out there is a variant called SHGetFolderPathW specifically for "W"ide characters which seems to work.

When this patch is used, the build of a lock file gets further however invocation of ocamlc seems to get confused about Windows paths in BUILD_PATH_PREFIX_MAP. Would you know if this is a known problem in OCaml?

Signed-off-by: Ali Caglayan <alizter@gmail.com>
@@ -78,6 +79,26 @@ CAMLprim value OPAMW_GetArchitecture(value unit)
return get_PE_cpu_architecture(NativeMachine);
}

/*
* Somewhat against my better judgement, wrap SHGetFolderPath rather than
* SHGetKnownFolderPath to maintain XP compatibility. OPAM already requires
Copy link
Collaborator

Choose a reason for hiding this comment

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

But then, wouldn't we be perfectly fine to use SHGetKnownFolderPath in our stubs? We don't really have to stay compatible with an OS from 2001.

I don't even think OCaml 5+ has a native compiler that supports 32-bit systems like XP machines would predominantly be.

Copy link
Collaborator Author

@Alizter Alizter Dec 13, 2023

Choose a reason for hiding this comment

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

I didn't write this comment, but took it from the opam stubs. I think I'll try and do a more modern equivalent. We aren't really looking to support XP in Dune.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I know, but the point of the comment is a valid one and while for OPAM it might've been the right call (I assume), it might not be for us.

@rgrinberg
Copy link
Member

Before there's any discussion of the code, can you update the description to include:

  1. What's the problem that you're address
  2. How this PR is addressing this problem

@Alizter
Copy link
Collaborator Author

Alizter commented Dec 14, 2023

@rgrinberg I've updated the PR description with the issue that this is meant to fix: #9474

@rgrinberg
Copy link
Member

Either I'm missing some context, or the description is still incomplete. How is this stub supposed to help with reading a config file? Why would we even need this platform specific code to read a config file?

@Alizter
Copy link
Collaborator Author

Alizter commented Dec 15, 2023

@rgrinberg I'm not entirely sure why opam wants to read the home directory in this case. This PR simply stops that from being an error which it currently is. You can check the backtrace in that issue to see that this function eventually gets called and because it doesn't have an implementation it errors.

We could probably do this in a better way, but it was my understanding that we didn't want to modify the opam code for now and get something working.

@rgrinberg
Copy link
Member

Yes, we don't want to modify the opam code. Unfortunately, this is exactly what your PR is doing.

Looking at the stacktrace, here's an alternative that does not modify upstream:

  1. Read the config file using our own IO functions
  2. Parse it using one of the string parsers.

@Alizter
Copy link
Collaborator Author

Alizter commented Dec 24, 2023

I somewhat disagree that this is what my PR is doing, but I agree that your alternative is perhaps a better option.

@Alizter Alizter closed this Dec 24, 2023
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.

3 participants