diff --git a/packages/grpc-tools/CMakeLists.txt b/packages/grpc-tools/CMakeLists.txt new file mode 100644 index 00000000..a7d58176 --- /dev/null +++ b/packages/grpc-tools/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.10) +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +set(PROTOBUF_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/protobuf) +add_subdirectory(${PROTOBUF_ROOT_DIR}/cmake deps/protobuf) + +set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests") +set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build protobuf with zlib.") + +add_executable(grpc_node_plugin + src/node_generator.cc + src/node_plugin.cc +) + + +target_include_directories(grpc_node_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src + PRIVATE ${PROTOBUF_ROOT_DIR}/include +) + +target_link_libraries(grpc_node_plugin + libprotoc + libprotobuf +) \ No newline at end of file diff --git a/packages/grpc-tools/build_binaries.ps1 b/packages/grpc-tools/build_binaries.ps1 new file mode 100644 index 00000000..7bfd9222 --- /dev/null +++ b/packages/grpc-tools/build_binaries.ps1 @@ -0,0 +1,47 @@ +Install-Module -Name 7Zip4Powershell + +function MkDir-p($Path) { + $FullPath = "\\?\" + $Path + if (-not (Test-Path -Path $FullPath)) { + New-Item -ItemType directory -Path $FullPath | Out-Null + } +} + +$WellKnownProtos = "any","api","compiler/plugin","descriptor","duration","empty","field_mask","source_context","struct","timestamp","type","wrappers" + +$Base = %~dp0 +cd $Base +$ProtobufBase = $Base + "/deps/protobuf" +MkDir-p $Base + "/build/bin" + +$PackageFile = $Base + "/package.json" +$ToolsVersion = (Get-Content $PackageFile) -join "`n" | ConvertFrom-Json | Get-Member -Name version + +$OutDir = $ARTIFACTS_OUT + "/grpc-tools/v" + $ToolsVersion +Mkdir-p $OutDir + +foreach ($Proto in $WellKnownProtos) { + Copy-Item $ProtobufBase + "/src/google/protobuf/" + $Proto + ".proto" -Destination $Base + "/build/bin/google/protobuf/" + $Proto + ".proto" +} + +$ArchList = "ia32","x64" + +foreach ($Arch in $ArchList) { + if ($Arch -eq "x64") { + $Generator = "Visual Studio 14 2015 Win64" + } else { + $Generator = "Visual Studio 14 2015" + } + Remove-Item $Base + "/build/bin/protoc.exe" + Remove-Item $Base + "/build/bin/grpc_node_plugin.exe" + Remove-Item $Base + "CMakeCache.txt" + + Invoke-Expression "cmake ." + Invoke-Expression "cmake --build ." + + Copy-Item $ProtobufBase + "/protoc.exe" -Destination $Base + "/build/bin/protoc.exe" + Copy-Item $Base + "/grpc_node_plugin.exe" -Destination $Base + "/build/bin/grpc_node_plugin.exe" + + Compress-7Zip -Path $Base + "/build" -Format Tar -ArchiveFileName $Base + "/Archive.tar" + Compress-7Zip -Path $Base + "/Archive.tar" -Format GZip -ArchiveFileName $OutDir + "/windows-x64.tar.gz" +} \ No newline at end of file diff --git a/packages/grpc-tools/build_binaries.sh b/packages/grpc-tools/build_binaries.sh new file mode 100755 index 00000000..60045d17 --- /dev/null +++ b/packages/grpc-tools/build_binaries.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e + +well_known_protos=( any api compiler/plugin descriptor duration empty field_mask source_context struct timestamp type wrappers ) + +cd $(dirname $0) +base=$(pwd) +protobuf_base=$base/deps/protobuf + +tools_version=$(jq '.version' < package.json | tr -d '"') + +out_dir=$ARTIFACTS_OUT/grpc-tools/v$tools_version +mkdir -p "$out_dir" + +mkdir -p "$base/build/bin/google/protobuf/compiler" +for proto in "${well_known_protos[@]}"; do + cp "$protobuf_base/src/google/protobuf/$proto.proto" "$base/build/bin/google/protobuf/$proto.proto" +done + +case $(uname -s) in + Linux) + platform=linux + arch_list=( ia32 x64 ) + ;; + Darwin) + platform=darwin + arch_list=( x64 ) + ;; +esac + +for arch in "${arch_list[@]}"; do + case $arch in + ia32) + toolchain_flag=-DCMAKE_TOOLCHAIN_FILE=linux_32bit.toolchain.cmake + ;; + *) + toolchain_flag= + ;; + esac + rm -f $base/build/bin/protoc + rm -f $base/build/bin/grpc_node_plugin + rm -f CMakeCache.txt + cmake $toolchain_flag . && cmake --build . --target clean && cmake --build . -- -j 12 + cp -L $protobuf_base/protoc $base/build/bin/protoc + cp $base/grpc_node_plugin $base/build/bin/ + cd $base/build + tar -czf "$out_dir/$platform-$arch.tar.gz" bin/ + cd $base +done \ No newline at end of file diff --git a/packages/grpc-tools/linux_32bit.toolchain.cmake b/packages/grpc-tools/linux_32bit.toolchain.cmake new file mode 100644 index 00000000..5a1b80f0 --- /dev/null +++ b/packages/grpc-tools/linux_32bit.toolchain.cmake @@ -0,0 +1,3 @@ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32" CACHE STRING "ld flags") \ No newline at end of file diff --git a/test/kokoro-nodejs-build-test.bat b/test/kokoro-nodejs-build-test.bat new file mode 100644 index 00000000..0ccf27ad --- /dev/null +++ b/test/kokoro-nodejs-build-test.bat @@ -0,0 +1,5 @@ +cd /d %~dp0 +cd .. + +call ./tools/release/kokoro-nodejs.bat +powershell -File ./packages/grpc-tools/build_binaries.ps1 \ No newline at end of file diff --git a/test/kokoro-nodejs-build-test.sh b/test/kokoro-nodejs-build-test.sh new file mode 100644 index 00000000..45371794 --- /dev/null +++ b/test/kokoro-nodejs-build-test.sh @@ -0,0 +1,6 @@ +set -e +cd $(dirname $0)/.. +base_dir=$(pwd) + +./tools/release/kokoro-nodejs.sh +ARTIFACTS_OUT=$base_dir/artifacts ./packages/grpc-tools/build_binaries.sh \ No newline at end of file diff --git a/test/kokoro/linux-build-nodejs.cfg b/test/kokoro/linux-build-nodejs.cfg index f64966a7..ba2f49f2 100644 --- a/test/kokoro/linux-build-nodejs.cfg +++ b/test/kokoro/linux-build-nodejs.cfg @@ -15,5 +15,5 @@ # Config file for Kokoro (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc-node/tools/release/kokoro-nodejs.sh" +build_file: "grpc-node/test/kokoro-nodejs-build-test.sh" timeout_mins: 60 diff --git a/test/kokoro/macos-build-nodejs.cfg b/test/kokoro/macos-build-nodejs.cfg index f64966a7..ba2f49f2 100644 --- a/test/kokoro/macos-build-nodejs.cfg +++ b/test/kokoro/macos-build-nodejs.cfg @@ -15,5 +15,5 @@ # Config file for Kokoro (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc-node/tools/release/kokoro-nodejs.sh" +build_file: "grpc-node/test/kokoro-nodejs-build-test.sh" timeout_mins: 60 diff --git a/test/kokoro/windows-build-nodejs.cfg b/test/kokoro/windows-build-nodejs.cfg index 3e934dee..87f44370 100644 --- a/test/kokoro/windows-build-nodejs.cfg +++ b/test/kokoro/windows-build-nodejs.cfg @@ -15,5 +15,5 @@ # Config file for Kokoro (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc-node/tools/release/kokoro-nodejs.bat" +build_file: "grpc-node/test/kokoro-nodejs-build-test.bat" timeout_mins: 60