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

On windows cmd.exe, cargo build cal msvc cl, the output encoding are invalid. #552

Open
lygstate opened this issue Oct 9, 2020 · 8 comments
Labels
help wanted O-windows Windows targets and toolchains

Comments

@lygstate
Copy link

lygstate commented Oct 9, 2020

cc = "1.0.61"

   = note: `#[warn(deprecated)]` on by default

warning: 1 warning emitted

   Compiling relibc v0.1.0 (C:\work\study\os\redox\relibc)
The following warnings were emitted during compilation:

warning: cl: ������ error D8021 :��Ч����ֵ������/Wno-expansion-to-defined��

error: failed to run custom build command for `relibc v0.1.0 (C:\work\study\os\redox\relibc)`

Caused by:
  process didn't exit successfully: `C:\work\study\os\redox\relibc\target\debug\build\relibc-df312d9f2100ce01\build-script-build` (exit code: 1)
  --- stderr


  error occurred: Command "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "C:\\work\\study\\os\\redox\\relibc/include" "-W4" "-nostdinc" "-nostdlib" "-fno-stack-protector" "-Wno-expansion-to-defined" "-FoC:\\work\\study\\os\\redox\\relibc\\target\\debug\\build\\relibc-7204dd44fe4e99e1\\out\\src/c\\dlmalloc.o" "-c" "src/c\\dlmalloc.c" with args "cl.exe" did not execute successfully (status code exit code: 2).
@alexcrichton
Copy link
Member

Can you try setting VSLANG=1033 in the environment? If that works then we can try doing the same thing that rustc does

@lygstate
Copy link
Author

lygstate commented Oct 11, 2020

Can you try setting VSLANG=1033 in the environment? If that works then we can try doing the same thing that rustc does

I am sorry that the newest version of visual studio doesn't take care of VSLANG=1033

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools>set VSLANG=1033

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools>set LC_ALL=c

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools>link
Microsoft (R) Incremental Linker Version 14.27.29111.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 用法: LINK [选项] [文件] [@commandfile]

  选项:

      /ALIGN:#
      /ALLOWBIND[:NO]
      /ALLOWISOLATION[:NO]
   /APPCONTAINER[:NO]
      /ASSEMBLYDEBUG[:DISABLE]
   /ASSEMBLYLINKRESOURCE:文件名
   /ASSEMBLYMODULE:文件名
   /ASSEMBLYRESOURCE:文件名[,[名称][,PRIVATE]]
   /BASE:{地址[,大小]|@文件名,键}
      /CLRIMAGETYPE:{IJW|PURE|SAFE|SAFE32BITPREFERRED}
   /CLRLOADEROPTIMIZATION:{MD|MDH|NONE|SD}
      /CLRSUPPORTLASTERROR[:{NO|SYSTEMDLL}]
      /CLRTHREADATTRIBUTE:{MTA|NONE|STA}
      /CLRUNMANAGEDCODECHECK[:NO]
      /DEBUG[:{FASTLINK|FULL|NONE}]
   /DEF:文件名
   /DEFAULTLIB:库
      /DELAY:{NOBIND|UNLOAD}
      /DELAYLOAD:dll
      /DELAYSIGN[:NO]
      /DEPENDENTLOADFLAG:flag
      /DLL
      /DRIVER[:{UPONLY|WDM}]
      /DYNAMICBASE[:NO]
      /ENTRY:symbol
(按回车键继续)
      /ERRORREPORT:{NONE|PROMPT|QUEUE|SEND}
      /EXPORT:symbol
      /EXPORTPADMIN[:size]
      /FASTFAIL[:NO]
      /FASTGENPROFILE[:{COUNTER32|COUNTER64|EXACT|MEMMAX=#|MEMMIN=#|NOEXACT|
                        NOPATH|NOTRACKEH|PATH|PGD=filename|TRACKEH}]
      /FILEALIGN:#
      /FIXED[:NO]
      /FORCE[:{MULTIPLE|UNRESOLVED}]
   /FUNCTIONPADMIN[:大小]
      /GUARD:{CF|NO}
   /GENPROFILE[:{COUNTER32|COUNTER64|EXACT|MEMMAX=#|MEMMIN=#|NOEXACT|
          NOPATH|NOTRACKEH|PATH|PGD=filename|TRACKEH}]
   /HEAP:reserve[,commit]
   /HIGHENTROPYVA[:NO]
   /IDLOUT:文件名
   /IGNORE:#
      /IGNOREIDL
      /ILK:filename
   /IMPLIB:文件名
   /INCLUDE:符号
      /INCREMENTAL[:NO]
   /INTEGRITYCHECK
      /KERNEL
   /KEYCONTAINER:name
   /KEYFILE:文件名
      /LARGEADDRESSAWARE[:NO]
   /LIBPATH:目录
      /LINKREPRO:dir
