vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

Cannot compile v compiler in Windows with an account name containing Unicode characters #21718

Open shnorbluk opened 5 days ago

shnorbluk commented 5 days ago

Describe the bug

I am a French user, and my name contains an accented character (Noé). On my Windows PC, with an account having this name, I cloned the v repository and called the make.bat script to compile it, as described in installation documentation. The C compilation fails with an error about writing in temp directory.

Reproduction Steps

Clone and build the v compiler, following the procedure described here:

git clone https://github.com/vlang/v
cd v
make

Expected Behavior

It should build the V package without error, or at least inform the user about this issue about having special characters in %TEMP% directory.

Current Behavior

The following output is displayed:

Updating TCC
 > Syncing TCC from https://github.com/vlang/tccbin

Updating vc...
 > Sync with remote https://github.com/vlang/vc
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (2/2), 1.03 MiB | 7.45 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Updating files: 100% (2/2), done.

Building V...
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with "thirdparty/tcc/tcc.exe"
 > Compiling "./v.exe" with "./v_win_bootstrap.exe"
> C compiler cmd: "thirdparty/tcc/tcc.exe" "@C:\Users\Noé\AppData\Local\Temp\v_0\v_up.exe.tmp.c.rsp"
> C compiler response file "C:\Users\Noé\AppData\Local\Temp\v_0\v_up.exe.tmp.c.rsp":
  -Bthirdparty/tcc -fwrapv -g -o "C:\\v\\v_up.exe" -Wl,-stack=16777216 -Werror=implicit-function-declaration -I "C:\\v\\thirdparty\\stdatomic\\win" "C:\\Users\\Noé\\AppData\\Local\\Temp\\v_0\\v_up.exe.tmp.c" -std=c99 -D_DEFAULT_SOURCE -municode -bt25 -ldbghelp -lws2_32 -ladvapi32 -lshell32
> C compiler cmd: gcc "@C:\Users\Noé\AppData\Local\Temp\v_0\v_up.exe.tmp.c.rsp"
> C compiler response file "C:\Users\Noé\AppData\Local\Temp\v_0\v_up.exe.tmp.c.rsp":
  -Bthirdparty/tcc -fwrapv -g -no-pie -o "C:\\v\\v_up.exe" -Wl,-stack=16777216 -Werror=implicit-function-declaration -I "C:\\v\\thirdparty\\stdatomic\\win" "C:\\Users\\Noé\\AppData\\Local\\Temp\\v_0\\v_up.exe.tmp.c" -std=c99 -D_DEFAULT_SOURCE -municode -ldbghelp -lws2_32 -ladvapi32 -lshell32
tcc: error: file 'C:\Users\Noé\AppData\Local\Temp\v_0\v_up.exe.tmp.c' not found
builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
 > Clang not found
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with GCC
 > Compiling "./v.exe" with "./v_win_bootstrap.exe"
> C compiler cmd: gcc "@C:\Users\Noé\AppData\Local\Temp\v_0\v_up.exe.tmp.c.rsp"
> C compiler response file "C:\Users\Noé\AppData\Local\Temp\v_0\v_up.exe.tmp.c.rsp":
  -fwrapv -g -no-pie -o "C:\\v\\v_up.exe" -Wl,-stack=16777216 -Werror=implicit-function-declaration -I "C:\\v\\thirdparty\\stdatomic\\win" "C:\\Users\\Noé\\AppData\\Local\\Temp\\v_0\\v_up.exe.tmp.c" -std=c99 -D_DEFAULT_SOURCE -municode -ldbghelp -lws2_32 -ladvapi32 -lshell32
==================
tcc: error: file 'C:\Users\Noé\AppData\Local\Temp\v_0\detect_tcc.01J132XD7VH3R189BH701TP8AE.tmp.c' not found
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
 > V built successfully
 > To add V to your PATH, run `./v.exe symlink`.

V version: V 0.4.6 4302f86

I can confirm that the file C:\Users\Noé\AppData\Local\Temp\v_0\detect_tcc.01J132XD7VH3R189BH701TP8AE.tmp.c actually exists.

Possible Solution

Consider treating the directory containing intermediate C source files as an Unicode string. A simple workaround for people facing this issue is to redefine the TEMP environment variable, for exemple C:\Temp

Additional Information/Context

In my case, the problem was about having temp folder (as pointed by TEMP environment variable) containing a non ASCII character. I think you can reproduce it with any directory containing non English characters, on Windows 11 PC, or maybe even on a Linux one.

V version

0.4.6 4302f86

Environment details (OS name and version, etc.)

V full version: V 0.4.6 cc14272.4302f86 OS: windows, Microsoft Windows 11 Famille v22631 64-bit Processor: 16 cpus, 64bit, little endian,

getwd: C:\v vexe: C:\v\v.exe vexe mtime: 2024-06-23 18:15:53

vroot: OK, value: C:\v VMODULES: OK, value: C:\Users\Noé.vmodules VTMP: OK, value: C:\Temp\v_0

Git version: git version 2.45.0.windows.1 Git vroot status: weekly.2024.25-6-g4302f869 (7 commit(s) behind V master) .git/config present: true

CC version: Error: 'cc' n’est pas reconnu en tant que commande interne ou externe, un programme exécutable ou un fichier de commandes.

thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

JalonSolov commented 5 days ago

This is a known limitation of the tcc compiler V uses by default, not in V itself. The only options at this time are to install V in a directory with only ASCII characters in the full path, or force the use of a different (and undoubtedly much slower) C compiler.

shnorbluk commented 5 days ago

Thank you for your quick reply. I understand that this issue come from tcc and that you cannot do anything about that. Would it be possible to inform the user, in case of a compiler error in make.bat, about this tcc limitation? My point is that it took me hours to find the root cause of this problem, I downloaded many precompiled versions, I tried with gcc, but all my attempts failed, and I was about to give up developing in V on my PC. And I did not find anything on Internet to workaround this issue. So, my request, if you agree, would be to add a message in case of tcc error, saying about this non ASCII characters limitation, or a link to a page listing known tcc error causes, including this one. I have another question: is there a way to tell v and v-analyzer to use a different directory than %USERPROFILE%\.cache and %USERPROFILE%\.vmodules for cache and vmodules, other than changing USERPROFILE variable? Thank you.

spytheman commented 1 day ago

Yes, you can set the environment variables VTMP and VMODULES to point to folders that are shorter and have only ASCII characters in them, like c:\tmp for example. Doing so should allow you to use V even on windows systems, where your profile name has non ASCII characters in it.

Note: VTMP is used for generating .tmp.c files, which are later compiled with tcc. Note 2: You can also customize VCACHE separately, but it is usually not needed, once you change VMODULES to a folder that has no non ASCII characters in its full path.