自从electron-builder升级到电子10.1.2之后,我对有了一个问题。我的构建现在在为keyboard-layout重建时失败了。重建只对Windows失败,而不针对Mac。我不知道从哪里开始这个问题,所以我在这里问:)。
我的设置:
当我将电子从9.0.0更新到10.1.2时,问题就开始了。其他什么都没变。
问题:
当使用命令调用electron-builder时,keyboard-layout的重建作为步骤之一被调用,如下所示:
> keyboard-layout@2.0.16 install C:\Users\<me>\<dir1>\<dir2>\dist\node_modules\keyboard-layout
> node-gyp rebuild但以下几个方面都没有做到:
...
win_delay_load_hook.cc
c:\users\<me>\.electron-gyp\10.1.2\include\node\v8.h(5378): error C2220: warning treated as error - no 'object' file generated (compiling source file ..\src\keyboard-layout-manager-windows.cc) [C:\Users\<me>\<dir1>\<dir2>\dist\node_modules\keyboard-layout\build\keyboard-layout-manager.vcxproj]
c:\users\<me>\.electron-gyp\10.1.2\include\node\v8.h(5378): warning C4309: 'static_cast': truncation of constant value (compiling source file ..\src\keyboard-layout-manager-windows.cc) [C:\Users\<me>\<dir1>\<dir2>\dist\node_modules\keyboard-layout\build\keyboard-layout-manager.vcxproj]
c:\users\<me>\.electron-gyp\10.1.2\include\node\v8.h(5378): error C2220: warning treated as error - no 'object' file generated (compiling source file ..\src\keyboard-layout-manager.cc) [C:\Users\<me>\<dir1>\<dir2>\dist\node_modules\keyboard-layout\build\keyboard-layout-manager.vcxproj]
c:\users\<me>\.electron-gyp\10.1.2\include\node\v8.h(5378): warning C4309: 'static_cast': truncation of constant value (compiling source file ..\src\keyboard-layout-manager.cc) [C:\Users\<me>\<dir1>\<dir2>\dist\node_modules\keyboard-layout\build\keyboard-layout-manager.vcxproj]
Done Building Project "C:\Users\<me>\<dir1>\<dir2>\dist\node_modules\keyboard-layout\build\keyboard-layout-manager.vcxproj" (default targets) -- FAILED.
Done Building Project "C:\Users\<me>\<dir1>\<dir2>\dist\node_modules\keyboard-layout\build\binding.sln" (default targets) -- FAILED.
Build FAILED.
...我尝试过的没有帮助的东西:
将binding.gyp中的node_modules/keyboard-layout更改为(标记为<---的chnage):
['OS=="win"', {
"sources": [
"src/keyboard-layout-manager-windows.cc",
],
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1, # /EHsc
'WarnAsError': 'false', # <--- I chnaged this from true to false
},
},
'msvs_disabled_warnings': [
4018, # signed/unsigned mismatch
2220, # <--- I added this
4244, # conversion from 'type1' to 'type2', possible loss of data
4267, # conversion from 'size_t' to 'type', possible loss of data
4302, # 'type cast': truncation from 'HKL' to 'UINT'
4311, # 'type cast': pointer truncation from 'HKL' to 'UINT'
4530, # C++ exception handler used, but unwind semantics are not enabled
4506, # no definition for inline function
4577, # 'noexcept' used with no exception handling mode specified
4996, # function was declared deprecated
],
}], # OS=="win"我尝试过的帮助:
电子10.x.y 将v8更新为8.5 (电子10.0.0释放说明),并查看导致错误(...\.electron-gyp\10.1.2\include\node\v8.h(5378))的线条,我看到如下内容:
static constexpr size_t kMaxLength =
internal::kApiSystemPointerSize == 4
? internal::kSmiMaxValue
: static_cast<size_t>(uint64_t{1} << 32); <--- Line 5378当我比较来自...\.electron-gyp\10.1.2\include\node\v8.h和...\.electron-gyp\9.0.0\include\node\v8.h的v8.h文件时,在这一行中有一个变化。
旧版本中的同一行:
static constexpr size_t kMaxLength = internal::kApiSystemPointerSize == 4
? internal::kSmiMaxValue
: 0xFFFFFFFF;如果我将static_cast<size_t>(uint64_t{1} << 32)转换为0xFFFFFFFF,build将继承.
我的理解到此为止。
0xFFFFFFFF中的结果发布于 2020-10-05 13:23:03
我所做的尝试并没有帮助:
'WarnAsError': 'false'应该能做到这一点;但是,报告了两个不同文件(..\src\keyboard-layout-manager.cc和..\src\keyboard-layout-manager-windows.cc)的错误,因此您必须修改这两个文件的构建规则。
禁用警告也会有帮助,但它必须是警告4309 (而不是2220),您需要禁用。同样,对于这两个文件(或者只是整个编译过程),您都必须这样做。
新旧线理论上不一样吗?一个移位32位导致
0xFFFFFFFF?
不,1 << 32 == 0x100000000 == 0xFFFFFFFF + 1)。
我能做些什么来解决这个问题?
'WarnAsError'应该会有帮助这一变化的原因是什么?
V8现在允许具有最多2**32元素的TypedArrays,这比以前多了一个元素。
为什么这个问题只出现在Windows上?
因为警告是编译器特有的,而且MSVC只在Windows上使用.
奇怪的是,你一开始就看到了这个错误。您使用--x64进行编译;如果这样做的话,您应该编译一个64位构建,其中internal::kApiSystemPointerSize == 8和size_t有64位,就像uint64_t一样,所以在表达式static_cast<size_t>(uint64_t{1} << 32);中,什么都不会被截断。
即使出于任何原因,这个构建试图创建一个32位的V8构建,那么另一个分支应该被接受(internal::kApiSystemPointerSize == 4),编译器应该足够聪明,不要警告一个静态死掉的分支。
无论如何,这似乎是编译器的错误/限制。因此,适当的解决办法是更新编译器或禁用错误警告。
https://stackoverflow.com/questions/64204193
复制相似问题