This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Windows: Use /utf-8 compiler flag
Type: Stage: resolved
Components: Build, Windows Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: methane, miss-islington, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2021-02-09 02:59 by methane, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24498 merged methane, 2021-02-10 05:13
PR 24513 merged miss-islington, 2021-02-12 02:21
Messages (6)
msg386689 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-02-09 02:59
When building Python on Windows Japanese environment, several warnings are shown.

```
C:\Users\songo\source\repos\cpython\Modules\_sha3\kcp\KeccakSponge.h(1,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを
Unicode 形式で保存してください。 [C:\Users\songo\source\repos\cpython\PCbuild\pythoncore.vcxproj]
C:\Users\songo\source\repos\cpython\Modules\_statisticsmodule.c(1,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んで います。データの損失を防ぐために、ファイルを Unico
de 形式で保存してください。 [C:\Users\songo\source\repos\cpython\PCbuild\pythoncore.vcxproj]
C:\Users\songo\source\repos\cpython\Modules\_zoneinfo.c(1,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。 データの損失を防ぐために、ファイルを Unicode 形式で保存
してください。 [C:\Users\songo\source\repos\cpython\PCbuild\_zoneinfo.vcxproj]
C:\Users\songo\source\repos\cpython\Modules\_zoneinfo.c(1028,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを Unicode 形式
で保存してください。 [C:\Users\songo\source\repos\cpython\PCbuild\_zoneinfo.vcxproj]
C:\Users\songo\source\repos\cpython\Modules\_zoneinfo.c(1970,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを Unicode 形式
で保存してください。 [C:\Users\songo\source\repos\cpython\PCbuild\_zoneinfo.vcxproj]
C:\Users\songo\source\repos\cpython\Modules\expat\xmltok.c(1,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを Unicode 形式
で保存してください。 [C:\Users\songo\source\repos\cpython\PCbuild\_elementtree.vcxproj]
C:\Users\songo\source\repos\cpython\Modules\expat\xmltok.c(1,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを Unicode 形式
で保存してください。 [C:\Users\songo\source\repos\cpython\PCbuild\pyexpat.vcxproj]
C:\Users\songo\source\repos\cpython\Modules\_lzmamodule.c(1,1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます 。データの損失を防ぐために、ファイルを Unicode 形式で
保存してください。 [C:\Users\songo\source\repos\cpython\PCbuild\_lzma.vcxproj]
```

These warnings are shown because source code is written in UTF-8 but compiler assume it's encoded in current code page.


I don't know what is the best way to fix the warning, but I can fix it by adding /utf-8 flag.


```
diff --git a/PCbuild/_zoneinfo.vcxproj b/PCbuild/_zoneinfo.vcxproj
index 6e6389c377..4602e45ce5 100644
--- a/PCbuild/_zoneinfo.vcxproj
+++ b/PCbuild/_zoneinfo.vcxproj
@@ -91,6 +91,11 @@
   <PropertyGroup>
     <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
   </PropertyGroup>
+  <ItemDefinitionGroup>
+    <ClCompile>
+      <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
+    </ClCompile>
+  </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\Modules\_zoneinfo.c" />
   </ItemGroup>
```
msg386744 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-09 20:48
The new property should go into PCbuild/pyproject.props, but otherwise seems like an okay change.

It *will* cause any string literals (const char *) to be UTF-8, but they ought to all be ASCII anyway. It shouldn't affect resource files, because those have a code page override in the source files. (Potentially a "#pragma code_page(1252)" might make more sense for our build, but I'm not sure, and I'm just as happy to got to UTF-8 if it doesn't break anything.)
msg386842 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-02-12 00:06
New changeset fedd86df2448370cdf62a229fd6f31dc92daf379 by Inada Naoki in branch 'master':
bpo-43174: Windows: Use /utf-8 compiler option. (GH-24498)
https://github.com/python/cpython/commit/fedd86df2448370cdf62a229fd6f31dc92daf379
msg386843 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-02-12 00:08
May I backport this for Python 3.9?
msg386846 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-12 00:49
I think so, yeah. We shouldn't have any string literals that are non-ASCII, but if we do then it's almost certainly an improvement for them to be UTF-8.
msg386851 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-02-12 04:33
New changeset 68d6bc798b34eccabdfbf94e563273759c4cef1f by Miss Islington (bot) in branch '3.9':
bpo-43174: Windows: Use /utf-8 compiler option. (GH-24498)
https://github.com/python/cpython/commit/68d6bc798b34eccabdfbf94e563273759c4cef1f
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87340
2021-02-12 04:44:41methanesetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.9
2021-02-12 04:33:43methanesetmessages: + msg386851
2021-02-12 02:21:04miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23299
2021-02-12 00:50:00steve.dowersetmessages: + msg386846
2021-02-12 00:08:03methanesetmessages: + msg386843
2021-02-12 00:06:58methanesetmessages: + msg386842
2021-02-10 05:13:09methanesetkeywords: + patch
stage: patch review
pull_requests: + pull_request23287
2021-02-09 20:48:10steve.dowersetmessages: + msg386744
2021-02-09 03:00:28xtreaksetnosy: + paul.moore, tim.golden, steve.dower, zach.ware
components: + Windows
2021-02-09 02:59:02methanecreate