Skip to content

Commit

Permalink
Merge pull request #2333 from RedstoneWizard08/master
Browse files Browse the repository at this point in the history
Add support for arm64 linux.
  • Loading branch information
murgatroid99 authored Jan 31, 2023
2 parents fe4272e + 4b9e401 commit 8fd930b
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules/
npm-debug.log
yarn-error.log
yarn.lock
artifacts

# Emacs temp files
*~
Expand All @@ -15,6 +16,7 @@ yarn.lock
reports/

package-lock.json
pnpm-lock.yaml

# Test generated files
coverage
Expand Down
7 changes: 7 additions & 0 deletions packages/grpc-tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CMakeFiles/
cmake_install.cmake
CMakeCache.txt
Makefile
grpc_node_plugin
protoc
deps/protobuf
83 changes: 44 additions & 39 deletions packages/grpc-tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,55 +1,60 @@
cmake_minimum_required(VERSION 3.7)
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.7" CACHE STRING "Minimum OS X deployment version" FORCE)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
CMAKE_MINIMUM_REQUIRED(VERSION 3.7)
PROJECT("grpc-tools")

SET(CMAKE_OSX_DEPLOYMENT_TARGET "11.7" CACHE STRING "Minimum OS X deployment version" FORCE)

IF(COMMAND CMAKE_POLICY)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(COMMAND CMAKE_POLICY)