(按回车键继续)
      /LINKREPROTARGET:filename
      /LTCG[:{INCREMENTAL|NOSTATUS|OFF|STATUS|}]
      /MACHINE:{ARM|ARM64|ARM64X|EBC|X64|X86}
      /MANIFEST[:{EMBED[,ID=#]|NO}]
   /MANIFESTDEPENDENCY:manifest dependency
   /MANIFESTFILE:filename
   /MANIFESTINPUT:文件名
   /MANIFESTUAC[:{NO|UAC 片段}]
   /MAP[:文件名]
      /MAPINFO:{EXPORTS|PDATA}
   /MERGE:from=to
   /MIDL:@commandfile
      /NATVIS:filename
      /NOASSEMBLY
   /NODEFAULTLIB[:库]
      /NOENTRY
      /NOIMPLIB
      /NOLOGO
      /NXCOMPAT[:NO]
      /OPT:{ICF[=iterations]|LBR|NOICF|NOLBR|NOREF|REF}
   /ORDER:@文件名
   /OUT:文件名
   /PDB:文件名
      /PDBSTRIPPED[:filename]
      /PROFILE
   /RELEASE
   /SAFESEH[:NO]
   /SECTION:名称,[[!]{DEKPRSW}][,ALIGN=#]
      /SOURCELINK:filename
(按回车键继续)
      /STACK:reserve[,commit]
      /STUB:filename
      /SUBSYSTEM:{BOOT_APPLICATION|CONSOLE|EFI_APPLICATION|
                  EFI_BOOT_SERVICE_DRIVER|EFI_ROM|EFI_RUNTIME_DRIVER|
         NATIVE|POSIX|WINDOWS|WINDOWSCE}[,#[.##]]
   /SWAPRUN:{CD|NET}
   /TLBID:#
   /TLBOUT:文件名
   /TIME
      /TSAWARE[:NO]
      /USEPROFILE[:{AGGRESSIVE|PGD=filename}]
      /VERBOSE[:{CLR|ICF|INCR|LIB|REF|SAFESEH|UNUSEDDELAYLOAD|UNUSEDLIBS}]
   /VERSION:#[.#]
      /WINMD[:{NO|ONLY}]
      /WINMDDELAYSIGN[:NO]
   /WINMDFILE:文件名
      /WINMDKEYCONTAINER:name
      /WINMDKEYFILE:filename
      /WHOLEARCHIVE[:library]
   /WX[:NO]

@alexcrichton
Copy link
Member

If that doesn't work unfortunately I don't know how to fix this :(

@crlf0710
Copy link
Member

@lygstate Can you double-check that you have Visual Studio English language pack installed (additionally to whatever your primary language pack) ? This VSLANG=1033 trick still works fine for me on my machine with VS2019.

@HMaker
Copy link

HMaker commented Oct 23, 2023

@crlf0710 I had same issue, installing English language pack in the Visual Studio Installer solved it. I think cc-rs should validate the MSVC language is in English and warn the user error messages may be silently dropped for non-english languages.

@thomcc
Copy link
Member

thomcc commented Nov 12, 2023

I think cc-rs should validate the MSVC language is in English and warn the user error messages may be silently dropped for non-english languages.

Makes sense. I'd take a PR for this.

@thomcc thomcc added help wanted O-windows Windows targets and toolchains labels Nov 12, 2023
@ChrisDenton
Copy link
Member

See also #809 (comment) which I think is related. We may be able to handle printing in the non UTF-8 case. But there's some complexity because cl.exe et al have their roots in very old tools and don't use the same code page as most cli applications do.

@kazatsuyu
Copy link

I was looking into this issue and noticed that cl.exe is behaving strangely. I am a Japanese user and when I run cl at the command prompt, I get

使い方: cl [ オプション... ] ファイル名... [ /link リンク オプション... ]

at the command prompt. However, when I run cl | cat, the output is

□g□□□□: cl [ □I□v□V□□□□... ] □t□@□C□□□□... [ /link □□□□□N □I□v□V□□□□... ]

If cl > temp.txt, its contents are encoded in CP932, and the result of cat temp.txt is the same as cl | cat.

Presumably, cl.exe uses the relatively new console API to output both UTF-16 strings and strings with legacy encoding, and the parent process can use any of the APIs to get UTF-16 strings. I will try this later to see if this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted O-windows Windows targets and toolchains
Projects
None yet
Development

No branches or pull requests

7 participants