From 3db0198f47f115b510370916c3fca2f38ea068b4 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Sun, 22 May 2022 21:19:18 +0800 Subject: [PATCH] Upgrade to v8 10.0.139.9 with tools support (#29) - upgrade to v8 10.0.139.9 - add mkcodecache tools - archive mksnapshot tools --- .github/workflows/android.yml | 21 +- .github/workflows/ios.yml | 7 +- .github/workflows/tools_macos_android.yml | 59 ++++++ .gitignore | 6 + .vscode/settings.json | 3 + README.md | 2 +- mkcodecache/mkcodecache.cc | 130 ++++++++++++ package.json | 12 +- packages/v8-android-jit-nointl/package.json | 2 +- packages/v8-android-jit/package.json | 2 +- packages/v8-android-nointl/package.json | 2 +- packages/v8-android-tools-linux/package.json | 24 +++ packages/v8-android-tools-macos/package.json | 24 +++ .../v8-android-tools-windows/package.json | 24 +++ packages/v8-android/package.json | 2 +- patches/android_build_break_v91.patch | 26 --- patches/custom_timezone.patch | 13 +- patches/fix_for_bottom_sheet.patch | 29 +++ patches/ios_build_error_forward.patch | 12 -- patches/mkcodecache.patch | 36 ++++ patches/system_xcode_build_error.patch | 13 ++ patches/v8_97_android_build_error.patch | 13 ++ patches/v8_97_android_unwind_link_error.patch | 47 ++++ patches/v8_shared_library.patch | 30 +-- patches/v8_shared_library_ios.patch | 80 +++---- scripts/archive.sh | 17 +- scripts/build.sh | 111 ++++++++-- scripts/bump.py | 48 ++--- scripts/env.sh | 5 +- scripts/patch.sh | 48 ++++- scripts/publish.py | 200 +++++++++++++++--- scripts/setup.sh | 34 ++- scripts/start.sh | 10 +- 33 files changed, 854 insertions(+), 238 deletions(-) create mode 100644 .github/workflows/tools_macos_android.yml create mode 100644 .vscode/settings.json create mode 100644 mkcodecache/mkcodecache.cc create mode 100644 packages/v8-android-tools-linux/package.json create mode 100644 packages/v8-android-tools-macos/package.json create mode 100644 packages/v8-android-tools-windows/package.json delete mode 100644 patches/android_build_break_v91.patch create mode 100644 patches/fix_for_bottom_sheet.patch delete mode 100644 patches/ios_build_error_forward.patch create mode 100644 patches/mkcodecache.patch create mode 100644 patches/system_xcode_build_error.patch create mode 100644 patches/v8_97_android_build_error.patch create mode 100644 patches/v8_97_android_unwind_link_error.patch diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 34786f1..3fdec71 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -29,7 +29,7 @@ jobs: # sudo sh -c "chmod 777 $GITHUB_WORKSPACE/../../_temp" sudo sh -c "chmod 777 /home" - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Ubuntu environment run: | @@ -41,7 +41,7 @@ jobs: - name: Export settings from npm package run: npm run export_npm_env - # - uses: actions/cache@v2 + # - uses: actions/cache@v3 # with: # path: v8 # key: android-v8-${{ env.V8_VERSION }}-${{ env.CACHE_KEY_SUFFIX }} @@ -73,11 +73,12 @@ jobs: - name: Archive run: | scripts/archive.sh android + tar -cvf dist.tar dist - - uses: actions/upload-artifact@master + - uses: actions/upload-artifact@v3 with: name: dist-${{ matrix.variant }} - path: dist + path: dist.tar ############################################################### @@ -108,7 +109,7 @@ jobs: # sudo sh -c "chmod 777 $GITHUB_WORKSPACE/../../_temp" # sudo sh -c "chmod 777 /home" # -# - uses: actions/checkout@v2 +# - uses: actions/checkout@v3 # # - name: Setup Ubuntu environment # run: | @@ -120,7 +121,7 @@ jobs: # - name: Export settings from npm package # run: npm run export_npm_env # -# # - uses: actions/cache@v1 +# # - uses: actions/cache@v3 # # id: v8-source-cache # # with: # # path: v8 @@ -140,7 +141,7 @@ jobs: # run: | # scripts/build.sh android arm # -# - uses: actions/upload-artifact@master +# - uses: actions/upload-artifact@v3 # with: # name: build-intl-arm # path: build @@ -174,7 +175,7 @@ jobs: # sudo sh -c "chmod 777 $GITHUB_WORKSPACE/../../_temp" # sudo sh -c "chmod 777 /home" # -# - uses: actions/checkout@v2 +# - uses: actions/checkout@v3 # # - name: Setup Ubuntu environment # run: | @@ -186,7 +187,7 @@ jobs: # - name: Export settings from npm package # run: npm run export_npm_env # -# # - uses: actions/cache@v1 +# # - uses: actions/cache@v3 # # id: v8-source-cache # # with: # # path: v8 @@ -206,7 +207,7 @@ jobs: # run: | # scripts/build.sh android ${{ env.arch }} # -# - uses: actions/upload-artifact@master +# - uses: actions/upload-artifact@v3 # with: # name: build-${{ matrix.variant }}-${{ matrix.arch }} # path: build diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 8a366f0..2922d7c 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -10,7 +10,7 @@ jobs: NO_JIT: true steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Export settings from npm package run: | @@ -29,8 +29,9 @@ jobs: run: | scripts/build.sh ios scripts/archive.sh ios + tar -cvf dist.tar dist - - uses: actions/upload-artifact@master + - uses: actions/upload-artifact@v3 with: name: dist - path: dist + path: dist.tar diff --git a/.github/workflows/tools_macos_android.yml b/.github/workflows/tools_macos_android.yml new file mode 100644 index 0000000..26fb92d --- /dev/null +++ b/.github/workflows/tools_macos_android.yml @@ -0,0 +1,59 @@ +name: v8-android tools builder for macos host + +on: [push] + +env: + CACHE_KEY_SUFFIX: v2 + +jobs: + macos: + runs-on: macOS-latest + + strategy: + matrix: + variant: [intl, nointl, jit-intl, jit-nointl] + + env: + NO_INTL: ${{ contains(matrix.variant, 'nointl') }} + NO_JIT: ${{ !contains(matrix.variant, 'jit') }} + TOOLS_ONLY: true + + steps: + - uses: actions/checkout@v3 + + - name: Export settings from npm package + run: npm run export_npm_env + + - name: Setup V8 build environment + run: | + brew install coreutils + scripts/setup.sh -r ${{ env.V8_VERSION }} macos_android + + - name: Patch V8 + run: scripts/patch.sh macos_android + + # - name: Build arm + # run: | + # scripts/build.sh macos_android arm + # + # - name: Build x86 + # run: | + # scripts/build.sh macos_android x86 + + - name: Build arm64 + run: | + scripts/build.sh macos_android arm64 + + - name: Build x64 + run: | + scripts/build.sh macos_android x64 + + - name: Archive + run: | + scripts/archive.sh macos_android + tar -cvf dist.tar dist + + - uses: actions/upload-artifact@v3 + with: + name: macos-tools-${{ matrix.variant }} + path: dist.tar diff --git a/.gitignore b/.gitignore index 5fa112d..7910be1 100644 --- a/.gitignore +++ b/.gitignore @@ -448,3 +448,9 @@ gradle-app.setting .cipd/* .gclient .gclient_entries + +# publish archives +mkcodecache +mksnapshot +*.bin +*.zip diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0ceb6db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.formatting.provider": "black" +} diff --git a/README.md b/README.md index 077fe01..3e83108 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To integrate with React Native, please check [react-native-v8](https://github.co 1. Single libv8android.so (or libv8.so on iOS) file. 2. Support i18n and JavaScript [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl). 3. V8 Lite mode (JIT-less mode) https://v8.dev/blog/v8-lite -4. Build by Android official NDK r19c which prevent potential ABI incompatible issue to integrate with React Native. +4. Build by Android official NDK r21e which prevent potential ABI incompatible issue to integrate with React Native. ## Build Guides diff --git a/mkcodecache/mkcodecache.cc b/mkcodecache/mkcodecache.cc new file mode 100644 index 0000000..944934e --- /dev/null +++ b/mkcodecache/mkcodecache.cc @@ -0,0 +1,130 @@ +// Copyright 2006-2008 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "include/libplatform/libplatform.h" +#include "include/v8-initialization.h" +#include "include/v8-message.h" +#include "include/v8-script.h" +#include "src/base/platform/platform.h" + +#include + +namespace v8 { + +namespace { + +// Reads a file into a v8 string. +Local ReadFile(Isolate* isolate, const char* name, + bool should_throw) { + std::unique_ptr file( + base::OS::MemoryMappedFile::open( + name, base::OS::MemoryMappedFile::FileMode::kReadOnly)); + if (!file) { + if (should_throw) { + std::ostringstream oss; + oss << "Error loading file: \"" << name << '"'; + isolate->ThrowError( + v8::String::NewFromUtf8(isolate, oss.str().c_str()).ToLocalChecked()); + } + return Local(); + } + + int size = static_cast(file->size()); + char* chars = static_cast(file->memory()); + Local result = String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size) + .ToLocalChecked(); + return result; +} + +} // namespace + +} // namespace v8 + +int main(int argc, char** argv) { + if (argc < 2) { + ::printf("Usage: %s script_file\n", argv[0]); + exit(1); + } + + v8::base::EnsureConsoleOutput(); + v8::V8::InitializeICUDefaultLocation(argv[0]); + std::unique_ptr platform = v8::platform::NewDefaultPlatform(); + v8::V8::InitializePlatform(platform.get()); + v8::V8::SetFlagsFromString("--nolazy"); + v8::V8::Initialize(); + v8::V8::InitializeExternalStartupData(argv[0]); + + v8::Isolate::CreateParams createParams; + auto arrayBufferAllocator = + std::unique_ptr(v8::ArrayBuffer::Allocator::NewDefaultAllocator()); + createParams.array_buffer_allocator = arrayBufferAllocator.get(); + v8::Isolate* isolate = v8::Isolate::New(createParams); + v8::HandleScope handle_scope(isolate); + + + v8::Local source = v8::ReadFile(isolate, argv[1], false); + + if (argc == 2) { + v8::ScriptOrigin origin = v8::ScriptOrigin(isolate, v8::String::NewFromUtf8Literal(isolate, "(mkcodecache)")); + + v8::ScriptCompiler::Source scriptSource(source, origin); + // v8::Local unboundScript = v8::ScriptCompiler::CompileUnboundScript(isolate, &scriptSource, v8::ScriptCompiler::kEagerCompile).ToLocalChecked(); + v8::Local unboundScript = v8::ScriptCompiler::CompileUnboundScript(isolate, &scriptSource, v8::ScriptCompiler::kNoCompileOptions).ToLocalChecked(); + v8::ScriptCompiler::CachedData *cachedData = v8::ScriptCompiler::CreateCodeCache(unboundScript); + ::printf("cache data size %d\n", cachedData->length); + + FILE* file = v8::base::Fopen("v8codecache.bin", "wb"); + if (file) { + fwrite(cachedData->data, 1, cachedData->length, file); + v8::base::Fclose(file); + } + } else { + v8::ScriptOrigin origin = v8::ScriptOrigin(isolate, v8::String::NewFromUtf8Literal(isolate, "(mkcodecache)")); + std::unique_ptr cachedData; + FILE* file = v8::base::Fopen("v8codecache.bin", "rb"); + if (file) { + fseek(file, 0, SEEK_END); + size_t size = ftell(file); + uint8_t *buffer = new uint8_t[size]; + rewind(file); + + if (fread(buffer, 1, size, file) != size) { + ::printf("ooxx fread error\n"); + } + v8::base::Fclose(file); + + cachedData = std::make_unique( + buffer, + static_cast(size), + v8::ScriptCompiler::CachedData::BufferPolicy::BufferOwned); + } + + auto begin = std::chrono::high_resolution_clock::now(); + + v8::Local context = v8::Context::New(isolate); + v8::Context::Scope context_scope(context); + + v8::ScriptCompiler::CachedData *cachedDataPtr = cachedData.release(); + v8::ScriptCompiler::Source scriptSource(source, origin, cachedDataPtr); + // v8::ScriptCompiler::Source scriptSource(source, origin, nullptr); + v8::Local compiledScript; + if (!v8::ScriptCompiler::Compile(context, &scriptSource, v8::ScriptCompiler::kConsumeCodeCache).ToLocal(&compiledScript)) { + // if (!v8::ScriptCompiler::Compile(context, &scriptSource, v8::ScriptCompiler::kNoCompileOptions).ToLocal(&compiledScript)) { + ::printf("ooxx error\n"); + } + + if (cachedDataPtr->rejected) { + ::printf("ooxx rejected\n"); + } + + auto end = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(end - begin); + ::printf("ooxx compile time: %lld\n", static_cast(duration.count())); + } + + v8::V8::Dispose(); + v8::V8::DisposePlatform(); + + return 0; +} diff --git a/package.json b/package.json index 6799f9a..e698a6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "9.93.0", + "version": "10.100.0", "workspaces": [ "packages/*" ], @@ -8,13 +8,13 @@ "clean": "rm -rf dist; rm -rf build; rm -rf v8/out.v8.*", "export_npm_env": "./scripts/export_npm_env.sh", "setup": "bash -c '. ./scripts/export_npm_env.sh && ./scripts/setup.sh android'", - "start": "bash -c '. ./scripts/export_npm_env.sh && ./scripts/start.sh android'", - "setup_mksnapshot": "bash -c '. ./scripts/export_npm_env.sh && MKSNAPSHOT_ONLY=1 ./scripts/setup.sh android'", - "start_mksnapshot": "bash -c '. ./scripts/export_npm_env.sh && MKSNAPSHOT_ONLY=1 ./scripts/start.sh android'", "setup_ios": "bash -c '. ./scripts/export_npm_env.sh && ./scripts/setup.sh ios'", - "start_ios": "bash -c '. ./scripts/export_npm_env.sh && ./scripts/start.sh ios'" + "setup_macos_android": "bash -c '. ./scripts/export_npm_env.sh && ./scripts/setup.sh macos_android'", + "start": "bash -c '. ./scripts/export_npm_env.sh && ./scripts/start.sh android'", + "start_ios": "bash -c '. ./scripts/export_npm_env.sh && ./scripts/start.sh ios'", + "start_tools_macos_android": "bash -c '. ./scripts/export_npm_env.sh && TOOLS_ONLY=true ./scripts/start.sh macos_android'" }, "config": { - "V8": "9.3.345.16" + "V8": "10.0.139.9" } } diff --git a/packages/v8-android-jit-nointl/package.json b/packages/v8-android-jit-nointl/package.json index d21e410..53e78ab 100644 --- a/packages/v8-android-jit-nointl/package.json +++ b/packages/v8-android-jit-nointl/package.json @@ -1,6 +1,6 @@ { "name": "v8-android-jit-nointl", - "version": "9.93.0", + "version": "10.100.0", "description": "Pre-build version of V8 to be used by React Native apps", "repository": { "type": "git", diff --git a/packages/v8-android-jit/package.json b/packages/v8-android-jit/package.json index bc5bb7f..2b6eb3c 100644 --- a/packages/v8-android-jit/package.json +++ b/packages/v8-android-jit/package.json @@ -1,6 +1,6 @@ { "name": "v8-android-jit", - "version": "9.93.0", + "version": "10.100.0", "description": "Pre-build version of V8 to be used by React Native apps", "repository": { "type": "git", diff --git a/packages/v8-android-nointl/package.json b/packages/v8-android-nointl/package.json index a28665f..e3b38cc 100644 --- a/packages/v8-android-nointl/package.json +++ b/packages/v8-android-nointl/package.json @@ -1,6 +1,6 @@ { "name": "v8-android-nointl", - "version": "9.93.0", + "version": "10.100.0", "description": "Pre-build version of V8 to be used by React Native apps (Non Intl supported version)", "repository": { "type": "git", diff --git a/packages/v8-android-tools-linux/package.json b/packages/v8-android-tools-linux/package.json new file mode 100644 index 0000000..47a5de7 --- /dev/null +++ b/packages/v8-android-tools-linux/package.json @@ -0,0 +1,24 @@ +{ + "name": "v8-android-tools-linux", + "version": "10.100.0", + "description": "Tools for v8-android", + "repository": { + "type": "git", + "url": "git+https://github.com/Kudo/v8-android-buildscripts.git", + "directory": "packages/v8-android-tools-linux" + }, + "keywords": [ + "react-native", + "android", + "v8", + "tools" + ], + "license": "BSD-2-Clause", + "bugs": { + "url": "https://github.com/Kudo/v8-android-buildscripts/issues" + }, + "homepage": "https://github.com/Kudo/v8-android-buildscripts#readme", + "files": [ + "v8-android*" + ] +} diff --git a/packages/v8-android-tools-macos/package.json b/packages/v8-android-tools-macos/package.json new file mode 100644 index 0000000..be61ad9 --- /dev/null +++ b/packages/v8-android-tools-macos/package.json @@ -0,0 +1,24 @@ +{ + "name": "v8-android-tools-macos", + "version": "10.100.0", + "description": "Tools for v8-android", + "repository": { + "type": "git", + "url": "git+https://github.com/Kudo/v8-android-buildscripts.git", + "directory": "packages/v8-android-tools-macos" + }, + "keywords": [ + "react-native", + "android", + "v8", + "tools" + ], + "license": "BSD-2-Clause", + "bugs": { + "url": "https://github.com/Kudo/v8-android-buildscripts/issues" + }, + "homepage": "https://github.com/Kudo/v8-android-buildscripts#readme", + "files": [ + "v8-android*" + ] +} diff --git a/packages/v8-android-tools-windows/package.json b/packages/v8-android-tools-windows/package.json new file mode 100644 index 0000000..0f601c1 --- /dev/null +++ b/packages/v8-android-tools-windows/package.json @@ -0,0 +1,24 @@ +{ + "name": "v8-android-tools-windows", + "version": "0.0.0", + "description": "Tools for v8-android", + "repository": { + "type": "git", + "url": "git+https://github.com/Kudo/v8-android-buildscripts.git", + "directory": "packages/v8-android-tools-windows" + }, + "keywords": [ + "react-native", + "android", + "v8", + "tools" + ], + "license": "BSD-2-Clause", + "bugs": { + "url": "https://github.com/Kudo/v8-android-buildscripts/issues" + }, + "homepage": "https://github.com/Kudo/v8-android-buildscripts#readme", + "files": [ + "v8-android*" + ] +} diff --git a/packages/v8-android/package.json b/packages/v8-android/package.json index bc2b69e..da5b043 100644 --- a/packages/v8-android/package.json +++ b/packages/v8-android/package.json @@ -1,6 +1,6 @@ { "name": "v8-android", - "version": "9.93.0", + "version": "10.100.0", "description": "Pre-build version of V8 to be used by React Native apps", "repository": { "type": "git", diff --git a/patches/android_build_break_v91.patch b/patches/android_build_break_v91.patch deleted file mode 100644 index 865ae06..0000000 --- a/patches/android_build_break_v91.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff --git a/src/compiler/backend/ia32/instruction-selector-ia32.cc b/src/compiler/backend/ia32/instruction-selector-ia32.cc -index 033a566e11..1b342dc2f6 100644 ---- a/src/compiler/backend/ia32/instruction-selector-ia32.cc -+++ b/src/compiler/backend/ia32/instruction-selector-ia32.cc -@@ -2996,9 +2996,6 @@ void InstructionSelector::VisitI8x16Shuffle(Node* node) { - } - Emit(opcode, 1, &dst, input_count, inputs, temp_count, temps); - } --#else --void InstructionSelector::VisitI8x16Shuffle(Node* node) { UNREACHABLE(); } --#endif // V8_ENABLE_WEBASSEMBLY - - void InstructionSelector::VisitI8x16Swizzle(Node* node) { - InstructionCode op = kIA32I8x16Swizzle; -@@ -3020,6 +3017,11 @@ void InstructionSelector::VisitI8x16Swizzle(Node* node) { - arraysize(temps), temps); - } - -+#else -+void InstructionSelector::VisitI8x16Shuffle(Node* node) { UNREACHABLE(); } -+void InstructionSelector::VisitI8x16Swizzle(Node* node) { UNREACHABLE(); } -+#endif // V8_ENABLE_WEBASSEMBLY -+ - namespace { - void VisitPminOrPmax(InstructionSelector* selector, Node* node, - ArchOpcode opcode) { diff --git a/patches/custom_timezone.patch b/patches/custom_timezone.patch index 60ff544..f9a7c1c 100644 --- a/patches/custom_timezone.patch +++ b/patches/custom_timezone.patch @@ -1,8 +1,8 @@ -diff --git a/include/v8.h b/include/v8.h -index 692e53b809..935db182de 100644 ---- a/include/v8.h -+++ b/include/v8.h -@@ -9207,7 +9207,7 @@ class V8_EXPORT Isolate { +diff --git a/include/v8-isolate.h b/include/v8-isolate.h +index 32b53f1b42..1ad04ba308 100644 +--- a/include/v8-isolate.h ++++ b/include/v8-isolate.h +@@ -1601,7 +1601,7 @@ class V8_EXPORT Isolate { * sandbox, the host time zone has to be detected outside the sandbox before * calling DateTimeConfigurationChangeNotification function. */ @@ -11,7 +11,7 @@ index 692e53b809..935db182de 100644 /** * Notification that the embedder has changed the time zone, daylight savings -@@ -9220,7 +9220,8 @@ class V8_EXPORT Isolate { +@@ -1614,7 +1614,8 @@ class V8_EXPORT Isolate { * the performance of date operations. */ void DateTimeConfigurationChangeNotification( @@ -195,4 +195,3 @@ index 9b8ad9fc95..4778408edd 100644 + } } } - diff --git a/patches/fix_for_bottom_sheet.patch b/patches/fix_for_bottom_sheet.patch new file mode 100644 index 0000000..8fddfdd --- /dev/null +++ b/patches/fix_for_bottom_sheet.patch @@ -0,0 +1,29 @@ +diff --git a/src/objects/objects.cc b/src/objects/objects.cc +index c2c9fe36c5..3dc2b080f6 100644 +--- a/src/objects/objects.cc ++++ b/src/objects/objects.cc +@@ -2510,12 +2510,6 @@ Maybe Object::SetPropertyInternal(LookupIterator* it, + Maybe result = + JSObject::SetPropertyWithInterceptor(it, should_throw, value); + if (result.IsNothing() || result.FromJust()) return result; +- // Assuming that the callback have side effects, we use +- // Object::SetSuperProperty() which works properly regardless on +- // whether the property was present on the receiver or not when +- // storing to the receiver. +- // Proceed lookup from the next state. +- it->Next(); + } else { + Maybe maybe_attributes = + JSObject::GetPropertyAttributesWithInterceptor(it); +@@ -2536,8 +2530,10 @@ Maybe Object::SetPropertyInternal(LookupIterator* it, + // property to the receiver. + it->NotFound(); + } ++ return Object::SetSuperProperty(it, value, store_origin, ++ should_throw); + } +- return Object::SetSuperProperty(it, value, store_origin, should_throw); ++ break; + } + + case LookupIterator::ACCESSOR: { diff --git a/patches/ios_build_error_forward.patch b/patches/ios_build_error_forward.patch deleted file mode 100644 index 7483341..0000000 --- a/patches/ios_build_error_forward.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/include/cppgc/allocation.h b/include/cppgc/allocation.h -index b06d9d7020..d75f1a9729 100644 ---- a/include/cppgc/allocation.h -+++ b/include/cppgc/allocation.h -@@ -10,6 +10,7 @@ - #include - #include - #include -+#include - - #include "cppgc/custom-space.h" - #include "cppgc/internal/api-constants.h" diff --git a/patches/mkcodecache.patch b/patches/mkcodecache.patch new file mode 100644 index 0000000..7497788 --- /dev/null +++ b/patches/mkcodecache.patch @@ -0,0 +1,36 @@ +diff --git a/BUILD.gn b/BUILD.gn +index 19731feebe..66f28d7313 100644 +--- a/BUILD.gn ++++ b/BUILD.gn +@@ -5670,6 +5681,31 @@ if (current_toolchain == v8_generator_toolchain) { + } + } + ++ ++group("mkcodecache_group") { ++ deps = [ ":mkcodecache($v8_generator_toolchain)" ] ++} ++ ++if (current_toolchain == v8_generator_toolchain) { ++ v8_executable("mkcodecache") { ++ visibility = [ ":*" ] # Only targets in this file can depend on this. ++ ++ sources = [ ++ "src/mkcodecache/mkcodecache.cc", ++ ] ++ ++ configs = [ ":internal_config" ] ++ ++ deps = [ ++ ":v8", ++ ":v8_libbase", ++ ":v8_libplatform", ++ ":v8_tracing", ++ "//build/win:default_exe_manifest", ++ ] ++ } ++} ++ + if (current_toolchain == v8_snapshot_toolchain) { + v8_executable("mksnapshot") { + visibility = [ ":*" ] # Only targets in this file can depend on this. diff --git a/patches/system_xcode_build_error.patch b/patches/system_xcode_build_error.patch new file mode 100644 index 0000000..acf8c23 --- /dev/null +++ b/patches/system_xcode_build_error.patch @@ -0,0 +1,13 @@ +diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn +index bc3de06d0..1e96de22c 100644 +--- a/build/config/compiler/BUILD.gn ++++ b/build/config/compiler/BUILD.gn +@@ -1254,7 +1254,7 @@ config("compiler_deterministic") { + # different build directory like "out/feature_a" and "out/feature_b" if + # we build same files with same compile flag. + # Other paths are already given in relative, no need to normalize them. +- if (is_nacl) { ++ if (is_nacl || (is_ios && use_system_xcode)) { + # TODO(https://crbug.com/1231236): Use -ffile-compilation-dir= here. + cflags += [ + "-Xclang", diff --git a/patches/v8_97_android_build_error.patch b/patches/v8_97_android_build_error.patch new file mode 100644 index 0000000..773c56c --- /dev/null +++ b/patches/v8_97_android_build_error.patch @@ -0,0 +1,13 @@ +diff --git a/BUILD.gn b/BUILD.gn +index bca5b5356b..5e0147d642 100644 +--- a/BUILD.gn ++++ b/BUILD.gn +@@ -1237,6 +1235,8 @@ config("toolchain") { + + # TODO(v8:12245): Fix shadowing instances and remove. + "-Wno-shadow", ++ ++ "-Wno-deprecated-copy-with-user-provided-copy", + ] + + if (v8_current_cpu != "mips" && v8_current_cpu != "mipsel") { diff --git a/patches/v8_97_android_unwind_link_error.patch b/patches/v8_97_android_unwind_link_error.patch new file mode 100644 index 0000000..ab38e6c --- /dev/null +++ b/patches/v8_97_android_unwind_link_error.patch @@ -0,0 +1,47 @@ +diff --git a/build/config/android/BUILD.gn b/build/config/android/BUILD.gn +index 4fc5565e2..c48c53536 100644 +--- a/build/config/android/BUILD.gn ++++ b/build/config/android/BUILD.gn +@@ -41,12 +41,18 @@ config("compiler") { + } + + ldflags = [ ++ # Don't allow visible symbols from libgcc or libc++ to be ++ # re-exported. ++ "-Wl,--exclude-libs=libgcc.a", ++ + # Don't allow visible symbols from libraries that contain + # assembly code with symbols that aren't hidden properly. + # http://crbug.com/448386 + "-Wl,--exclude-libs=libvpx_assembly_arm.a", + ] + ++ # TODO(crbug.com/1184398): Move to compiler-rt when we are ready. ++ ldflags += [ "--rtlib=libgcc" ] + if (current_cpu == "arm64") { + if (arm_control_flow_integrity == "standard") { + cflags += [ "-mbranch-protection=standard" ] +@@ -55,10 +61,6 @@ config("compiler") { + } + } + +- # Instead of using an unwind lib from the toolchain, +- # buildtools/third_party/libunwind will be built and used directly. +- ldflags += [ "--unwindlib=none" ] +- + # $compile_api_level corresponds to the API level used for the sysroot path + # calculation in //build/config/android/config.gni + if (android_64bit_target_cpu) { +@@ -80,8 +82,11 @@ config("compiler") { + # that is Android-only. Please see that target for advice on what should go in + # :runtime_library vs. :compiler. + config("runtime_library") { ++ # Let the linker find libgcc.a. ++ ldflags = [ "--gcc-toolchain=" + ++ rebase_path(android_toolchain_root, root_build_dir) ] ++ + libs = [] +- ldflags = [] + + # On 64-bit platforms, the only symbols provided by libandroid_support.a are + # strto{d,f,l,ul}_l. These symbols are not used by our libc++, and newer NDKs diff --git a/patches/v8_shared_library.patch b/patches/v8_shared_library.patch index a196400..376e95b 100644 --- a/patches/v8_shared_library.patch +++ b/patches/v8_shared_library.patch @@ -1,28 +1,28 @@ diff --git a/BUILD.gn b/BUILD.gn -index c486f1a..6aeb762 100644 +index bca5b5356b..6e24a30cd3 100644 --- a/BUILD.gn +++ b/BUILD.gn -@@ -284,9 +284,7 @@ config("internal_config") { - ":v8_header_features", +@@ -585,9 +585,7 @@ config("internal_config") { + ":cppgc_header_features", ] - if (is_component_build) { - defines += [ "BUILDING_V8_SHARED" ] - } + defines += [ "BUILDING_V8_SHARED" ] - } - # This config should be applied to code using the libplatform. -@@ -3480,7 +3478,7 @@ v8_source_set("torque_ls_base") { + if (v8_current_cpu == "riscv64") { + libs = [ "atomic" ] +@@ -4956,7 +4954,7 @@ v8_source_set("torque_ls_base") { } } -v8_component("v8_libbase") { +v8_source_set("v8_libbase") { sources = [ - "src/base/adapters.h", "src/base/address-region.h", -@@ -3569,11 +3567,7 @@ v8_component("v8_libbase") { + "src/base/atomic-utils.h", +@@ -5071,11 +5069,7 @@ v8_component("v8_libbase") { data_deps = [] @@ -35,7 +35,7 @@ index c486f1a..6aeb762 100644 if (is_posix || is_fuchsia) { sources += [ -@@ -3675,7 +3669,7 @@ v8_component("v8_libbase") { +@@ -5194,7 +5188,7 @@ v8_component("v8_libbase") { # TODO(jochen): Add support for qnx, freebsd, openbsd, netbsd, and solaris. } @@ -44,7 +44,7 @@ index c486f1a..6aeb762 100644 sources = [ "//base/trace_event/common/trace_event_common.h", "include/libplatform/libplatform-export.h", -@@ -3704,9 +3698,7 @@ v8_component("v8_libplatform") { +@@ -5225,9 +5219,7 @@ v8_component("v8_libplatform") { configs = [ ":internal_config_base" ] @@ -55,10 +55,10 @@ index c486f1a..6aeb762 100644 public_configs = [ ":libplatform_config" ] -@@ -3813,6 +3805,23 @@ v8_static_library("wee8") { - ] +@@ -5637,6 +5629,23 @@ if (v8_enable_webassembly) { + } } - + +v8_loadable_module("libv8android") { + defines = [ "BUILDING_V8_SHARED" ] + @@ -80,10 +80,10 @@ index c486f1a..6aeb762 100644 # Executables # diff --git a/gni/v8.gni b/gni/v8.gni -index e55c4cf..a97111b 100644 +index fe445307f9..b07fb80222 100644 --- a/gni/v8.gni +++ b/gni/v8.gni -@@ -230,3 +230,12 @@ template("v8_static_library") { +@@ -303,3 +303,12 @@ template("v8_static_library") { configs += invoker.configs } } diff --git a/patches/v8_shared_library_ios.patch b/patches/v8_shared_library_ios.patch index 323c703..9255eb5 100644 --- a/patches/v8_shared_library_ios.patch +++ b/patches/v8_shared_library_ios.patch @@ -1,64 +1,64 @@ diff --git a/BUILD.gn b/BUILD.gn -index c486f1a..6aeb762 100644 +index bca5b5356b..7c77b8c79d 100644 --- a/BUILD.gn +++ b/BUILD.gn -@@ -284,9 +284,7 @@ config("internal_config") { - ":v8_header_features", +@@ -585,9 +585,7 @@ config("internal_config") { + ":cppgc_header_features", ] - + - if (is_component_build) { - defines += [ "BUILDING_V8_SHARED" ] - } + defines += [ "BUILDING_V8_SHARED" ] - } - - # This config should be applied to code using the libplatform. -@@ -3480,7 +3478,7 @@ v8_source_set("torque_ls_base") { + + if (v8_current_cpu == "riscv64") { + libs = [ "atomic" ] +@@ -4956,7 +4954,7 @@ v8_source_set("torque_ls_base") { } } - + -v8_component("v8_libbase") { +v8_source_set("v8_libbase") { sources = [ - "src/base/adapters.h", "src/base/address-region.h", -@@ -3569,11 +3567,7 @@ v8_component("v8_libbase") { - + "src/base/atomic-utils.h", +@@ -5071,11 +5069,7 @@ v8_component("v8_libbase") { + data_deps = [] - + - defines = [] - - if (is_component_build) { - defines = [ "BUILDING_V8_BASE_SHARED" ] - } + defines = [ "BUILDING_V8_BASE_SHARED" ] - + if (is_posix || is_fuchsia) { sources += [ -@@ -3675,7 +3669,7 @@ v8_component("v8_libbase") { +@@ -5194,7 +5188,7 @@ v8_component("v8_libbase") { # TODO(jochen): Add support for qnx, freebsd, openbsd, netbsd, and solaris. } - + -v8_component("v8_libplatform") { +v8_source_set("v8_libplatform") { sources = [ "//base/trace_event/common/trace_event_common.h", "include/libplatform/libplatform-export.h", -@@ -3704,9 +3698,7 @@ v8_component("v8_libplatform") { - +@@ -5225,9 +5219,7 @@ v8_component("v8_libplatform") { + configs = [ ":internal_config_base" ] - + - if (is_component_build) { - defines = [ "BUILDING_V8_PLATFORM_SHARED" ] - } + defines = [ "BUILDING_V8_PLATFORM_SHARED" ] - + public_configs = [ ":libplatform_config" ] - -@@ -3813,6 +3805,23 @@ v8_static_library("wee8") { - ] + +@@ -5637,6 +5629,23 @@ if (v8_enable_webassembly) { + } } - + +v8_shared_library("libv8") { + defines = [ "BUILDING_V8_SHARED" ] + @@ -79,35 +79,3 @@ index c486f1a..6aeb762 100644 ############################################################################### # Executables # -diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn -index cba0602f8..1e4ae504f 100644 ---- a/build/config/compiler/BUILD.gn -+++ b/build/config/compiler/BUILD.gn -@@ -1513,6 +1513,13 @@ config("default_warnings") { - cflags += [ "-Wno-nonportable-include-path" ] - } - -+ if (clang_base_path == default_clang_base_path) { -+ cflags += [ -+ "-Wno-implicit-int-float-conversion", -+ "-Wno-unknown-warning-option", -+ ] -+ } -+ - if (current_toolchain == host_toolchain || !use_xcode_clang) { - # Flags NaCl (Clang 3.7) and Xcode 9.2 (Clang clang-900.0.39.2) do not - # recognize. -@@ -1557,6 +1564,13 @@ config("default_warnings") { - } - } - } -+ if (use_xcode_clang) { -+ cflags_cc += [ -+ "-Wno-deprecated-copy", -+ "-Wno-final-dtor-non-final-class", -+ "-Wno-range-loop-analysis", -+ ] -+ } - } - - # chromium_code --------------------------------------------------------------- diff --git a/scripts/archive.sh b/scripts/archive.sh index e48a6e8..bc5f0d1 100755 --- a/scripts/archive.sh +++ b/scripts/archive.sh @@ -2,8 +2,8 @@ source $(dirname $0)/env.sh function makeDistPackageDir() { - if [[ ${MKSNAPSHOT_ONLY} = "1" ]]; then - echo "${DIST_DIR}/packages/v8-${PLATFORM}-tools" + if [[ ${TOOLS_ONLY} = "true" ]]; then + echo "${DIST_DIR}/packages/v8-android-tools" return 0 fi @@ -57,11 +57,18 @@ function copyHeaders() { function copyTools() { printf "\n\n\t\t===================== adding tools to ${DIST_PACKAGE_DIR}/tools =====================\n\n" - cp -Rf "${BUILD_DIR}/tools" "${DIST_PACKAGE_DIR}/tools" + cp -Rf "${BUILD_DIR}/tools" "${DIST_PACKAGE_DIR}/" +} + +function copySnapshotBlobIfNeeded() { + if [[ ${EXTERNAL_STARTUP_DATA} = "true" || ${TOOLS_ONLY} = "true" ]]; then + printf "\n\n\t\t===================== adding snapshot_blob to ${DIST_PACKAGE_DIR}/snapshot_blob =====================\n\n" + cp -Rf "${BUILD_DIR}/snapshot_blob" "${DIST_PACKAGE_DIR}/" + fi } -if [[ ${MKSNAPSHOT_ONLY} = "1" ]]; then +if [[ ${TOOLS_ONLY} = "true" ]]; then mkdir -p "$DIST_PACKAGE_DIR" copyTools exit 0 @@ -78,9 +85,11 @@ if [[ ${PLATFORM} = "android" ]]; then createUnstrippedLibs copyHeaders copyTools + copySnapshotBlobIfNeeded elif [[ ${PLATFORM} = "ios" ]]; then createUniversalDylib copyDylib copyHeaders copyTools + copySnapshotBlobIfNeeded fi diff --git a/scripts/build.sh b/scripts/build.sh index 8e034a4..8c93e35 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -7,16 +7,23 @@ BUILD_TYPE="Release" ARCH=$2 GN_ARGS_BASE=" - target_os=\"${PLATFORM}\" is_component_build=false - use_debug_fission=false use_custom_libcxx=false - v8_use_external_startup_data=false icu_use_data_file=false + treat_warnings_as_errors=false " +if [[ ${PLATFORM} = "macos_android" ]]; then + GN_ARGS_BASE="${GN_ARGS_BASE} target_os=\"android\" host_cpu=\"x64\"" +else + GN_ARGS_BASE="${GN_ARGS_BASE} target_os=\"${PLATFORM}\"" +fi + if [[ ${PLATFORM} = "ios" ]]; then GN_ARGS_BASE="${GN_ARGS_BASE} enable_ios_bitcode=false use_xcode_clang=true ios_enable_code_signing=false v8_enable_pointer_compression=false ios_deployment_target=${IOS_DEPLOYMENT_TARGET}" +elif [[ ${PLATFORM} = "android" ]]; then + # Workaround v8 sysroot build issues with custom ndk + GN_ARGS_BASE="${GN_ARGS_BASE} use_sysroot=false" fi if [[ ${NO_INTL} = "true" ]]; then @@ -27,6 +34,12 @@ if [[ ${NO_JIT} = "true" ]]; then GN_ARGS_BASE="${GN_ARGS_BASE} v8_enable_lite_mode=true" fi +if [[ ${EXTERNAL_STARTUP_DATA} = "true" || ${TOOLS_ONLY} = "true" ]]; then + GN_ARGS_BASE="${GN_ARGS_BASE} v8_use_external_startup_data=true" +else + GN_ARGS_BASE="${GN_ARGS_BASE} v8_use_external_startup_data=false" +fi + if [[ "$BUILD_TYPE" = "Debug" ]] then GN_ARGS_BUILD_TYPE=' @@ -76,7 +89,7 @@ function normalize_arch_for_platform() esac } -function build_arch() +function buildArch() { local arch=$1 local platform_arch=$(normalize_arch_for_platform $arch) @@ -89,6 +102,8 @@ function build_arch() elif [[ ${PLATFORM} = "ios" ]]; then target="libv8" target_ext=".dylib" + elif [[ ${PLATFORM} = "macos_android" ]]; then + : else exit 1 fi @@ -96,32 +111,84 @@ function build_arch() echo "Build v8 ${arch} variant NO_INTL=${NO_INTL} NO_JIT=${NO_JIT}" gn gen --args="${GN_ARGS_BASE} ${GN_ARGS_BUILD_TYPE} target_cpu=\"${arch}\"" "out.v8.${arch}" - if [[ ${MKSNAPSHOT_ONLY} = "1" ]]; then - date ; ninja ${NINJA_PARAMS} -C "out.v8.${arch}" run_mksnapshot_default ; date + if [[ ${TOOLS_ONLY} = "true" ]]; then + date ; ninja ${NINJA_PARAMS} -C "out.v8.${arch}" run_mksnapshot_default mkcodecache_group ; date + copySnapshot $arch + copyMkcodecache $arch + else + date ; ninja ${NINJA_PARAMS} -C "out.v8.${arch}" ${target} run_mksnapshot_default mkcodecache_group ; date + copyLib $arch + copySnapshot $arch + copyMkcodecache $arch + fi +} + +function copyLib() +{ + local arch=$1 + local platform_arch=$(normalize_arch_for_platform $arch) + + local target='' + local target_ext='' + if [[ ${PLATFORM} = "android" ]]; then + target="libv8android" + target_ext=".so" + elif [[ ${PLATFORM} = "ios" ]]; then + target="libv8" + target_ext=".dylib" else - date ; ninja ${NINJA_PARAMS} -C "out.v8.${arch}" ${target} ; date + exit 1 + fi - mkdir -p "${BUILD_DIR}/lib/${platform_arch}" - cp -f "out.v8.${arch}/${target}${target_ext}" "${BUILD_DIR}/lib/${platform_arch}/${target}${target_ext}" + mkdir -p "${BUILD_DIR}/lib/${platform_arch}" + cp -f "out.v8.${arch}/${target}${target_ext}" "${BUILD_DIR}/lib/${platform_arch}/${target}${target_ext}" - if [[ -d "out.v8.${arch}/lib.unstripped" ]]; then - mkdir -p "${BUILD_DIR}/lib.unstripped/${platform_arch}" - cp -f "out.v8.${arch}/lib.unstripped/${target}${target_ext}" "${BUILD_DIR}/lib.unstripped/${platform_arch}/${target}${target_ext}" - fi + if [[ -d "out.v8.${arch}/lib.unstripped" ]]; then + mkdir -p "${BUILD_DIR}/lib.unstripped/${platform_arch}" + cp -f "out.v8.${arch}/lib.unstripped/${target}${target_ext}" "${BUILD_DIR}/lib.unstripped/${platform_arch}/${target}${target_ext}" fi +} + +function copySnapshot() +{ + local arch=$1 + local platform_arch=$(normalize_arch_for_platform $arch) + + mkdir -p "${BUILD_DIR}/tools/${PLATFORM}/${platform_arch}" + cp -f out.v8.${arch}/clang_*/mksnapshot "${BUILD_DIR}/tools/${PLATFORM}/${platform_arch}/mksnapshot" - mkdir -p "${BUILD_DIR}/tools/${platform_arch}" - cp -f out.v8.${arch}/clang_*/mksnapshot "${BUILD_DIR}/tools/${platform_arch}/mksnapshot" + if [[ ${EXTERNAL_STARTUP_DATA} = "true" || ${TOOLS_ONLY} = "true" ]]; then + mkdir -p "${BUILD_DIR}/snapshot_blob/${platform_arch}" + cp -f out.v8.${arch}/snapshot_blob.bin "${BUILD_DIR}/snapshot_blob/${platform_arch}/snapshot_blob.bin" + fi +} + +function copyMkcodecache() +{ + local arch=$1 + local platform_arch=$(normalize_arch_for_platform $arch) + + mkdir -p "${BUILD_DIR}/tools/${PLATFORM}/${platform_arch}" + cp -f out.v8.${arch}/clang_*/mkcodecache "${BUILD_DIR}/tools/${PLATFORM}/${platform_arch}/mkcodecache" + + if [[ ${EXTERNAL_STARTUP_DATA} = "true" || ${TOOLS_ONLY} = "true" ]]; then + cp -f out.v8.${arch}/clang_*/snapshot_blob.bin "${BUILD_DIR}/tools/${PLATFORM}/${platform_arch}/snapshot_blob.bin" + fi } if [[ ${ARCH} ]]; then - build_arch "${ARCH}" + buildArch "${ARCH}" elif [[ ${PLATFORM} = "android" ]]; then - build_arch "arm" - build_arch "x86" - build_arch "arm64" - build_arch "x64" + buildArch "arm" + buildArch "x86" + buildArch "arm64" + buildArch "x64" elif [[ ${PLATFORM} = "ios" ]]; then - build_arch "arm64" - build_arch "x64" + buildArch "arm64" + buildArch "x64" +elif [[ ${PLATFORM} = "macos_android" ]]; then + # buildArch "arm" + # buildArch "x86" + buildArch "arm64" + buildArch "x64" fi diff --git a/scripts/bump.py b/scripts/bump.py index c8c26e2..04cc7d2 100644 --- a/scripts/bump.py +++ b/scripts/bump.py @@ -7,43 +7,43 @@ import sys ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) -PACKAGES = ('v8-android', 'v8-android-nointl', 'v8-android-jit', 'v8-android-jit-nointl') +PACKAGES = ( + "v8-android", + "v8-android-nointl", + "v8-android-jit", + "v8-android-jit-nointl", + "v8-android-tools-macos", + "v8-android-tools-linux", +) class PackageConfigPatcher: def __init__(self, root, version): - self._config_path = os.path.join(root, 'package.json') + self._config_path = os.path.join(root, "package.json") self._version = version @classmethod - def _replace_file_content(cls, - file_path, - old_pattern, - new_pattern, - re_flags=0): - with io.open(file_path, 'r', encoding='utf8') as f: + def _replace_file_content(cls, file_path, old_pattern, new_pattern, re_flags=0): + with io.open(file_path, "r", encoding="utf8") as f: content = str(f.read()) - new_content = re.sub(old_pattern, - new_pattern, - content, - flags=re_flags) - with io.open(file_path, 'w', encoding='utf8') as f: + new_content = re.sub(old_pattern, new_pattern, content, flags=re_flags) + with io.open(file_path, "w", encoding="utf8") as f: f.write(new_content) def patch(self): - self._replace_file_content(self._config_path, - r'("version": )("[^"]+")(,)', - '\\1"' + self._version + '"\\3') + self._replace_file_content( + self._config_path, + r'("version": )("[^"]+")(,)', + '\\1"' + self._version + '"\\3', + ) def parse_args(): arg_parser = argparse.ArgumentParser() - arg_parser.add_argument('--version', - '-V', - type=str, - required=True, - help='Bump packages version') + arg_parser.add_argument( + "--version", "-V", type=str, required=True, help="Bump packages version" + ) args = arg_parser.parse_args() return args @@ -56,10 +56,10 @@ def main(): PackageConfigPatcher(ROOT_DIR, version).patch() for package in PACKAGES: - print('\nBump {} package to version {}'.format(package, version)) - package_root = os.path.join(ROOT_DIR, 'packages', package) + print("\nBump {} package to version {}".format(package, version)) + package_root = os.path.join(ROOT_DIR, "packages", package) PackageConfigPatcher(package_root, version).patch() -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/scripts/env.sh b/scripts/env.sh index f98b24f..87cc8c9 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -17,7 +17,7 @@ function abs_path() function verify_platform() { local arg=$1 - SUPPORTED_PLATFORMS=(android ios) + SUPPORTED_PLATFORMS=(android ios macos_android) local valid_platform= for platform in ${SUPPORTED_PLATFORMS[@]} do @@ -42,8 +42,9 @@ V8_DIR="${ROOT_DIR}/v8" DIST_DIR="${ROOT_DIR}/dist" PATCHES_DIR="${ROOT_DIR}/patches" -NDK_VERSION="r19c" +NDK_VERSION="r21e" IOS_DEPLOYMENT_TARGET="9" +EXTERNAL_STARTUP_DATA="true" export PATH="$DEPOT_TOOLS_DIR:$PATH" PLATFORM=$(verify_platform $1) diff --git a/scripts/patch.sh b/scripts/patch.sh index 9e86d98..b8ad0f5 100755 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -15,8 +15,19 @@ V8_PATCHSET_ANDROID=( # https://github.com/Kudo/react-native-v8/issues/37 "custom_timezone.patch" - # Fix build break for v91 - "android_build_break_v91.patch" + # Fix v8 9.7 build error + "v8_97_android_build_error.patch" + + # Fix v8 9.7 libunwind link error + # revert https://chromium.googlesource.com/chromium/src/build/+/7bb5f36104 + "v8_97_android_unwind_link_error.patch" + + # Add mkcodecache tool + "mkcodecache.patch" + + # Fix for [react-native-bottom-sheet](https://github.com/gorhom/react-native-bottom-sheet) not working + # revert https://chromium-review.googlesource.com/c/v8/v8/+/3548458 + "fix_for_bottom_sheet.patch" ) V8_PATCHSET_IOS=( @@ -29,8 +40,20 @@ V8_PATCHSET_IOS=( # Workaround latest Xcode12 build break on non Apple Silicon # "v8_ios_host_break.patch" - # Fix std::forward undefined - "ios_build_error_forward.patch" + # Fix use_system_xcode build error + "system_xcode_build_error.patch" + + # Add mkcodecache tool + "mkcodecache.patch" + + # Fix for [react-native-bottom-sheet](https://github.com/gorhom/react-native-bottom-sheet) not working + # revert https://chromium-review.googlesource.com/c/v8/v8/+/3548458 + "fix_for_bottom_sheet.patch" +) + +V8_PATCHSET_MACOS_ANDROID=( + # Add mkcodecache tool + "mkcodecache.patch" ) ###################################################################################### @@ -48,6 +71,11 @@ function setupNDK() { unset ndk_major_version } +function setupMkCodecache() { + mkdir -p "${V8_DIR}/src/mkcodecache" + cp -f "${ROOT_DIR}/mkcodecache/mkcodecache.cc" "${V8_DIR}/src/mkcodecache/" +} + if [[ ${PLATFORM} = "android" ]]; then for patch in "${V8_PATCHSET_ANDROID[@]}" do @@ -56,10 +84,22 @@ if [[ ${PLATFORM} = "android" ]]; then done setupNDK + setupMkCodecache elif [[ ${PLATFORM} = "ios" ]]; then for patch in "${V8_PATCHSET_IOS[@]}" do printf "### Patch set: ${patch}\n" patch -d "${V8_DIR}" -p1 < "${PATCHES_DIR}/$patch" done + + setupMkCodecache +elif [[ ${PLATFORM} = "macos_android" ]]; then + for patch in "${V8_PATCHSET_MACOS_ANDROID[@]}" + do + printf "### Patch set: ${patch}\n" + patch -d "${V8_DIR}" -p1 < "${PATCHES_DIR}/$patch" + done + + setupNDK + setupMkCodecache fi diff --git a/scripts/publish.py b/scripts/publish.py index aff5cdf..cc73735 100644 --- a/scripts/publish.py +++ b/scripts/publish.py @@ -7,27 +7,32 @@ ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) PACKAGE_MAP = { - 'v8-android': 'dist-intl.zip', - 'v8-android-nointl': 'dist-nointl.zip', - 'v8-android-jit': 'dist-jit-intl.zip', - 'v8-android-jit-nointl': 'dist-jit-nointl.zip', + "v8-android": "dist-intl.zip", + "v8-android-nointl": "dist-nointl.zip", + "v8-android-jit": "dist-jit-intl.zip", + "v8-android-jit-nointl": "dist-jit-nointl.zip", +} + +MACOS_TOOLS_DIST_MAP = { + "v8-android": "macos-tools-intl.zip", + "v8-android-nointl": "macos-tools-nointl.zip", + "v8-android-jit": "macos-tools-jit-intl.zip", + "v8-android-jit-nointl": "macos-tools-jit-nointl.zip", } def parse_args(): arg_parser = argparse.ArgumentParser() - arg_parser.add_argument('--dry-run', - action='store_true', - help='Dry run mode for npm publish') - arg_parser.add_argument('--tag', - '-T', - type=str, - required=True, - help='NPM published tag') - arg_parser.add_argument('distdir', - action='store', - help='dir to dist*.zip files created from CI') + arg_parser.add_argument( + "--dry-run", action="store_true", help="Dry run mode for npm publish" + ) + arg_parser.add_argument( + "--tag", "-T", type=str, required=True, help="NPM published tag" + ) + arg_parser.add_argument( + "distdir", action="store", help="dir to dist*.zip files created from CI" + ) args = arg_parser.parse_args() if not args.distdir: @@ -36,36 +41,171 @@ def parse_args(): return args -def main(): - args = parse_args() - - workdir = os.path.join(ROOT_DIR, 'build', 'publish') - +def publish_engines(args, workdir): for (package, distfile) in PACKAGE_MAP.items(): - print('\n\n========== Publish {} package =========='.format(package)) + print("\n\n========== Publish {} package ==========".format(package)) if os.path.exists(workdir): shutil.rmtree(workdir) os.makedirs(workdir) distfile_path = os.path.join(args.distdir, distfile) if not os.path.exists(distfile_path): - raise FileNotFoundError( - 'dist file not found: {}'.format(distfile_path)) - subprocess.run(['unzip', distfile_path, '-d', workdir]) + raise FileNotFoundError("dist file not found: {}".format(distfile_path)) + subprocess.run(["unzip", distfile_path, "-d", workdir]) - cwd = os.path.join(ROOT_DIR, 'packages', package) - source_dir_in_zip_file = os.path.join(workdir, 'packages', package) - distdir = os.path.join(cwd, 'dist') + cwd = os.path.join(ROOT_DIR, "packages", package) + source_dir_in_zip_file = os.path.join(workdir, "dist", "packages", package) + distfile_path = os.path.join(workdir, "dist.tar") + subprocess.run(["tar", "-xf", distfile_path, "-C", workdir]) + distdir = os.path.join(cwd, "dist") if os.path.exists(distdir): shutil.rmtree(distdir) shutil.move(source_dir_in_zip_file, distdir) - cmds = ['npm', 'publish', '--tag', args.tag] + + # remove unstripped lib and tools from npm and upload to github releases + shutil.rmtree(os.path.join(distdir, "lib.unstripped")) + shutil.rmtree(os.path.join(distdir, "tools")) + + cmds = ["npm", "publish", "--tag", args.tag] if args.dry_run: - cmds.append('--dry-run') + cmds.append("--dry-run") subprocess.run(cmds, cwd=cwd) shutil.rmtree(workdir) -if __name__ == '__main__': +def publish_tools_macos(args, workdir): + print("\n\n========== Publish v8-android-tools-macos package ==========") + pkg_root = os.path.join(ROOT_DIR, "packages", "v8-android-tools-macos") + + for (package, distfile) in MACOS_TOOLS_DIST_MAP.items(): + if os.path.exists(workdir): + shutil.rmtree(workdir) + os.makedirs(workdir) + + distfile_path = os.path.join(args.distdir, distfile) + if not os.path.exists(distfile_path): + raise FileNotFoundError("dist file not found: {}".format(distfile_path)) + + subprocess.run(["unzip", distfile_path, "-d", workdir]) + source_dir_in_zip_file = os.path.join( + workdir, "dist", "packages", "v8-android-tools", "tools", "macos_android" + ) + distfile_path = os.path.join(workdir, "dist.tar") + subprocess.run(["tar", "-xf", distfile_path, "-C", workdir]) + distdir = os.path.join(pkg_root, package) + if os.path.exists(distdir): + shutil.rmtree(distdir) + shutil.move(source_dir_in_zip_file, distdir) + + # clear attributes + subprocess.run(["xattr", "-r", "-d", "com.apple.quarantine", pkg_root]) + subprocess.run( + ["xattr", "-r", "-d", "com.apple.metadata:kMDItemWhereFroms", pkg_root] + ) + + # publish + cmds = ["npm", "publish", "--tag", args.tag] + if args.dry_run: + cmds.append("--dry-run") + subprocess.run(cmds, cwd=pkg_root) + + shutil.rmtree(workdir) + + +def create_engines_zip(args, workdir): + print("\n\n========== Create v8-android-tools-linux zip ==========") + + for (package, distfile) in PACKAGE_MAP.items(): + distfile_path = os.path.join(args.distdir, distfile) + zip_filename = "{}.zip".format(package) + shutil.copyfile(distfile_path, os.path.join(ROOT_DIR, zip_filename)) + + +def create_tools_zip_macos(args, workdir): + print("\n\n========== Create v8-android-tools-macos.zip ==========") + pkg_root = os.path.join(ROOT_DIR, "packages", "v8-android-tools-macos") + + for (package, distfile) in MACOS_TOOLS_DIST_MAP.items(): + if os.path.exists(workdir): + shutil.rmtree(workdir) + os.makedirs(workdir) + + distfile_path = os.path.join(args.distdir, distfile) + if not os.path.exists(distfile_path): + raise FileNotFoundError("dist file not found: {}".format(distfile_path)) + + subprocess.run(["unzip", distfile_path, "-d", workdir]) + source_dir_in_zip_file = os.path.join( + workdir, "dist", "packages", "v8-android-tools", "tools", "macos_android" + ) + distfile_path = os.path.join(workdir, "dist.tar") + subprocess.run(["tar", "-xf", distfile_path, "-C", workdir]) + distdir = os.path.join(pkg_root, package) + if os.path.exists(distdir): + shutil.rmtree(distdir) + shutil.move(source_dir_in_zip_file, distdir) + + # clear attributes + subprocess.run(["xattr", "-r", "-d", "com.apple.quarantine", pkg_root]) + subprocess.run( + ["xattr", "-r", "-d", "com.apple.metadata:kMDItemWhereFroms", pkg_root] + ) + + # publish + cmds = ["zip", "-r", os.path.join(ROOT_DIR, "v8-android-tools-macos.zip"), "."] + subprocess.run(cmds, cwd=pkg_root) + + shutil.rmtree(workdir) + + +def create_tools_zip_linux(args, workdir): + print("\n\n========== Create v8-android-tools-linux zip ==========") + pkg_root = os.path.join(ROOT_DIR, "packages", "v8-android-tools-linux") + + for (package, distfile) in PACKAGE_MAP.items(): + if os.path.exists(workdir): + shutil.rmtree(workdir) + os.makedirs(workdir) + + distfile_path = os.path.join(args.distdir, distfile) + if not os.path.exists(distfile_path): + raise FileNotFoundError("dist file not found: {}".format(distfile_path)) + + subprocess.run(["unzip", distfile_path, "-d", workdir]) + source_dir_in_zip_file = os.path.join( + workdir, "dist", "packages", package, "tools", "android" + ) + distfile_path = os.path.join(workdir, "dist.tar") + subprocess.run(["tar", "-xf", distfile_path, "-C", workdir]) + distdir = os.path.join(pkg_root, package) + if os.path.exists(distdir): + shutil.rmtree(distdir) + shutil.move(source_dir_in_zip_file, distdir) + + # clear attributes + subprocess.run(["xattr", "-r", "-d", "com.apple.quarantine", pkg_root]) + subprocess.run( + ["xattr", "-r", "-d", "com.apple.metadata:kMDItemWhereFroms", pkg_root] + ) + + # zip + cmds = ["zip", "-r", os.path.join(ROOT_DIR, "v8-android-tools-linux.zip"), "."] + subprocess.run(cmds, cwd=pkg_root) + + shutil.rmtree(workdir) + + +def main(): + args = parse_args() + workdir = os.path.join(ROOT_DIR, "build", "publish") + publish_engines(args, workdir) + publish_tools_macos(args, workdir) + + create_engines_zip(args, workdir) + create_tools_zip_macos(args, workdir) + create_tools_zip_linux(args, workdir) + + +if __name__ == "__main__": main() diff --git a/scripts/setup.sh b/scripts/setup.sh index 8cf507e..61bf7f5 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -17,11 +17,12 @@ source $(dirname $0)/env.sh # Install NDK function installNDK() { + local host_arch=$1 pushd . cd "${V8_DIR}" - wget -q https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux-x86_64.zip - unzip -q android-ndk-${NDK_VERSION}-linux-x86_64.zip - rm -f android-ndk-${NDK_VERSION}-linux-x86_64.zip + wget -q https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-${host_arch}-x86_64.zip + unzip -q android-ndk-${NDK_VERSION}-${host_arch}-x86_64.zip + rm -f android-ndk-${NDK_VERSION}-${host_arch}-x86_64.zip popd } @@ -31,11 +32,6 @@ fi gclient config --name v8 --unmanaged "https://chromium.googlesource.com/v8/v8.git" -if [[ ${MKSNAPSHOT_ONLY} = "1" ]]; then - gclient sync ${GCLIENT_SYNC_ARGS} - exit 0 -fi - if [[ ${PLATFORM} = "ios" ]]; then gclient sync --deps=ios ${GCLIENT_SYNC_ARGS} exit 0 @@ -48,6 +44,20 @@ if [[ ${PLATFORM} = "android" ]]; then patch -d "${V8_DIR}" -p1 < "${PATCHES_DIR}/prebuild_no_snapd.patch" sudo bash -c 'v8/build/install-build-deps-android.sh' + sudo apt-get -y install \ + libc6-dev \ + libc6-dev-i386 \ + libc6-dev-armel-cross \ + libc6-dev-armhf-cross \ + libc6-dev-arm64-cross \ + libc6-dev-armel-armhf-cross \ + libgcc-10-dev-armhf-cross \ + libstdc++-9-dev \ + lib32stdc++-9-dev \ + libx32stdc++-9-dev \ + libstdc++-10-dev-armhf-cross \ + libstdc++-9-dev-armhf-cross \ + libsfstdc++-10-dev-armhf-cross # Reset changes after installation patch -d "${V8_DIR}" -p1 -R < "${PATCHES_DIR}/prebuild_no_snapd.patch" @@ -58,6 +68,12 @@ if [[ ${PLATFORM} = "android" ]]; then # Workaround to install missing android_sdk tools gclient sync --deps=android ${GCLIENT_SYNC_ARGS} - installNDK + installNDK "linux" + exit 0 +fi + +if [[ ${PLATFORM} = "macos_android" ]]; then + gclient sync --deps=android ${GCLIENT_SYNC_ARGS} + installNDK "darwin" exit 0 fi diff --git a/scripts/start.sh b/scripts/start.sh index 363d491..9852a87 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -7,8 +7,10 @@ fi cd "${V8_DIR}" -if [[ ${MKSNAPSHOT_ONLY} = "1" ]]; then +if [[ ${MKSNAPSHOT_ONLY} = "true" ]]; then gclient sync --reset --with_branch_head --revision ${V8_VERSION} +elif [[ ${MKCODECACHE_ONLY} = "true" ]]; then + gclient sync --deps=android --reset --with_branch_head --revision ${V8_VERSION} else gclient sync --deps=${PLATFORM} --reset --with_branch_head --revision ${V8_VERSION} fi @@ -19,5 +21,7 @@ scripts/patch.sh ${PLATFORM} scripts/build.sh ${PLATFORM} scripts/archive.sh ${PLATFORM} -NO_INTL=1 scripts/build.sh ${PLATFORM} -NO_INTL=1 scripts/archive.sh ${PLATFORM} +if [[ ${TOOLS_ONLY} != "true" ]]; then + NO_INTL=true scripts/build.sh ${PLATFORM} + NO_INTL=true scripts/archive.sh ${PLATFORM} +fi