mirror of
https://github.com/ivabus/pantry
synced 2024-11-25 18:05:07 +03:00
+wangle (#1858)
* +wangle * fix cmake files * [wip] Add test * whole bunch of fixes * Darwin folly deps * Kills can fail * skip cleanup (breaks testing) * this is thorny * nevermind --------- Co-authored-by: Jacob Heider <jacob@tea.xyz>
This commit is contained in:
parent
1084be91f2
commit
572fa511cb
6 changed files with 293 additions and 8 deletions
|
@ -18,6 +18,9 @@ dependencies:
|
|||
google.github.io/snappy: '*'
|
||||
google.com/double-conversion: ^3
|
||||
fmt.dev: ^9
|
||||
darwin:
|
||||
sourceware.org/bzip2: '*'
|
||||
zlib.net: '*'
|
||||
|
||||
build:
|
||||
dependencies:
|
||||
|
@ -35,8 +38,14 @@ build:
|
|||
script:
|
||||
- test -d xyz.tea.srcs && rm -rf xyz.tea.srcs
|
||||
- mv $SRCROOT xyz.tea.srcs
|
||||
- cmake $ARGS -S xyz.tea.srcs -B .
|
||||
- make --jobs {{hw.concurrency}} install
|
||||
- cmake $ARGS -DBUILD_SHARED_LIBS=ON -S xyz.tea.srcs -B shared
|
||||
- cmake --build shared
|
||||
- cmake --install shared
|
||||
|
||||
- cmake $ARGS -DBUILD_SHARED_LIBS=OFF -S xyz.tea.srcs -B static
|
||||
- cmake --build static
|
||||
- run: cp /tmp/xyz.tea.folly/static/libfolly.a libfollybenchmark.a
|
||||
working-directory: ${{prefix}}/static/folly
|
||||
|
||||
- run: |
|
||||
sed -E -i.bak \
|
||||
|
|
95
projects/facebook.com/wangle/EchoClient.cpp
Normal file
95
projects/facebook.com/wangle/EchoClient.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <folly/portability/GFlags.h>
|
||||
|
||||
#include <folly/init/Init.h>
|
||||
#include <wangle/bootstrap/ClientBootstrap.h>
|
||||
#include <wangle/channel/AsyncSocketHandler.h>
|
||||
#include <wangle/channel/EventBaseHandler.h>
|
||||
#include <wangle/codec/LineBasedFrameDecoder.h>
|
||||
#include <wangle/codec/StringCodec.h>
|
||||
|
||||
using namespace folly;
|
||||
using namespace wangle;
|
||||
|
||||
DEFINE_int32(port, 8080, "echo server port");
|
||||
DEFINE_string(host, "::1", "echo server address");
|
||||
|
||||
typedef Pipeline<folly::IOBufQueue&, std::string> EchoPipeline;
|
||||
|
||||
// the handler for receiving messages back from the server
|
||||
class EchoHandler : public HandlerAdapter<std::string> {
|
||||
public:
|
||||
void read(Context*, std::string msg) override {
|
||||
std::cout << "received back: " << msg;
|
||||
}
|
||||
void readException(Context* ctx, exception_wrapper e) override {
|
||||
std::cout << exceptionStr(e) << std::endl;
|
||||
close(ctx);
|
||||
}
|
||||
void readEOF(Context* ctx) override {
|
||||
std::cout << "EOF received :(" << std::endl;
|
||||
close(ctx);
|
||||
}
|
||||
};
|
||||
|
||||
// chains the handlers together to define the response pipeline
|
||||
class EchoPipelineFactory : public PipelineFactory<EchoPipeline> {
|
||||
public:
|
||||
EchoPipeline::Ptr newPipeline(std::shared_ptr<AsyncTransport> sock) override {
|
||||
auto pipeline = EchoPipeline::create();
|
||||
pipeline->addBack(AsyncSocketHandler(sock));
|
||||
pipeline->addBack(
|
||||
EventBaseHandler()); // ensure we can write from any thread
|
||||
pipeline->addBack(LineBasedFrameDecoder(8192, false));
|
||||
pipeline->addBack(StringCodec());
|
||||
pipeline->addBack(EchoHandler());
|
||||
pipeline->finalize();
|
||||
return pipeline;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
folly::Init init(&argc, &argv);
|
||||
|
||||
ClientBootstrap<EchoPipeline> client;
|
||||
client.group(std::make_shared<folly::IOThreadPoolExecutor>(1));
|
||||
client.pipelineFactory(std::make_shared<EchoPipelineFactory>());
|
||||
auto pipeline = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get();
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
std::string line;
|
||||
std::getline(std::cin, line);
|
||||
if (line == "") {
|
||||
break;
|
||||
}
|
||||
|
||||
pipeline->write(line + "\r\n").get();
|
||||
if (line == "bye") {
|
||||
pipeline->close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cout << exceptionStr(e) << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
65
projects/facebook.com/wangle/EchoServer.cpp
Normal file
65
projects/facebook.com/wangle/EchoServer.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <folly/portability/GFlags.h>
|
||||
|
||||
#include <folly/init/Init.h>
|
||||
#include <wangle/bootstrap/ServerBootstrap.h>
|
||||
#include <wangle/channel/AsyncSocketHandler.h>
|
||||
#include <wangle/codec/LineBasedFrameDecoder.h>
|
||||
#include <wangle/codec/StringCodec.h>
|
||||
|
||||
using namespace folly;
|
||||
using namespace wangle;
|
||||
|
||||
DEFINE_int32(port, 8080, "echo server port");
|
||||
|
||||
typedef Pipeline<IOBufQueue&, std::string> EchoPipeline;
|
||||
|
||||
// the main logic of our echo server; receives a string and writes it straight
|
||||
// back
|
||||
class EchoHandler : public HandlerAdapter<std::string> {
|
||||
public:
|
||||
void read(Context* ctx, std::string msg) override {
|
||||
std::cout << "handling " << msg << std::endl;
|
||||
write(ctx, msg + "\r\n");
|
||||
}
|
||||
};
|
||||
|
||||
// where we define the chain of handlers for each messeage received
|
||||
class EchoPipelineFactory : public PipelineFactory<EchoPipeline> {
|
||||
public:
|
||||
EchoPipeline::Ptr newPipeline(std::shared_ptr<AsyncTransport> sock) override {
|
||||
auto pipeline = EchoPipeline::create();
|
||||
pipeline->addBack(AsyncSocketHandler(sock));
|
||||
pipeline->addBack(LineBasedFrameDecoder(8192));
|
||||
pipeline->addBack(StringCodec());
|
||||
pipeline->addBack(EchoHandler());
|
||||
pipeline->finalize();
|
||||
return pipeline;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
folly::Init init(&argc, &argv);
|
||||
|
||||
ServerBootstrap<EchoPipeline> server;
|
||||
server.childPipeline(std::make_shared<EchoPipelineFactory>());
|
||||
server.bind(FLAGS_port);
|
||||
server.waitForStop();
|
||||
|
||||
return 0;
|
||||
}
|
108
projects/facebook.com/wangle/package.yml
Normal file
108
projects/facebook.com/wangle/package.yml
Normal file
|
@ -0,0 +1,108 @@
|
|||
distributable:
|
||||
url: https://github.com/facebook/wangle/archive/refs/tags/v{{version.raw}}.tar.gz
|
||||
strip-components: 1
|
||||
|
||||
versions:
|
||||
github: facebook/wangle
|
||||
strip: /v/
|
||||
|
||||
dependencies:
|
||||
boost.org: '*'
|
||||
google.com/double-conversion: ^3
|
||||
github.com/facebookincubator/fizz: '*'
|
||||
fmt.dev: ^9
|
||||
facebook.com/folly: '*'
|
||||
gflags.github.io: '*'
|
||||
google.com/glog: '*'
|
||||
libevent.org: '*'
|
||||
libsodium.org: '*'
|
||||
lz4.org: ^1
|
||||
openssl.org: ^1.1
|
||||
google.github.io/snappy: '*'
|
||||
facebook.com/zstd: ^1
|
||||
darwin:
|
||||
sourceware.org/bzip2: '*'
|
||||
zlib.net: '*'
|
||||
|
||||
build:
|
||||
dependencies:
|
||||
tea.xyz/gx/cc: c99
|
||||
tea.xyz/gx/make: '*'
|
||||
cmake.org: ^3
|
||||
working-directory: wangle
|
||||
script:
|
||||
- cmake . -DBUILD_SHARED_LIBS=ON $ARGS
|
||||
- make install
|
||||
- make clean
|
||||
|
||||
- cmake . -DBUILD_SHARED_LIBS=OFF $ARGS
|
||||
- make
|
||||
- cp lib/libwangle.a {{prefix}}/lib
|
||||
|
||||
- sed -i.bak "s:$(tea --prefix):\$\{_IMPORT_PREFIX\}/../../../..:g" "{{prefix}}"/lib/cmake/wangle/wangle-targets.cmake
|
||||
- rm "{{prefix}}"/lib/cmake/wangle/wangle-targets.cmake.bak
|
||||
env:
|
||||
ARGS:
|
||||
- -DCMAKE_INSTALL_PREFIX={{prefix}}
|
||||
- -DCMAKE_BUILD_TYPE=Release
|
||||
- -DBUILD_TESTS=OFF
|
||||
|
||||
test:
|
||||
dependencies:
|
||||
tea.xyz/gx/cc: c99
|
||||
curl.se: '*'
|
||||
script:
|
||||
- c++ $CXXFLAGS 'EchoClient.cpp' -o EchoClient
|
||||
- c++ $CXXFLAGS 'EchoServer.cpp' -o EchoServer
|
||||
|
||||
# This should all work; but it doesn't in GHA.
|
||||
# We should FIXME.
|
||||
# # Find a free port
|
||||
# - FREE_PORT=0
|
||||
# - run: |
|
||||
# FREE_PORT=49152
|
||||
# while lsof -i:$FREE_PORT >/dev/null 2>&1; do
|
||||
# ((FREE_PORT++))
|
||||
# done
|
||||
|
||||
# # Start the EchoServer
|
||||
# - run: |
|
||||
# ./EchoServer -port "${FREE_PORT}" &
|
||||
# SERVER_PID=$!
|
||||
# - sleep 10
|
||||
|
||||
# # Send test lines to the EchoClient
|
||||
# - run: |
|
||||
# ./EchoClient -port "${FREE_PORT}" > out << EOF || true
|
||||
# Hello from tea!
|
||||
# Another test line.
|
||||
# EOF
|
||||
# CLIENT_BACKGROUND_PID=$!
|
||||
|
||||
# - sleep 20
|
||||
|
||||
# # Check the output for the test lines
|
||||
# - grep "Hello from tea!" out
|
||||
# - grep "Another test line." out
|
||||
env:
|
||||
CXXFLAGS:
|
||||
- -std=c++17
|
||||
- -lgflags
|
||||
- -lglog
|
||||
- -lfolly
|
||||
- -lfizz
|
||||
- -lwangle
|
||||
- -lssl
|
||||
- -lcrypto
|
||||
- -lfmt
|
||||
- -ldouble-conversion
|
||||
- -levent
|
||||
- -lboost_context
|
||||
darwin:
|
||||
CXXFLAGS:
|
||||
- -lc++abi
|
||||
linux:
|
||||
CXXFLAGS:
|
||||
- -ldl
|
||||
- -lpthread
|
||||
- -latomic
|
|
@ -33,6 +33,9 @@ build:
|
|||
cmake -S fizz -B build $ARGS
|
||||
cmake --build build
|
||||
cmake --install build
|
||||
|
||||
sed -i.bak "s:$(tea --prefix):\$\{_IMPORT_PREFIX\}/../../../..:g" "{{prefix}}"/lib/cmake/fizz/fizz-targets.cmake
|
||||
rm "{{prefix}}"/lib/cmake/fizz/fizz-targets.cmake.bak
|
||||
env:
|
||||
ARGS:
|
||||
- -GNinja
|
||||
|
|
|
@ -12,19 +12,24 @@ build:
|
|||
freedesktop.org/pkg-config: '*'
|
||||
cmake.org: '*'
|
||||
gnu.org/patch: '*'
|
||||
script: |
|
||||
script:
|
||||
# disable -Werror (because there are warnings lol)
|
||||
patch -p1 <props/CMakeLists.txt.patch
|
||||
cmake . $ARGS
|
||||
make
|
||||
make install
|
||||
- patch -p1 <props/CMakeLists.txt.patch
|
||||
# disable no-rtti, since it messes up folly
|
||||
- run: |
|
||||
sed -i.bak -e '/# Disable RTTI./{N;N;d;}' CMakeLists.txt
|
||||
rm CMakeLists.txt.bak
|
||||
- cmake . $ARGS
|
||||
- make install
|
||||
- make clean
|
||||
- cmake . -DBUILD_SHARED_LIBS=ON $ARGS
|
||||
- make install
|
||||
env:
|
||||
ARGS:
|
||||
- -DCMAKE_INSTALL_PREFIX={{prefix}}
|
||||
- -DCMAKE_BUILD_TYPE=Release
|
||||
- -DSNAPPY_BUILD_TESTS=OFF
|
||||
- -DSNAPPY_BUILD_BENCHMARKS=OFF
|
||||
- -DBUILD_SHARED_LIBS=ON
|
||||
|
||||
test:
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in a new issue