# MSVC runtime library flags are selected by an abstraction.
if(COMMAND cmake_policy AND POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
IF(COMMAND CMAKE_POLICY AND POLICY CMP0091)
CMAKE_POLICY(SET CMP0091 NEW)
ENDIF()

SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
SET(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests")
SET(protobuf_WITH_ZLIB OFF CACHE BOOL "Build protobuf with zlib.")
SET(PROTOBUF_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/protobuf)

set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests")
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build protobuf with zlib.")
set(PROTOBUF_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/protobuf)
add_subdirectory(${PROTOBUF_ROOT_DIR}/cmake deps/protobuf)
ADD_SUBDIRECTORY(${PROTOBUF_ROOT_DIR}/cmake deps/protobuf)

set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector")
SET(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector")

add_executable(grpc_node_plugin
src/node_generator.cc
src/node_plugin.cc
ADD_EXECUTABLE(grpc_node_plugin
src/node_generator.cc
src/node_plugin.cc
)

if (MSVC)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
else ()
foreach (flag_var
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif (${flag_var} MATCHES "/MD")
endforeach (flag_var)
endif ()
endif (MVC)

target_include_directories(grpc_node_plugin
IF(MSVC)
IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
SET(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
ELSE()
FOREACH(flag_var
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
IF(${flag_var} MATCHES "/MD")
STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
ENDIF(${flag_var} MATCHES "/MD")
ENDFOREACH(flag_var)
ENDIF()
ENDIF(MSVC)

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
TARGET_LINK_LIBRARIES(grpc_node_plugin
libprotoc
libprotobuf
)
76 changes: 41 additions & 35 deletions packages/grpc-tools/build_binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,68 @@ set -e

uname -a

cd $(dirname $0)
cd "$(dirname "$0")"
base=$(pwd)
protobuf_base=$base/deps/protobuf

tools_version=$(jq '.version' < package.json | tr -d '"')
tools_version=$(jq '.version' <package.json | tr -d '"')

# Note: artifacts should not be output in the package directory
out_dir=$base/../../artifacts/grpc-tools/v$tools_version
mkdir -p "$out_dir"

build () {
build() {
cmake_flag=$*

rm -rf $base/build/bin
rm -f $base/CMakeCache.txt
rm -rf $base/CMakeFiles
rm -f $protobuf_base/CMakeCache.txt
rm -rf $protobuf_base/CMakeFiles
cmake $cmake_flag . && cmake --build . --target clean && cmake --build . -- -j 12
mkdir -p $base/build/bin
cp -L $protobuf_base/protoc $base/build/bin/protoc
cp $base/grpc_node_plugin $base/build/bin/
file $base/build/bin/*
rm -rf "$base/build/bin"
rm -f "$base/CMakeCache.txt"
rm -rf "$base/CMakeFiles"
rm -f "$protobuf_base/CMakeCache.txt"
rm -rf "$protobuf_base/CMakeFiles"

cmake -DCMAKE_TOOLCHAIN_FILE=linux.toolchain.cmake $cmake_flag . && cmake --build . --target clean && cmake --build . -- -j 12

mkdir -p "$base/build/bin"

cp -L "$protobuf_base/protoc" "$base/build/bin/protoc"
cp "$base/grpc_node_plugin" "$base/build/bin/"

file "$base/build/bin"/*
}

artifacts() {
platform=$1
arch=$2
dir=$3
case $(uname -s) in
Linux)
tar -czf $out_dir/$platform-$arch.tar.gz -C $(dirname $dir) $(basename $dir)
;;
Darwin)
tar --format=gnutar -czf $out_dir/$platform-$arch.tar.gz -C $(dirname $dir) $(basename $dir)
;;
Linux)
tar -czf "$out_dir/$platform-$arch.tar.gz" -C "$(dirname "$dir")" "$(basename "$dir")"
;;
Darwin)
tar --format=gnutar -czf "$out_dir/$platform-$arch.tar.gz" -C "$(dirname "$dir")" "$(basename "$dir")"
;;
esac
}

case $(uname -s) in
Linux)
build -DCMAKE_TOOLCHAIN_FILE=linux_32bit.toolchain.cmake
artifacts linux ia32 $base/build/bin
build -DCMAKE_TOOLCHAIN_FILE=linux_64bit.toolchain.cmake
artifacts linux x64 $base/build/bin
;;
Darwin)
build -DCMAKE_TOOLCHAIN_FILE=linux_64bit.toolchain.cmake -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
Linux)
build -DGRPC_TOOLS_TARGET=i686
artifacts linux ia32 "$base/build/bin"
build -DGRPC_TOOLS_TARGET=x86_64
artifacts linux x64 "$base/build/bin"
build -DGRPC_TOOLS_TARGET=aarch64
artifacts linux arm64 "$base/build/bin"
;;
Darwin)
build -DGRPC_TOOLS_TARGET=x86_64 -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"

for arch in "x64" "arm64"; do
mkdir $base/build/bin/$arch
for bin in protoc grpc_node_plugin; do
lipo -extract x86_64 $base/build/bin/$bin -o $base/build/bin/$arch/$bin
otool -l $base/build/bin/$arch/$bin | grep minos
done
artifacts darwin $arch $base/build/bin/$arch/
for arch in "x64" "arm64"; do
mkdir "$base/build/bin/$arch"
for bin in protoc grpc_node_plugin; do
lipo -extract x86_64 "$base/build/bin/$bin" -o "$base/build/bin/$arch/$bin"
otool -l "$base/build/bin/$arch/$bin" | grep minos
done
;;
artifacts darwin $arch "$base/build/bin/$arch/"
done
;;
esac
32 changes: 32 additions & 0 deletions packages/grpc-tools/linux.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
IF(UNIX AND NOT APPLE)
SET(CMAKE_COMPILER_PREFIX "")

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -Wl,-Bstatic")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -Wl,-Bstatic")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,-Bstatic")

IF(GRPC_TOOLS_TARGET STREQUAL "x86_64")
SET(CMAKE_COMPILER_PREFIX "x86_64-linux-gnu-")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64")
ENDIF()

IF(GRPC_TOOLS_TARGET STREQUAL "i686")
SET(CMAKE_COMPILER_PREFIX "i686-linux-gnu-")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
ENDIF()

IF(GRPC_TOOLS_TARGET STREQUAL "aarch64")
SET(CMAKE_COMPILER_PREFIX "aarch64-linux-gnu-")
ENDIF()

SET(CMAKE_C_COMPILER "${CMAKE_COMPILER_PREFIX}gcc")
SET(CMAKE_CXX_COMPILER "${CMAKE_COMPILER_PREFIX}g++")
ELSE()
MESSAGE(WARNING "OS is not linux, not setting variables.")
ENDIF()
3 changes: 0 additions & 3 deletions packages/grpc-tools/linux_32bit.toolchain.cmake

This file was deleted.

3 changes: 0 additions & 3 deletions packages/grpc-tools/linux_64bit.toolchain.cmake

This file was deleted.

18 changes: 16 additions & 2 deletions tools/release/native/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
FROM debian:stretch
# NOTE: We don't have to worry about glibc versions
# because we use static linking during the
# compile step.
# (See packages/grpc-tools/CMakeLists.txt#L25)

FROM ubuntu:22.04

RUN apt-get update
RUN apt-get install -y cmake curl build-essential python libc6-dev-i386 lib32stdc++-6-dev jq
RUN apt-get install -y cmake curl build-essential \
python3 libc6-dev-i386-cross libc6-dev-amd64-cross \
libc6-dev-arm64-cross lib32stdc++6-amd64-cross jq \
lib32stdc++6-x32-cross libstdc++6-amd64-cross \
libstdc++6-arm64-cross libstdc++6-i386-cross \
gcc-i686-linux-gnu g++-i686-linux-gnu tar file \
gcc-x86-64-linux-gnu g++-x86-64-linux-gnu binutils \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu make \
gcc g++ gzip bash libc6-amd64-i386-cross \
libc6-dev-amd64-i386-cross

RUN mkdir /usr/local/nvm
ENV NVM_DIR /usr/local/nvm
Expand Down

0 comments on commit 8fd930b

Please sign in to comment.