在 Mac OS 10.15 上使用 gn 和 ninja 从源构建电子时出错

Posted

技术标签:

【中文标题】在 Mac OS 10.15 上使用 gn 和 ninja 从源构建电子时出错【英文标题】:errors when building electron from source with gn and ninja on Mac OS 10.15 【发布时间】:2019-11-11 00:45:53 【问题描述】:

目前,我尝试修复电子中的一些可访问性错误。为此,我试图从源头构建电子。来源未经我编辑或更改,因此是原创的。

我按照构建说明从 GitHub 上的官方 repo 中提取了源代码,并且我使用了客户端等等。

这是我在 Mac OS X 10.15 下的终端中的步骤输出:

Christophers-MacBook-Pro:src chpross$ gn gen out/Testing --args="import(\"//electron/build/args/testing.gn\") $GN_EXTRA_ARGS"
Done. Made 11597 targets from 1978 files in 6073ms

Christophers-MacBook-Pro:src chpross$ ninja -C out/Testing electron
ninja: Entering directory `out/Testing'
[8992/26566] CXX obj/services/network/..._cpp_sources/udp_socket.mojom-shared.o^[9026/26566] CXX obj/services/network/...content_security_policy.mojom-shared.o^[9044/26566] CXX obj/services/video_ca...ed_cpp_sources/receiver.mojom-shared.o^[9047/26566] CXX obj/services/video_ca...ared_cpp_sources/device.mojom-shared.o^[9098/26566] CXX obj/v8/torque_generat...itializers/object-fromentries-tq-csa.o^[9160/26566] CXX obj/third_party/blink...nderer/core/inspector/generated/Page.o^[10130/26566] OBJCXX obj/components/vi...tal_context_provider/metal_api_proxy.o
FAILED: obj/components/viz/common/metal_context_provider/metal_api_proxy.o 
/Users/chpross/programmierung/electron-gn/src/electron/external_binaries/sccache ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/components/viz/common/metal_context_provider/metal_api_proxy.o.d -DVIZ_METAL_CONTEXT_PROVIDER_IMPLEMENTATION -DDCHECK_ALWAYS_ON=1 -D_LIBCPP_HAS_NO_ALIGNED_ALLOCATION -DCR_XCODE_VERSION=1120 -DCR_CLANG_REVISION=\"373424-64a362e7-1\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_LIBCPP_ABI_UNSTABLE -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_ENABLE_NODISCARD -DCR_LIBCXX_REVISION=361348 -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DWEBP_EXTERN=extern -DENABLE_IPC_FUZZER -DUSE_EGL -DSK_GL -DSK_HAS_PNG_LIBRARY -DSK_HAS_WEBP_LIBRARY -DSK_USER_CONFIG_HEADER=\"../../skia/config/SkUserConfig.h\" -DSK_HAS_JPEG_LIBRARY -DSK_SUPPORT_GPU=1 -DSK_GPU_WORKAROUNDS_HEADER=\"gpu/config/gpu_driver_bug_workaround_autogen.h\" -DSK_BUILD_FOR_MAC -DSK_METAL -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DUSE_CHROMIUM_ICU=1 -DU_STATIC_IMPLEMENTATION -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE -DUCHAR_TYPE=uint16_t -I../.. -Igen -I../../third_party/libwebp/src -I../../third_party/skia -I../../third_party/boringssl/src/include -I../../third_party/icu/source/common -I../../third_party/icu/source/i18n -I../../third_party/khronos -I../../gpu -I../../third_party/mesa_headers -fno-strict-aliasing -fstack-protector -fcolor-diagnostics -fmerge-all-constants -fcrash-diagnostics-dir=../../tools/clang/crashreports -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -fcomplete-member-pointers -arch x86_64 -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -Xclang -fdebug-compilation-dir -Xclang . -no-canonical-prefixes -Wall -Werror -Wextra -Wimplicit-fallthrough -Wthread-safety -Wextra-semi -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-ignored-pragma-optimize -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-sizeof-array-div -O2 -fno-omit-frame-pointer -gdwarf-4 -g1 -isysroot ../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.10.0 -fvisibility=hidden -Xclang -add-plugin -Xclang find-bad-constructs -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -std=c++14 -stdlib=libc++ -fobjc-call-cxx-cdtors -Wobjc-missing-property-synthesis -fno-exceptions -fno-rtti -fvisibility-inlines-hidden -include obj/components/viz/common/metal_context_provider/precompile.h-mm -c ../../components/viz/common/gpu/metal_api_proxy.mm -o obj/components/viz/common/metal_context_provider/metal_api_proxy.o
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'hasUnifiedMemory' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:353:27: note: property declared here
@property (readonly) BOOL hasUnifiedMemory API_AVAILABLE(macos(10.15), ios(13.0));
                          ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'location' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:368:40: note: property declared here
@property (readonly) MTLDeviceLocation location API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                                       ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'locationNumber' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:377:33: note: property declared here
@property (readonly) NSUInteger locationNumber API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                                ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'maxTransferRate' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:385:31: note: property declared here
@property (readonly) uint64_t maxTransferRate API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                              ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'barycentricCoordsSupported' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:421:64: note: property declared here
@property(readonly, getter=areBarycentricCoordsSupported) BOOL barycentricCoordsSupported API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                                                               ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'supportsShaderBarycentricCoordinates' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:423:27: note: property declared here
@property (readonly) BOOL supportsShaderBarycentricCoordinates API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                          ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'peerGroupID' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:753:31: note: property declared here
@property (readonly) uint64_t peerGroupID API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                              ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'peerIndex' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:760:31: note: property declared here
@property (readonly) uint32_t peerIndex API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                              ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'peerCount' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:766:31: note: property declared here
@property (readonly) uint32_t peerCount API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                              ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: auto property synthesis will not synthesize property 'counterSets' declared in protocol 'MTLDevice' [-Werror,-Wobjc-protocol-property-synthesis]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:782:60: note: property declared here
@property (readonly, nullable) NSArray<id<MTLCounterSet>>* counterSets API_AVAILABLE(macos(10.15)) API_UNAVAILABLE(ios);
                                                           ^
../../components/viz/common/gpu/metal_api_proxy.mm:578:1: note: add a '@synthesize' directive
@end
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: method 'supportsFamily:' in protocol 'MTLDevice' not implemented [-Werror,-Wprotocol]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:659:1: note: method 'supportsFamily:' declared here
- (BOOL)supportsFamily:(MTLGPUFamily)gpuFamily API_AVAILABLE(macos(10.15), ios(13.0));
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: method 'newCounterSampleBufferWithDescriptor:error:' in protocol 'MTLDevice' not implemented [-Werror,-Wprotocol]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:793:1: note: method 'newCounterSampleBufferWithDescriptor:error:' declared here
- (nullable id<MTLCounterSampleBuffer>) newCounterSampleBufferWithDescriptor:(MTLCounterSampleBufferDescriptor*)descriptor
^
../../components/viz/common/gpu/metal_api_proxy.mm:224:17: error: method 'sampleTimestamps:gpuTimestamp:' in protocol 'MTLDevice' not implemented [-Werror,-Wprotocol]
@implementation MTLDeviceProxy
                ^
../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h:803:1: note: method 'sampleTimestamps:gpuTimestamp:' declared here
-(void)sampleTimestamps:(NSUInteger *)cpuTimestamp
^
13 errors generated.
[10139/26566] CXX obj/v8/v8_initializers/code-stub-assembler.o
ninja: build stopped: subcommand failed.

所以不同的忍者目标会产生不同的错误。我觉得这对于一个问题来说太大了,所以如果有人需要这个错误,我可以将它粘贴到一个 pastebin 中。源代码是官方的,但是构建失败,我已经重启了系统,清理了out-dir等等。希望有人知道这里出了什么问题。

【问题讨论】:

快速查看,你匹配xcode sdk版本了吗? 把出现错误的源代码贴出来怎么办? @OJ Kwon:是的,官方说明来自 Xcode 9.4.1 和 macOS sdk 10.13,我现在都试过了。类似的错误。 @***foe 很抱歉,我做不到。我没有更改官方代码。所以,它是原创的,不是我编辑的。 【参考方案1】:

SDK 不兼容 当您尝试构建时,Electron/Chromium 与 MacOSX 10.15 SDK 不兼容。正如

所指出的,所需的版本是 10.14
$ gn args out/Testing --list --short|grep sdk
mac_sdk_min = "10.14"

反对the docs。从较旧的 XCode 版本或通过 GitHub 非正式地下载它

svn checkout https://github.com/phracker/MacOSX-SDKs/tree/master/MacOSX10.14.sdk

并将其设置为对忍者有效,例如通过在src/electron/build/args/testing.gn 中通过mac_sdk_path = "$path_to_sdk_folder" 包含路径。 我恢复了我的更改(参见原始帖子)并删除了out/Testing,丢弃了所有编译结果。可能有一种破坏性较小的方法可以仅重置/重新编译受影响的文件。然后通过gn genregenerate the config 重新编译。

很遗憾,v8_context_snapshot 的错误仍然存​​在:

ACTION //tools/v8_context_snapshot:generate_v8_context_snapshot(//build/toolchain/mac:clang_x64)
FAILED: v8_context_snapshot.bin
python ../../build/gn_run_binary.py ./v8_context_snapshot_generator --output_file=v8_context_snapshot.bin
[1119/152748.970749:FATAL:protected_memory.h(218)] Check failed: SetMemoryReadWrite(&writers, &writers + 1).
0   v8_context_snapshot_generator       0x000000010eda4829 base::debug::CollectStackTrace(void**, unsigned long) + 9
1   v8_context_snapshot_generator       0x000000010ec88dd3 base::debug::StackTrace::StackTrace() + 19
2   v8_context_snapshot_generator       0x000000010ec9b869 logging::LogMessage::~LogMessage() + 233
3   v8_context_snapshot_generator       0x000000010f1337df base::AutoWritableMemory::AutoWritableMemory(void*, void*) + 239
4   v8_context_snapshot_generator       0x000000010f133421 MojoEmbedderSetSystemThunks(MojoSystemThunks const*) + 257
5   v8_context_snapshot_generator       0x000000010c135c16 main + 86
6   libdyld.dylib                       0x00007fff6a0ed3d5 start + 1

./v8_context_snapshot_generator failed with exit code -5
ninja: build stopped: subcommand failed.

另一种选择是等到上游修复它,正如here 指出的那样,这已经发生了。或者使用以下第一个更改自己实施必要的更改,但还需要更多。


原帖

Chromium 有一个 MTLDeviceProxy

包装对 MTLDevice 的所有调用 [并] 向 GPU 看门狗报告进度。

不幸的是,它缺少MTLDevice protocol 所需的属性 那个 Clang can't auto-synthesize. 所以我们在components/viz/common/gpu/metal_api_proxy.mm中明确地合成它们:

@implementation MTLDeviceProxy
- (id)initWithDevice:(id<MTLDevice>)device 
  if (self = [super init]) 
    device_.reset(device, base::scoped_policy::RETAIN);
    libraryCache_ = std::make_unique<MTLLibraryCache>();
  
  return self;


// add synthesized properties here
@synthesize hasUnifiedMemory;
@synthesize location;
@synthesize locationNumber;
@synthesize maxTransferRate;
@synthesize barycentricCoordsSupported;
@synthesize supportsShaderBarycentricCoordinates;
@synthesize peerGroupID;
@synthesize peerIndex;
@synthesize peerCount;
@synthesize counterSets;

还缺少三个抽象方法。 在结尾之前插入这三个包装器:

PROXY_METHOD1(BOOL, supportsFamily, MTLGPUFamily)
PROXY_METHOD2_SLOW(nullable id<MTLCounterSampleBuffer>,
                   newCounterSampleBufferWithDescriptor,
                   MTLCounterSampleBufferDescriptor*,
                   error,
                   NSError**)
PROXY_METHOD2_SLOW(void,
               sampleTimestamps,
               NSUInteger *,
               gpuTimestamp,
               NSUInteger *)

#endif
#pragma clang diagnostic pop

我想知道这些属性和方法是如何被遗忘的,以及为什么现在会出现这个问题。 编译愉快!

【讨论】:

所以,谢谢,但我认为问题比我想象的要大。我实现了这些更改,现在它导致了其他错误,即某些委托未实现。现在在 /components/storage_monitor/image_capture_device.mm。我不知道这是来自电子、铬还是简单的我的机器/系统的问题 嗨@Christopher 当我尝试构建铬版本 76.0.3809.146 时,我在这里遇到了同样的问题。你设法解决了这个问题吗? @TonyG:不,我还没有找到解决方案。也许我们应该打开一个错误报告 @Christopher 您现在面临的问题..我设法解决了许多问题。 @TonyG:v8_context_snapshot_generator 有问题。带有protected_memory.h的东西。【参考方案2】:

Chromium 似乎已经更新了 macOS 10.15 的代码。 您可以在此处找到更新的代码。 https://github.com/chromium/chromium/commit/961e7821b9356445f48e5ce2c077c40c2c6b2309

【讨论】:

以上是关于在 Mac OS 10.15 上使用 gn 和 ninja 从源构建电子时出错的主要内容,如果未能解决你的问题,请参考以下文章

在VMware上安装MAC OS10.15最新版本并安装Xcode11.4教程(所有坑已经走过)

Mac OS X 10.15 编译和安装 Nginx

mac os 10.15 virtualBox6.0.12崩溃

MAC OS 10.15 Lucene 源码分析环境搭建

MAC OS 10.15 挂载ntfs文件系统并设置自动挂载RW模式.

Mac OS 是啥?