diff --git a/.gitignore b/.gitignore index 25a12fd..953a320 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build -out \ No newline at end of file +out +.vscode diff --git a/ReactNative.V8Jsi.Windows.nuspec b/ReactNative.V8Jsi.Windows.nuspec index 07c908d..f43689e 100644 --- a/ReactNative.V8Jsi.Windows.nuspec +++ b/ReactNative.V8Jsi.Windows.nuspec @@ -3,7 +3,7 @@ ReactNative.V8Jsi.Windows $Version$ - Contains a Windows implementation of the V8 JSI wrapper for ReactNative + Contains a Windows implementation of the V8 JSI wrapper for ReactNative (VERSION_DETAILS) Facebook, Google, Microsoft https://github.com/microsoft/v8-jsi false diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 77fdc0e..860b7c7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,12 +30,12 @@ jobs: X86Release: BuildConfiguration: Release BuildPlatform: x86 - X64Release-Clang: - BuildConfiguration: Release-Clang - BuildPlatform: x64 - X86Release-Clang: - BuildConfiguration: Release-Clang - BuildPlatform: x86 + #X64Release-Clang: + # BuildConfiguration: Release-Clang + # BuildPlatform: x64 + #X86Release-Clang: + # BuildConfiguration: Release-Clang + # BuildPlatform: x86 steps: - task: UsePythonVersion@0 diff --git a/config.json b/config.json index 85bbb55..7752e46 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { "version": "0.2.2", - "v8ref": "refs/branch-heads/7.9" + "v8ref": "refs/branch-heads/8.0" } \ No newline at end of file diff --git a/localbuild.ps1 b/localbuild.ps1 index ea192a6..62bffa8 100644 --- a/localbuild.ps1 +++ b/localbuild.ps1 @@ -3,7 +3,7 @@ $OutputPath = "$PSScriptRoot\out" $SourcesPath = $PSScriptRoot $Platforms = "x64", "x86" -$Configurations = "Debug", "Release", "Release-Clang" +$Configurations = "Release", "Debug", "Release-Clang", "EXPERIMENTAL-libcpp-Clang" Write-Host "Downloading environment..." & ".\scripts\download_depottools.ps1" -SourcesPath $SourcesPath @@ -14,7 +14,7 @@ if (!$?) { } Write-Host "Fetching code..." -& ".\scripts\fetch_code.ps1" -SourcesPath $SourcesPath -Configuration $Configurations[0] +& ".\scripts\fetch_code.ps1" -SourcesPath $SourcesPath -OutputPath $OutputPath -Configuration $Configurations[0] if (!$?) { Write-Host "Failed to retrieve the v8 code" diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 3165858..0432408 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -28,6 +28,19 @@ if (!(Select-String -Path (Join-Path $workpath "v8build\v8\BUILD.gn") -Pattern ' $FixNeededPath = Join-Path $workpath "v8build\v8\build\config\win\BUILD.gn" (Get-Content $FixNeededPath) -replace (":static_crt", ":dynamic_crt") | Set-Content $FixNeededPath +#TODO: This is temporary until Office moves to the new toolset with FH4 support (ETA: May 2020) +(Get-Content $FixNeededPath) -replace ('/Zc:sizedDealloc-', @' +/Zc:sizedDealloc-","-d2FH4- +'@) | Set-Content $FixNeededPath + +(Get-Content $FixNeededPath) -replace ('ldflags = \[\]', @' +if (is_clang) { + ldflags = [] +} else { + ldflags = ["-d2:-FH4-"] +} +'@) | Set-Content $FixNeededPath + Remove-Item (Join-Path $workpath "v8build\v8\jsi") -Recurse -ErrorAction Ignore Copy-Item $jsigitpath -Destination (Join-Path $workpath "v8build\v8\jsi") -Recurse -Force @@ -40,7 +53,11 @@ if ($Configuration -like "*android") { $gnargs += ' use_goma=false target_os=\"android\" target_cpu=\"' + $Platform + '\"' } else { - $gnargs += ' use_custom_libcxx=false target_cpu=\"' + $Platform + '\"' + if (-not ($Configuration -like "*libcpp*")) { + $gnargs += ' use_custom_libcxx=false' + } + + $gnargs += ' target_cpu=\"' + $Platform + '\"' if ($Configuration -like "*clang") { #TODO (#2): we need to figure out how to actually build DEBUG with clang-cl (won't work today due to STL iterator issues) @@ -118,7 +135,7 @@ Copy-Item "$jsigitpath\jsi\jsi.cpp" -Destination "$OutputPath\build\native\inclu Copy-Item "$jsigitpath\jsi\instrumentation.h" -Destination "$OutputPath\build\native\include\jsi\" # Miscellaneous -Copy-Item "$SourcesPath\ReactNative.V8Jsi.Windows.nuspec" -Destination "$OutputPath\" +#Copy-Item "$SourcesPath\ReactNative.V8Jsi.Windows.nuspec" -Destination "$OutputPath\" Copy-Item "$SourcesPath\ReactNative.V8Jsi.Windows.targets" -Destination "$OutputPath\build\native\" Copy-Item "$SourcesPath\config.json" -Destination "$OutputPath\" Copy-Item "$SourcesPath\LICENSE" -Destination "$OutputPath\license\" diff --git a/scripts/fetch_code.ps1 b/scripts/fetch_code.ps1 index b507adf..ebe716f 100644 --- a/scripts/fetch_code.ps1 +++ b/scripts/fetch_code.ps1 @@ -2,6 +2,7 @@ # Licensed under the MIT license. param( [string]$SourcesPath = $PSScriptRoot, + [string]$OutputPath = "$PSScriptRoot\out", [string]$Configuration = "Release" ) @@ -27,7 +28,7 @@ $env:GIT_REDIRECT_STDERR = '2>&1' $config = Get-Content (Join-Path $SourcesPath "config.json") | Out-String | ConvertFrom-Json & git fetch origin $config.v8ref -& git checkout FETCH_HEAD +$CheckOutVersion = (git checkout FETCH_HEAD) | Out-String & gclient sync #TODO (#2): Submit PR upstream to Google for this fix @@ -42,7 +43,26 @@ if (!$PSVersionTable.Platform -or $IsWindows) { Pop-Location Pop-Location -Write-Host "##vso[task.setvariable variable=V8JSI_VERSION;]$config.version" +$verString = $config.version + +$gitRevision = "" +$v8Version = "" + +$Matches = $CheckOutVersion | Select-String -Pattern 'HEAD is now at (.+) Version (.+)' +if ($Matches.Matches.Success) { + $gitRevision = $Matches.Matches.Groups[1].Value + $v8Version = $Matches.Matches.Groups[2].Value.Trim() + $verString = $verString + "-v8_" + $v8Version.Replace('.', '_') +} + +# Save the revision information in the NuGet description +if (!(Test-Path -Path $OutputPath)) { + New-Item -ItemType "directory" -Path $OutputPath | Out-Null +} + +(Get-Content "$SourcesPath\ReactNative.V8Jsi.Windows.nuspec") -replace ('VERSION_DETAILS', "V8 version: $v8Version; Git revision: $gitRevision") | Set-Content "$OutputPath\ReactNative.V8Jsi.Windows.nuspec" + +Write-Host "##vso[task.setvariable variable=V8JSI_VERSION;]$verString" # Install build depndencies for Android if ($PSVersionTable.Platform -and !$IsWindows) { @@ -54,28 +74,15 @@ if ($PSVersionTable.Platform -and !$IsWindows) { #TODO (#2): Use the .gzip for Android / Linux builds # Verify the Boost installation if (-not (Test-Path "$env:BOOST_ROOT\boost\asio.hpp")) { - - if (-not (Test-Path (Join-Path $workpath "v8build\boost\boost_1_72_0\boost\asio.hpp"))) { + if (-not (Test-Path (Join-Path $workpath "v8build/boost.1.71.0.0/lib/native/include/boost/asio.hpp"))) { Write-Host "Boost ASIO not found, downloading..." - # This operation will take a long time, but it's required on the Azure Agents because they don't have ASIO headers - $output = [System.IO.Path]::GetTempFileName() + $targetNugetExe = Join-Path $workpath "nuget.exe" + Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $targetNugetExe - # If 7-zip is available on path, use it as it's much faster and lets us unpack just the folder we need - if (Get-Command "7z.exe" -ErrorAction SilentlyContinue) { - Invoke-WebRequest -Uri "https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.7z" -OutFile "$output.7z" - Write-Host "Unzipping archive..." - 7z x "$output.7z" -o"$workpath\v8build\boost" -i!boost_1_72_0\boost - Remove-Item "$output.7z" - } - else { - Invoke-WebRequest -Uri "https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.zip" -OutFile "$output.zip" - Write-Host "Unzipping archive..." - Expand-Archive -path "$output.zip" -DestinationPath "$workpath\v8build\boost" - Remove-Item "$output.zip" - } + & $targetNugetExe install -OutputDirectory (Join-Path $workpath "v8build") boost -Version 1.71.0 } - $env:BOOST_ROOT = Join-Path $workpath "v8build\boost\boost_1_72_0" - Write-Host "##vso[task.setvariable variable=BOOST_ROOT;]$workpath\v8build\boost\boost_1_72_0" + $env:BOOST_ROOT = Join-Path $workpath "v8build/boost.1.71.0.0/lib/native/include" + Write-Host "##vso[task.setvariable variable=BOOST_ROOT;]$env:BOOST_ROOT" } diff --git a/src/BUILD.gn b/src/BUILD.gn index e3f3f3d..a39eaf1 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -17,6 +17,8 @@ target("shared_library", "v8jsi") { "V8Platform.h", ] + cflags = [ "-DBOOST_ASIO_STANDALONE", "-DBOOST_ASIO_HEADER_ONLY" ] + if (is_win) { sources += [ "etw/tracing.h", diff --git a/src/inspector/inspector_agent.cpp b/src/inspector/inspector_agent.cpp index 1dbb0f6..1ef1de0 100644 --- a/src/inspector/inspector_agent.cpp +++ b/src/inspector/inspector_agent.cpp @@ -15,12 +15,10 @@ #include #include #include - #include - -#include -#include -#include +#include +#include +#include namespace inspector { @@ -42,9 +40,21 @@ std::string GetProcessTitle() { } std::string GenerateID() { - boost::uuids::uuid uuid = boost::uuids::random_generator()(); - return boost::uuids::to_string(uuid); - //return "RANDON_UUID"; + static std::random_device rd; + static std::mt19937 mte(rd()); + + std::uniform_int_distribution dist; + + std::array buffer; + std::generate(buffer.begin(), buffer.end(), [&] () { return dist(mte); }); + + char uuid[256]; + snprintf(uuid, sizeof(uuid), "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", + buffer[0], buffer[1], buffer[2], + (buffer[3] & 0x0fff) | 0x4000, + (buffer[4] & 0x3fff) | 0x8000, + buffer[5], buffer[6], buffer[7]); + return uuid; } std::string StringViewToUtf8(const v8_inspector::StringView &view) { diff --git a/src/inspector/inspector_socket.cpp b/src/inspector/inspector_socket.cpp index 1d0f998..da2b5ef 100644 --- a/src/inspector/inspector_socket.cpp +++ b/src/inspector/inspector_socket.cpp @@ -73,7 +73,7 @@ class TcpHolder { void read_loop(); - boost::shared_ptr connection() { return connection_; }; + std::shared_ptr connection() { return connection_; }; InspectorSocket::Delegate* delegate(); static void OnClosedCallback(void*data); @@ -84,7 +84,7 @@ class TcpHolder { tcp_connection::pointer connection_; - explicit TcpHolder(boost::shared_ptr connection, InspectorSocket::DelegatePointer delegate); + explicit TcpHolder(std::shared_ptr connection, InspectorSocket::DelegatePointer delegate); ~TcpHolder() = default; const InspectorSocket::DelegatePointer delegate_; @@ -638,7 +638,7 @@ std::string ProtocolHandler::GetHost() const { } // RAII uv_tcp_t wrapper -TcpHolder::TcpHolder(boost::shared_ptr connection, InspectorSocket::DelegatePointer delegate) +TcpHolder::TcpHolder(std::shared_ptr connection, InspectorSocket::DelegatePointer delegate) : delegate_(std::move(delegate)), connection_(connection), handler_(nullptr) { } @@ -712,7 +712,7 @@ void InspectorSocket::Shutdown(ProtocolHandler* handler) { } // static -InspectorSocket::Pointer InspectorSocket::Accept(boost::shared_ptr connection, DelegatePointer delegate) { +InspectorSocket::Pointer InspectorSocket::Accept(std::shared_ptr connection, DelegatePointer delegate) { auto tcp = TcpHolder::Accept(connection, std::move(delegate)); if (tcp) { InspectorSocket* inspector = new InspectorSocket(); diff --git a/src/inspector/inspector_socket.h b/src/inspector/inspector_socket.h index e62cf34..ca33795 100644 --- a/src/inspector/inspector_socket.h +++ b/src/inspector/inspector_socket.h @@ -38,7 +38,7 @@ class InspectorSocket { using DelegatePointer = std::unique_ptr; using Pointer = std::unique_ptr; - static Pointer Accept(boost::shared_ptr connection, DelegatePointer delegate); + static Pointer Accept(std::shared_ptr connection, DelegatePointer delegate); ~InspectorSocket(); diff --git a/src/inspector/inspector_socket_server.cpp b/src/inspector/inspector_socket_server.cpp index 84227a3..5caafec 100644 --- a/src/inspector/inspector_socket_server.cpp +++ b/src/inspector/inspector_socket_server.cpp @@ -311,7 +311,7 @@ std::string InspectorSocketServer::GetFrontendURL(bool is_compat, return frontend_url.str(); } -/*static */void InspectorSocketServer::SocketConnectedCallback(boost::shared_ptr connection, void* callbackData_) { +/*static */void InspectorSocketServer::SocketConnectedCallback(std::shared_ptr connection, void* callbackData_) { InspectorSocketServer* server = reinterpret_cast(callbackData_); server->Accept(connection, server->port_); } @@ -358,7 +358,7 @@ int InspectorSocketServer::Port() const { return port_; } -void InspectorSocketServer::Accept(boost::shared_ptr connection, int server_port) { +void InspectorSocketServer::Accept(std::shared_ptr connection, int server_port) { std::unique_ptr session( new SocketSession(this, next_session_id_++, server_port)); diff --git a/src/inspector/inspector_socket_server.h b/src/inspector/inspector_socket_server.h index 67f4be3..a5b6612 100644 --- a/src/inspector/inspector_socket_server.h +++ b/src/inspector/inspector_socket_server.h @@ -46,7 +46,7 @@ public: int Port() const; // Session connection lifecycle - void Accept(boost::shared_ptr connection, int server_port/*, uv_stream_t* server_socket*/); + void Accept(std::shared_ptr connection, int server_port/*, uv_stream_t* server_socket*/); bool HandleGetRequest(int session_id, const std::string& host, const std::string& path); void SessionStarted(int session_id, const std::string& target_id, const std::string& ws_id); void SessionTerminated(int session_id); @@ -58,7 +58,7 @@ public: // return server_sockets_.empty() && connected_sessions_.empty(); //} - static void InspectorSocketServer::SocketConnectedCallback(boost::shared_ptr connection, void* callbackData_); + static void InspectorSocketServer::SocketConnectedCallback(std::shared_ptr connection, void* callbackData_); static void InspectorSocketServer::SocketClosedCallback(void* callbackData_); private: diff --git a/src/inspector/inspector_tcp.cpp b/src/inspector/inspector_tcp.cpp index ae0d23c..41c4c8f 100644 --- a/src/inspector/inspector_tcp.cpp +++ b/src/inspector/inspector_tcp.cpp @@ -3,9 +3,8 @@ // This code is based on the old node inspector implementation. See LICENSE_NODE for Node.js' project license details #include "inspector_tcp.h" -#include -#include -#include +#include + #include namespace inspector { diff --git a/src/inspector/inspector_tcp.h b/src/inspector/inspector_tcp.h index 0420be6..ef38ed1 100644 --- a/src/inspector/inspector_tcp.h +++ b/src/inspector/inspector_tcp.h @@ -3,19 +3,17 @@ // This code is based on the old node inspector implementation. See LICENSE_NODE for Node.js' project license details #pragma once -#include -#include -#include #include #include +#include namespace inspector { -class tcp_connection : public boost::enable_shared_from_this +class tcp_connection : public std::enable_shared_from_this { public: - typedef boost::shared_ptr pointer; + typedef std::shared_ptr pointer; static pointer create(boost::asio::ip::tcp::socket socket); boost::asio::ip::tcp::socket& socket(); @@ -56,10 +54,10 @@ private: bool writing_{ false }; }; -class tcp_server : public boost::enable_shared_from_this { +class tcp_server : public std::enable_shared_from_this { public: typedef std::shared_ptr pointer; - typedef void(*ConnectionCallback)(boost::shared_ptr connection, void* callbackData_); + typedef void(*ConnectionCallback)(std::shared_ptr connection, void* callbackData_); void run();