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

errors when building electron from source with gn and ninja on Mac OS 10.15

目前,我正在尝试修复 electron 中的一些可访问性错误。为此,我曾尝试从源头构建电子。来源未经我编辑或更改,所以它是原始的。

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

这是我在 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等等。希望有人知道这里出了什么问题。

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

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

不幸的是,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.

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


原版post

Chromium 有一个 MTLDeviceProxy 其中

wraps all calls to an MTLDevice [and] reports progress to the GPU watchdog.

不幸的是,它缺少 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

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

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