Skip to content

Commit

Permalink
refactor protocol using protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
netanelc305 committed Dec 20, 2023
1 parent 99073f7 commit 245176a
Show file tree
Hide file tree
Showing 37 changed files with 1,404 additions and 1,640 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
# TODO: remove when lief releases the 3.12 wheel (https://github.com/lief-project/LIEF/issues/990)
if: matrix.python-version != 3.12
run: |
python3 -m pip install mypy-protobuf protobuf grpcio-tools
make -C ../protos/ python_protos
python -m pip install build
python3 -m build
- name: Install
Expand Down Expand Up @@ -80,7 +82,15 @@ jobs:
fi
- name: Test make
run: |
make clean all
sudo apt-get update
sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev protobuf-c-compiler
make -C ../protos/ c_protos
mkdir build
cd build
cmake .. -DTARGET=LINUX
make
pytest:
if: '! github.event.pull_request.draft'
Expand Down Expand Up @@ -137,11 +147,18 @@ jobs:
- name: Run server
working-directory: ./src/rpcserver
run: |
make SERVER_CFLAGS=-DSAFE_READ_WRITES
sudo nohup ./rpcserver &
brew install protobuf protobuf-c
make -C ../protos/ c_protos
mkdir build
cd build
cmake .. -DTARGET=OSX
make
sudo nohup ./rpcserver_macosx &
- name: Install python package + pytest
working-directory: ./src/rpcclient
run: |
python3 -m pip install mypy-protobuf protobuf grpcio-tools
make -C ../protos/ python_protos
python -m pip install --upgrade pip
python -m pip install -U pytest
python -m pip install -U .
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
python-version: '3.x'
- name: Install dependencies
run: |
python3 -m pip install mypy-protobuf protobuf grpcio-tools
make -C ../protos/ python_protos
python -m pip install --upgrade pip
pip install -U build setuptools wheel twine
- name: Build and publish
Expand Down
41 changes: 24 additions & 17 deletions .github/workflows/server-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,45 @@ jobs:
name: Build server on ubuntu
working-directory: ./src/rpcserver
run: |
make SERVER_CFLAGS=-DSAFE_READ_WRITES
sudo apt-get update
sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev protobuf-c-compiler
make -C ../protos/ c_protos
mkdir build
cd build
cmake .. -DTARGET=LINUX
make
- if: matrix.os == 'ubuntu-latest'
name: Upload ubuntu server artifact
uses: actions/upload-artifact@v3
with:
name: rpcserver_ubuntu_x86_64
path: ./src/rpcserver/rpcserver
name: rpcserver_linux
path: ./src/rpcserver/build/rpcserver_linux

- if: matrix.os == 'macos-latest'
name: Build server on macos
working-directory: ./src/rpcserver
run: |
./build_darwin.sh
brew install protobuf protobuf-c
make -C ../protos/ c_protos
mkdir build
cd build
cmake .. -DTARGET=IOS
make
cmake .. -DTARGET=OSX
make
- if: matrix.os == 'macos-latest'
name: Upload iphoneos server artifact
uses: actions/upload-artifact@v3
with:
name: rpcserver_iphoneos_arm64
path: ./src/rpcserver/rpcserver_iphoneos_arm64
name: rpcserver_ios
path: ./src/rpcserver/build/rpcserver_ios

- if: matrix.os == 'macos-latest'
name: Upload macos,x86_64 server artifact
uses: actions/upload-artifact@v3
with:
name: rpcserver_macosx_x86_64
path: ./src/rpcserver/rpcserver_macosx_x86_64

- if: matrix.os == 'macos-latest'
name: Upload macos,arm64 server artifact
name: Upload macos server artifact
uses: actions/upload-artifact@v3
with:
name: rpcserver_macosx_arm64
path: ./src/rpcserver/rpcserver_macosx_arm64
name: rpcserver_macosx
path: ./src/rpcserver/build/rpcserver_macosx
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ _CodeSignature

# Build
**/_version.py
src/rpcserver/protos/
src/rpcclient/rpcclient/protos/
cmake-build-debug

# Third party
src/rpcserver/protobuf-c/
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ rpclocal

Download and execute the latest server artifact, according to your platform and arch from here:

- [rpcserver_iphoneos_arm64.zip](https://nightly.link/doronz88/rpc-project/workflows/server-publish/master/rpcserver_iphoneos_arm64.zip)
- [rpcserver_macosx_x86_64.zip](https://nightly.link/doronz88/rpc-project/workflows/server-publish/master/rpcserver_macosx_x86_64.zip)
- [rpcserver_ubuntu_x86_64.zip](https://nightly.link/doronz88/rpc-project/workflows/server-publish/master/rpcserver_ubuntu_x86_64.zip)
- [rpcserver_ios.zip](https://nightly.link/doronz88/rpc-project/workflows/server-publish/master/rpcserver_ios.zip)
- [rpcserver_macosx.zip](https://nightly.link/doronz88/rpc-project/workflows/server-publish/master/rpcserver_macosx.zip)
- [rpcserver_linux.zip](https://nightly.link/doronz88/rpc-project/workflows/server-publish/master/rpcserver_linux.zip)

If your specific platform and arch isn't listed, you can also [build it yourself](#building).

Expand All @@ -82,20 +82,39 @@ python3 -m pip install -U rpcclient

## Building

macOS & Linux:
**Note:** Cross-platform support is currently not available.

```shell
### macOS/iOS
For macOS/iOS (Ensure that Xcode is installed):

```bash
brew install protobuf protobuf-c
python3 -m pip install mypy-protobuf protobuf grpcio-tools
git clone git@github.com:doronz88/rpc-project.git
cd rpc-project
make -C src/protos/ all
cd src/rpcserver
mkdir build
cd build
cmake .. -DTARGET=OSX
make
cmake .. -DTARGET=IOS
make
```

iOS (Make sure to have XCode installed):
### Linux

```shell
```bash
sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev protobuf-c-compiler
python3 -m pip mypy-protobuf protobuf grpcio-tools
git clone git@github.com:doronz88/rpc-project.git
cd rpc-project
make -C src/protos/ all
cd src/rpcserver
./build_darwin.sh
mkdir build
cd build
cmake .. -DTARGET=LINUX
make
```

## Quickstart
Expand Down
21 changes: 21 additions & 0 deletions src/protos/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PROTO_FILES = rpc.proto
PYTHON_OUT_DIR=../rpcclient/rpcclient/protos/
C_OUT_DIR=../rpcserver/protos/

.PHONY: all c_protos python_protos clean

all: c_protos python_protos

c_protos: $(PROTO_FILES)
# Compile Protocol Buffers for C
mkdir -p $(C_OUT_DIR)
protoc --c_out=$(C_OUT_DIR) --proto_path=. $(PROTO_FILES)

python_protos: $(PROTO_FILES)
# Compile Protocol Buffers for Python
mkdir -p $(PYTHON_OUT_DIR)
python3 -m grpc_tools.protoc --python_out=$(PYTHON_OUT_DIR) --mypy_out=$(PYTHON_OUT_DIR) --proto_path=. $(PROTO_FILES)

clean:
# Clean up generated files
rm -rf $(C_OUT_DIR) $(PYTHON_OUT_DIR)
Loading

0 comments on commit 245176a

Please sign in to comment.