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

gleam build doesn't have permission to link priv on Windows #3015

Open
PastMoments opened this issue Apr 20, 2024 · 7 comments
Open

gleam build doesn't have permission to link priv on Windows #3015

PastMoments opened this issue Apr 20, 2024 · 7 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions encouraged priority:high

Comments

@PastMoments
Copy link

On Windows running gleam build on a project with a priv directory will error. This seems to be caused by a Windows-specific symlink behaviour.
https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/

You can enable "Developer Mode", which will grant the symlink permission.
image
If there's no easy way to fix this, then printing out a warning to enable this setting would probably be okay.

Using Gleam v1.1.0

Reproducing:

gleam new project_name
cd project_name
mkdir priv
gleam build
> gleam build
Downloading packages
 Downloaded 2 packages in 0.02s
  Compiling gleam_stdlib
  Compiling gleeunit
  Compiling project_name
error: File IO failure

An error occurred while trying to link this file:

    C:\Users\USERNAME\Desktop\project_name\build\dev\erlang\project_name\priv

The error message from the file IO library was:

    A required privilege is not held by the client. (os error 1314)
@PastMoments PastMoments added the bug Something isn't working label Apr 20, 2024
@lpil
Copy link
Member

lpil commented Apr 20, 2024

Ah sorry! This is very frustrating.

What would be the best thing to do here? Perhaps we can try and link first, but if the linking fails then we can fall back to scanning the priv directory and copying all the files across. It'll be a lot slower but should always work.

@lpil lpil added help wanted Contributions encouraged good first issue Good for newcomers priority:high labels Apr 20, 2024
@PastMoments
Copy link
Author

PastMoments commented Apr 20, 2024

That seems like the only option with the way Windows/rust std works. With some change detection to the contents of the priv directory, the slowness shouldn't be too bad, at least when iterating on just the Gleam code itself.

We use this to symlink right now
https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_dir.html

Windows treats symlink creation as a privileged action, therefore this function is likely to fail unless the user makes changes to their system to permit symlink creation. Users can try enabling Developer Mode, granting the SeCreateSymbolicLinkPrivilege privilege, or running the process as an administrator.

I think it would be a good idea to emit this warning when it does the copying anyways, so if the user cares about the slowness they know how to fix it.

If anyone is curious, here's the way the rust std implements symlinking.
https://github.com/rust-lang/rust/blob/1.77.2/library/std/src/os/windows/fs.rs#L620
https://github.com/rust-lang/rust/blob/1.77.2/library/std/src/sys/pal/windows/fs.rs#L1261
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw

Looks like it's already doing all that it can do on Windows.

@johannesvollmer
Copy link

I have Rust experience and feel confident that copying the files sounds simple enough. Is someone already working on this?

@lpil
Copy link
Member

lpil commented May 15, 2024

Not that I'm aware of

@johannesvollmer
Copy link

Already started looking into the issue. Three biggest question would be, if we can write a useful test for this. I can test locally today, but it shouldn't fail in the future.

I'll have a look into it :)

@johannesvollmer
Copy link

Is GitHub issues the primary communication? The discord server seems to be about using Gleam, not about contributing.

@lpil
Copy link
Member

lpil commented May 20, 2024

It is, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions encouraged priority:high
Projects
None yet
Development

No branches or pull requests

3 participants