mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-08 11:10:16 +00:00
Compare commits
6 Commits
4582c3075c
...
885274b2a1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
885274b2a1 | ||
|
|
ff50f6fb49 | ||
|
|
1bfa937346 | ||
|
|
066a4c3936 | ||
|
|
6038692611 | ||
|
|
2e99fbcd97 |
42
.github/workflows/main.yml
vendored
42
.github/workflows/main.yml
vendored
@ -102,7 +102,7 @@ jobs:
|
||||
run: python scripts/run_tests.py benchmark
|
||||
- name: Test Amalgamated Build
|
||||
run: python amalgamate.py
|
||||
build_android:
|
||||
build_android_libs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@ -116,9 +116,9 @@ jobs:
|
||||
add-to-path: false
|
||||
- name: Compile Shared Library
|
||||
run: |
|
||||
bash build_android.sh arm64-v8a
|
||||
bash build_android.sh armeabi-v7a
|
||||
bash build_android.sh x86_64
|
||||
bash build_android_libs.sh arm64-v8a
|
||||
bash build_android_libs.sh armeabi-v7a
|
||||
bash build_android_libs.sh x86_64
|
||||
|
||||
mkdir -p output/arm64-v8a
|
||||
mkdir -p output/armeabi-v7a
|
||||
@ -133,7 +133,7 @@ jobs:
|
||||
with:
|
||||
name: android
|
||||
path: output
|
||||
build_ios:
|
||||
build_darwin_libs:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@ -141,8 +141,22 @@ jobs:
|
||||
submodules: recursive
|
||||
- name: Compile Frameworks
|
||||
run: |
|
||||
git clone https://github.com/leetal/ios-cmake --depth 1 ~/ios-cmake
|
||||
bash build_ios.sh
|
||||
bash build_darwin_libs.sh
|
||||
mkdir -p output
|
||||
cp build/libpocketpy.a output/libpocketpy.a
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: darwin
|
||||
path: output
|
||||
build_ios_libs:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Compile Frameworks
|
||||
run: |
|
||||
bash build_ios_libs.sh
|
||||
mkdir -p output
|
||||
cp -r build/pocketpy.xcframework output/pocketpy.xcframework
|
||||
- uses: actions/upload-artifact@v4
|
||||
@ -175,7 +189,7 @@ jobs:
|
||||
|
||||
merge:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ build_win32, build_linux, build_darwin, build_android, build_ios ]
|
||||
needs: [ build_win32, build_linux, build_darwin, build_android_libs, build_darwin_libs, build_ios_libs ]
|
||||
steps:
|
||||
- name: "Create output directory"
|
||||
run: "mkdir $GITHUB_WORKSPACE/output"
|
||||
@ -192,18 +206,18 @@ jobs:
|
||||
name: linux
|
||||
path: $GITHUB_WORKSPACE/output/linux
|
||||
|
||||
# - name: "Merge darwin"
|
||||
# uses: actions/download-artifact@v4.1.7
|
||||
# with:
|
||||
# name: macos
|
||||
# path: $GITHUB_WORKSPACE/output/macos
|
||||
|
||||
- name: "Merge android"
|
||||
uses: actions/download-artifact@v4.1.7
|
||||
with:
|
||||
name: android
|
||||
path: $GITHUB_WORKSPACE/output/android
|
||||
|
||||
- name: "Merge darwin"
|
||||
uses: actions/download-artifact@v4.1.7
|
||||
with:
|
||||
name: darwin
|
||||
path: $GITHUB_WORKSPACE/output/darwin
|
||||
|
||||
- name: "Merge ios"
|
||||
uses: actions/download-artifact@v4.1.7
|
||||
with:
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,6 +1,3 @@
|
||||
[submodule "3rd/libhv/libhv"]
|
||||
path = 3rd/libhv/libhv
|
||||
url = https://github.com/ithewei/libhv.git
|
||||
[submodule "3rd/lz4/lz4"]
|
||||
path = 3rd/lz4/lz4
|
||||
url = https://github.com/lz4/lz4
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(libhv_bindings)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
option(BUILD_SHARED "build shared library" OFF)
|
||||
option(BUILD_STATIC "build static library" ON)
|
||||
option(BUILD_EXAMPLES "build examples" OFF)
|
||||
|
||||
option(WITH_OPENSSL "with openssl library" OFF)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/libhv)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_LIST_DIR}/src LIBHV_BINDINGS_SRC)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${LIBHV_BINDINGS_SRC})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} hv_static)
|
||||
|
||||
# define WITHOUT_HTTP_CONTENT
|
||||
target_compile_definitions(libhv_bindings PRIVATE WITHOUT_HTTP_CONTENT)
|
||||
target_compile_definitions(hv_static PRIVATE WITHOUT_HTTP_CONTENT)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../include
|
||||
${CMAKE_CURRENT_LIST_DIR}/include
|
||||
${CMAKE_CURRENT_LIST_DIR}/libhv
|
||||
${CMAKE_CURRENT_LIST_DIR}/libhv/base
|
||||
${CMAKE_CURRENT_LIST_DIR}/libhv/evpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/libhv/event
|
||||
${CMAKE_CURRENT_LIST_DIR}/libhv/http
|
||||
${CMAKE_CURRENT_LIST_DIR}/libhv/ssl
|
||||
${CMAKE_CURRENT_LIST_DIR}/libhv/cpputil
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/include
|
||||
)
|
||||
@ -1,15 +0,0 @@
|
||||
-xc++
|
||||
-std=c++14
|
||||
|
||||
-I../../include
|
||||
|
||||
-Iinclude/
|
||||
-Ilibhv/
|
||||
-Ilibhv/base/
|
||||
-Ilibhv/evpp/
|
||||
-Ilibhv/event/
|
||||
-Ilibhv/http/
|
||||
-Ilibhv/ssl/
|
||||
-Ilibhv/cpputil/
|
||||
|
||||
-DWITHOUT_HTTP_CONTENT
|
||||
@ -1,56 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "pocketpy.h"
|
||||
#include "http/HttpMessage.h"
|
||||
#include "base/hplatform.h"
|
||||
|
||||
#include "pocketpy/common/name.h"
|
||||
|
||||
extern "C" void pk__add_module_libhv();
|
||||
|
||||
void libhv_HttpRequest_create(py_OutRef out, HttpRequestPtr ptr);
|
||||
|
||||
py_Type libhv_register_HttpRequest(py_GlobalRef mod);
|
||||
py_Type libhv_register_HttpClient(py_GlobalRef mod);
|
||||
py_Type libhv_register_HttpServer(py_GlobalRef mod);
|
||||
py_Type libhv_register_WebSocketClient(py_GlobalRef mod);
|
||||
|
||||
#include <deque>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
template <typename T>
|
||||
class libhv_MQ {
|
||||
private:
|
||||
std::atomic<bool> lock;
|
||||
std::deque<T> queue;
|
||||
|
||||
public:
|
||||
void push(T msg) {
|
||||
while(lock.exchange(true)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
queue.push_back(msg);
|
||||
lock.store(false);
|
||||
}
|
||||
|
||||
bool pop(T* msg) {
|
||||
while(lock.exchange(true)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
if(queue.empty()) {
|
||||
lock.store(false);
|
||||
return false;
|
||||
}
|
||||
*msg = queue.front();
|
||||
queue.pop_front();
|
||||
lock.store(false);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
enum class WsMessageType {
|
||||
onopen,
|
||||
onclose,
|
||||
onmessage,
|
||||
};
|
||||
@ -1 +0,0 @@
|
||||
Subproject commit fded2ba287199d3c20c619e06ddc571e2972ed92
|
||||
@ -1,318 +0,0 @@
|
||||
#include "HttpMessage.h"
|
||||
#include "libhv_bindings.hpp"
|
||||
#include "base/herr.h"
|
||||
#include "http/client/HttpClient.h"
|
||||
|
||||
struct libhv_HttpResponse {
|
||||
HttpRequestPtr request;
|
||||
HttpResponsePtr response;
|
||||
bool ok;
|
||||
|
||||
bool is_valid() { return ok && response != NULL; }
|
||||
|
||||
libhv_HttpResponse(HttpRequestPtr request) : request(request), response(NULL), ok(false) {}
|
||||
};
|
||||
|
||||
static bool libhv_HttpResponse_status_code(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
if(!resp->is_valid()) return RuntimeError("HttpResponse: no response");
|
||||
py_newint(py_retval(), resp->response->status_code);
|
||||
return true;
|
||||
};
|
||||
|
||||
static bool libhv_HttpResponse_headers(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
if(!resp->is_valid()) return RuntimeError("HttpResponse: no response");
|
||||
py_Ref headers = py_getslot(argv, 0);
|
||||
if(py_isnil(headers)) {
|
||||
py_newdict(headers);
|
||||
py_Ref _0 = py_pushtmp();
|
||||
py_Ref _1 = py_pushtmp();
|
||||
for(auto& kv: resp->response->headers) {
|
||||
py_newstr(_0, kv.first.c_str());
|
||||
py_newstr(_1, kv.second.c_str());
|
||||
py_dict_setitem(headers, _0, _1);
|
||||
}
|
||||
py_shrink(2);
|
||||
}
|
||||
py_assign(py_retval(), headers);
|
||||
return true;
|
||||
};
|
||||
|
||||
static bool libhv_HttpResponse_text(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
if(!resp->is_valid()) return RuntimeError("HttpResponse: no response");
|
||||
py_Ref text = py_getslot(argv, 1);
|
||||
if(py_isnil(text)) {
|
||||
c11_sv sv;
|
||||
sv.data = resp->response->body.c_str();
|
||||
sv.size = resp->response->body.size();
|
||||
py_newstrv(text, sv);
|
||||
}
|
||||
py_assign(py_retval(), text);
|
||||
return true;
|
||||
};
|
||||
|
||||
static bool libhv_HttpResponse_content(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
if(!resp->is_valid()) return RuntimeError("HttpResponse: no response");
|
||||
py_Ref content = py_getslot(argv, 2);
|
||||
if(py_isnil(content)) {
|
||||
int size = resp->response->body.size();
|
||||
unsigned char* buf = py_newbytes(content, size);
|
||||
memcpy(buf, resp->response->body.data(), size);
|
||||
}
|
||||
py_assign(py_retval(), content);
|
||||
return true;
|
||||
};
|
||||
|
||||
static bool libhv_HttpResponse_json(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
if(!resp->is_valid()) return RuntimeError("HttpResponse: no response");
|
||||
const char* source = resp->response->body.c_str(); // json string is null-terminated
|
||||
return py_json_loads(source);
|
||||
};
|
||||
|
||||
static bool libhv_HttpResponse_completed(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
py_newbool(py_retval(), resp->is_valid());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpResponse__new__(int argc, py_Ref argv) {
|
||||
return py_exception(tp_NotImplementedError, "");
|
||||
}
|
||||
|
||||
static bool libhv_HttpResponse__iter__(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
py_assign(py_retval(), argv);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpResponse__next__(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
if(!resp->is_valid()) {
|
||||
py_newnone(py_retval());
|
||||
return true;
|
||||
} else {
|
||||
if(!py_tpcall(tp_StopIteration, 1, argv)) return false;
|
||||
return py_raise(py_retval());
|
||||
}
|
||||
}
|
||||
|
||||
static bool libhv_HttpResponse__repr__(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
if(!resp->is_valid()) {
|
||||
py_newstr(py_retval(), "<HttpResponse: no response>");
|
||||
} else {
|
||||
py_newfstr(py_retval(), "<HttpResponse: %d>", (int)resp->response->status_code);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpResponse_cancel(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpResponse* resp = (libhv_HttpResponse*)py_touserdata(argv);
|
||||
resp->request->Cancel();
|
||||
py_newnone(py_retval());
|
||||
return true;
|
||||
}
|
||||
|
||||
static py_Type libhv_register_HttpResponse(py_GlobalRef mod) {
|
||||
py_Type type = py_newtype("HttpResponse", tp_object, mod, [](void* ud) {
|
||||
((libhv_HttpResponse*)ud)->~libhv_HttpResponse();
|
||||
});
|
||||
|
||||
py_bindproperty(type, "status_code", libhv_HttpResponse_status_code, NULL);
|
||||
py_bindproperty(type, "headers", libhv_HttpResponse_headers, NULL);
|
||||
py_bindproperty(type, "text", libhv_HttpResponse_text, NULL);
|
||||
py_bindproperty(type, "content", libhv_HttpResponse_content, NULL);
|
||||
py_bindmethod(type, "json", libhv_HttpResponse_json);
|
||||
|
||||
py_bindmagic(type, __new__, libhv_HttpResponse__new__);
|
||||
py_bindmagic(type, __iter__, libhv_HttpResponse__iter__);
|
||||
py_bindmagic(type, __next__, libhv_HttpResponse__next__);
|
||||
py_bindmagic(type, __repr__, libhv_HttpResponse__repr__);
|
||||
// completed
|
||||
py_bindproperty(type, "completed", libhv_HttpResponse_completed, NULL);
|
||||
// cancel
|
||||
py_bindmethod(type, "cancel", libhv_HttpResponse_cancel);
|
||||
return type;
|
||||
}
|
||||
|
||||
static bool libhv_HttpClient__send_request(py_Ref arg_self,
|
||||
enum http_method method,
|
||||
py_Ref arg_url,
|
||||
py_Ref arg_params,
|
||||
py_Ref arg_headers,
|
||||
py_Ref arg_data,
|
||||
py_Ref arg_json,
|
||||
py_Ref arg_timeout) {
|
||||
hv::HttpClient* cli = (hv::HttpClient*)py_touserdata(arg_self);
|
||||
if(!py_checkstr(arg_url)) return false;
|
||||
const char* url = py_tostr(arg_url);
|
||||
if(!py_checkint(arg_timeout)) return false;
|
||||
int timeout = py_toint(arg_timeout);
|
||||
|
||||
auto req = std::make_shared<HttpRequest>();
|
||||
req->method = method;
|
||||
req->url = url;
|
||||
if(!py_isnone(arg_params)) {
|
||||
if(!py_checktype(arg_params, tp_dict)) return false;
|
||||
|
||||
bool ok = py_dict_apply(
|
||||
arg_params,
|
||||
[](py_Ref key, py_Ref value, void* ctx) {
|
||||
HttpRequest* p_req = (HttpRequest*)ctx;
|
||||
if(!py_checkstr(key)) return false;
|
||||
if(!py_str(value)) return false; // key: str(value)
|
||||
p_req->SetParam(py_tostr(key), py_tostr(py_retval()));
|
||||
return true;
|
||||
},
|
||||
req.get());
|
||||
if(!ok) return false;
|
||||
}
|
||||
|
||||
req->headers["Connection"] = "keep-alive";
|
||||
|
||||
if(!py_isnone(arg_headers)) {
|
||||
if(!py_checktype(arg_headers, tp_dict)) return false;
|
||||
|
||||
bool ok = py_dict_apply(
|
||||
arg_headers,
|
||||
[](py_Ref key, py_Ref value, void* ctx) {
|
||||
HttpRequest* p_req = (HttpRequest*)ctx;
|
||||
if(!py_checkstr(key)) return false;
|
||||
if(!py_str(value)) return false; // key: str(value)
|
||||
p_req->headers[py_tostr(key)] = py_tostr(py_retval());
|
||||
return true;
|
||||
},
|
||||
req.get());
|
||||
if(!ok) return false;
|
||||
}
|
||||
|
||||
if(!py_isnone(arg_data)) {
|
||||
// data must be str or bytes
|
||||
if(py_istype(arg_data, tp_str)) {
|
||||
req->body = py_tostr(arg_data);
|
||||
} else if(py_istype(arg_data, tp_bytes)) {
|
||||
int size;
|
||||
unsigned char* buf = py_tobytes(arg_data, &size);
|
||||
req->body.assign((const char*)buf, size);
|
||||
} else {
|
||||
return TypeError("HttpClient: data must be str or bytes");
|
||||
}
|
||||
}
|
||||
|
||||
if(!py_isnone(arg_json)) {
|
||||
if(!py_isnone(arg_data)) {
|
||||
return ValueError("HttpClient: data and json cannot be set at the same time");
|
||||
}
|
||||
|
||||
if(!py_json_dumps(arg_json, 0)) return false;
|
||||
req->body = py_tostr(py_retval());
|
||||
req->headers["Content-Type"] = "application/json";
|
||||
}
|
||||
|
||||
req->timeout = timeout;
|
||||
|
||||
libhv_HttpResponse* retval =
|
||||
(libhv_HttpResponse*)py_newobject(py_retval(),
|
||||
py_gettype("libhv", py_name("HttpResponse")),
|
||||
3, // headers, text, content
|
||||
sizeof(libhv_HttpResponse));
|
||||
// placement new
|
||||
new (retval) libhv_HttpResponse(req);
|
||||
|
||||
int code = cli->sendAsync(req, [retval](const HttpResponsePtr& resp) {
|
||||
if(resp == NULL) {
|
||||
retval->ok = false;
|
||||
retval->response = NULL;
|
||||
} else {
|
||||
retval->ok = true;
|
||||
retval->response = resp;
|
||||
}
|
||||
});
|
||||
if(code != 0) {
|
||||
const char* msg = hv_strerror(code);
|
||||
return RuntimeError("HttpClient: %s (%d)", msg, code);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
py_Type libhv_register_HttpClient(py_GlobalRef mod) {
|
||||
py_Type type = py_newtype("HttpClient", tp_object, mod, [](void* ud) {
|
||||
((hv::HttpClient*)ud)->~HttpClient();
|
||||
});
|
||||
py_GlobalRef type_object = py_tpobject(type);
|
||||
libhv_register_HttpResponse(mod);
|
||||
|
||||
py_bindmagic(type, __new__, [](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
hv::HttpClient* ud =
|
||||
(hv::HttpClient*)py_newobject(py_retval(), py_totype(argv), 0, sizeof(hv::HttpClient));
|
||||
new (ud) hv::HttpClient();
|
||||
return true;
|
||||
});
|
||||
|
||||
py_bind(type_object,
|
||||
"get(self, url: str, params=None, headers=None, timeout=10)",
|
||||
[](int argc, py_Ref argv) {
|
||||
return libhv_HttpClient__send_request(py_arg(0), // self
|
||||
HTTP_GET, // method
|
||||
py_arg(1), // url
|
||||
py_arg(2), // params
|
||||
py_arg(3), // headers
|
||||
py_None(), // data
|
||||
py_None(), // json
|
||||
py_arg(4)); // timeout
|
||||
});
|
||||
|
||||
py_bind(type_object,
|
||||
"post(self, url: str, params=None, headers=None, data=None, json=None, timeout=10)",
|
||||
[](int argc, py_Ref argv) {
|
||||
return libhv_HttpClient__send_request(py_arg(0), // self
|
||||
HTTP_POST, // method
|
||||
py_arg(1), // url
|
||||
py_arg(2), // params
|
||||
py_arg(3), // headers
|
||||
py_arg(4), // data
|
||||
py_arg(5), // json
|
||||
py_arg(6)); // timeout
|
||||
});
|
||||
|
||||
py_bind(type_object,
|
||||
"put(self, url: str, params=None, headers=None, data=None, json=None, timeout=10)",
|
||||
[](int argc, py_Ref argv) {
|
||||
return libhv_HttpClient__send_request(py_arg(0), // self
|
||||
HTTP_PUT, // method
|
||||
py_arg(1), // url
|
||||
py_arg(2), // params
|
||||
py_arg(3), // headers
|
||||
py_arg(4), // data
|
||||
py_arg(5), // json
|
||||
py_arg(6)); // timeout
|
||||
});
|
||||
|
||||
py_bind(type_object,
|
||||
"delete(self, url: str, params=None, headers=None, timeout=10)",
|
||||
[](int argc, py_Ref argv) {
|
||||
return libhv_HttpClient__send_request(py_arg(0), // self
|
||||
HTTP_DELETE, // method
|
||||
py_arg(1), // url
|
||||
py_arg(2), // params
|
||||
py_arg(3), // headers
|
||||
py_None(), // data
|
||||
py_None(), // json
|
||||
py_arg(4)); // timeout
|
||||
});
|
||||
return type;
|
||||
}
|
||||
@ -1,114 +0,0 @@
|
||||
#include "libhv_bindings.hpp"
|
||||
#include "HttpMessage.h"
|
||||
|
||||
struct libhv_HttpRequest {
|
||||
HttpRequestPtr ptr;
|
||||
|
||||
libhv_HttpRequest(HttpRequestPtr ptr) : ptr(ptr) {}
|
||||
};
|
||||
|
||||
void libhv_HttpRequest_create(py_OutRef out, HttpRequestPtr ptr) {
|
||||
py_Type type = py_gettype("libhv", py_name("HttpRequest"));
|
||||
libhv_HttpRequest* self =
|
||||
(libhv_HttpRequest*)py_newobject(out, type, 2, sizeof(libhv_HttpRequest));
|
||||
new (self) libhv_HttpRequest(ptr);
|
||||
}
|
||||
|
||||
py_Type libhv_register_HttpRequest(py_GlobalRef mod) {
|
||||
py_Type type = py_newtype("HttpRequest", tp_object, mod, [](void* ud) {
|
||||
((libhv_HttpRequest*)ud)->~libhv_HttpRequest();
|
||||
});
|
||||
|
||||
py_bindmagic(type, __new__, [](int argc, py_Ref argv) {
|
||||
return py_exception(tp_NotImplementedError, "");
|
||||
});
|
||||
|
||||
py_bindproperty(
|
||||
type,
|
||||
"method",
|
||||
[](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpRequest* req = (libhv_HttpRequest*)py_touserdata(argv);
|
||||
py_newstr(py_retval(), req->ptr->Method());
|
||||
return true;
|
||||
},
|
||||
NULL);
|
||||
|
||||
py_bindproperty(
|
||||
type,
|
||||
"url",
|
||||
[](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpRequest* req = (libhv_HttpRequest*)py_touserdata(argv);
|
||||
py_newstr(py_retval(), req->ptr->Url().c_str());
|
||||
return true;
|
||||
},
|
||||
NULL);
|
||||
|
||||
py_bindproperty(
|
||||
type,
|
||||
"path",
|
||||
[](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpRequest* req = (libhv_HttpRequest*)py_touserdata(argv);
|
||||
py_newstr(py_retval(), req->ptr->Path().c_str());
|
||||
return true;
|
||||
},
|
||||
NULL);
|
||||
|
||||
// headers (cache in slots[0])
|
||||
py_bindproperty(
|
||||
type,
|
||||
"headers",
|
||||
[](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpRequest* req = (libhv_HttpRequest*)py_touserdata(argv);
|
||||
py_Ref headers = py_getslot(argv, 0);
|
||||
if(py_isnil(headers)) {
|
||||
py_newdict(headers);
|
||||
py_Ref _0 = py_pushtmp();
|
||||
py_Ref _1 = py_pushtmp();
|
||||
for(auto& kv: req->ptr->headers) {
|
||||
py_newstr(_0, kv.first.c_str()); // TODO: tolower
|
||||
py_newstr(_1, kv.second.c_str());
|
||||
py_dict_setitem(headers, _0, _1);
|
||||
}
|
||||
py_shrink(2);
|
||||
}
|
||||
py_assign(py_retval(), headers);
|
||||
return true;
|
||||
},
|
||||
NULL);
|
||||
|
||||
// data (cache in slots[1])
|
||||
py_bindproperty(
|
||||
type,
|
||||
"data",
|
||||
[](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpRequest* req = (libhv_HttpRequest*)py_touserdata(argv);
|
||||
py_Ref data = py_getslot(argv, 1);
|
||||
|
||||
if(py_isnil(data)) {
|
||||
auto content_type = req->ptr->ContentType();
|
||||
bool is_text_data = content_type == TEXT_PLAIN ||
|
||||
content_type == APPLICATION_JSON ||
|
||||
content_type == APPLICATION_XML || content_type == TEXT_HTML ||
|
||||
content_type == CONTENT_TYPE_NONE;
|
||||
if(is_text_data) {
|
||||
c11_sv sv;
|
||||
sv.data = req->ptr->body.data();
|
||||
sv.size = req->ptr->body.size();
|
||||
py_newstrv(data, sv);
|
||||
} else {
|
||||
unsigned char* buf = py_newbytes(data, req->ptr->body.size());
|
||||
memcpy(buf, req->ptr->body.data(), req->ptr->body.size());
|
||||
}
|
||||
}
|
||||
py_assign(py_retval(), data);
|
||||
return true;
|
||||
},
|
||||
NULL);
|
||||
|
||||
return type;
|
||||
}
|
||||
@ -1,260 +0,0 @@
|
||||
#include "HttpMessage.h"
|
||||
#include "WebSocketChannel.h"
|
||||
#include "libhv_bindings.hpp"
|
||||
#include "http/server/WebSocketServer.h"
|
||||
#include "pocketpy.h"
|
||||
|
||||
struct libhv_HttpServer {
|
||||
hv::HttpService http_service;
|
||||
hv::WebSocketService ws_service;
|
||||
hv::WebSocketServer server;
|
||||
|
||||
libhv_MQ<std::pair<HttpContextPtr, std::atomic<int>>*> mq;
|
||||
|
||||
struct WsMessage {
|
||||
WsMessageType type;
|
||||
hv::WebSocketChannel* channel;
|
||||
HttpRequestPtr request;
|
||||
std::string body;
|
||||
};
|
||||
|
||||
libhv_MQ<WsMessage> ws_mq;
|
||||
};
|
||||
|
||||
static bool libhv_HttpServer__new__(int argc, py_Ref argv) {
|
||||
libhv_HttpServer* self =
|
||||
(libhv_HttpServer*)py_newobject(py_retval(), py_totype(argv), 0, sizeof(libhv_HttpServer));
|
||||
new (self) libhv_HttpServer();
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer__init__(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(3);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
PY_CHECK_ARG_TYPE(1, tp_str);
|
||||
PY_CHECK_ARG_TYPE(2, tp_int);
|
||||
const char* host = py_tostr(py_arg(1));
|
||||
int port = py_toint(py_arg(2));
|
||||
self->server.setHost(host);
|
||||
self->server.setPort(port);
|
||||
|
||||
// http
|
||||
self->http_service.AllowCORS();
|
||||
http_ctx_handler internal_handler = [self](const HttpContextPtr& ctx) {
|
||||
std::pair<HttpContextPtr, std::atomic<int>> msg(ctx, 0);
|
||||
self->mq.push(&msg);
|
||||
int code;
|
||||
do {
|
||||
code = msg.second.load();
|
||||
} while(code == 0);
|
||||
return code;
|
||||
};
|
||||
self->http_service.Any("*", internal_handler);
|
||||
self->server.registerHttpService(&self->http_service);
|
||||
|
||||
// websocket
|
||||
self->ws_service.onopen = [self](const WebSocketChannelPtr& channel,
|
||||
const HttpRequestPtr& req) {
|
||||
self->ws_mq.push({WsMessageType::onopen, channel.get(), req, ""});
|
||||
};
|
||||
self->ws_service.onmessage = [self](const WebSocketChannelPtr& channel,
|
||||
const std::string& msg) {
|
||||
self->ws_mq.push({WsMessageType::onmessage, channel.get(), nullptr, msg});
|
||||
};
|
||||
self->ws_service.onclose = [self](const WebSocketChannelPtr& channel) {
|
||||
self->ws_mq.push({WsMessageType::onclose, channel.get(), nullptr, ""});
|
||||
};
|
||||
self->server.registerWebSocketService(&self->ws_service);
|
||||
|
||||
py_newnone(py_retval());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer_dispatch(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(2);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
py_Ref callable = py_arg(1);
|
||||
if(!py_callable(callable)) return TypeError("dispatcher must be callable");
|
||||
|
||||
std::pair<HttpContextPtr, std::atomic<int>>* mq_msg;
|
||||
if(!self->mq.pop(&mq_msg)) {
|
||||
py_newbool(py_retval(), false);
|
||||
return true;
|
||||
} else {
|
||||
HttpContextPtr ctx = mq_msg->first;
|
||||
libhv_HttpRequest_create(py_retval(), ctx->request);
|
||||
// call dispatcher
|
||||
if(!py_call(callable, 1, py_retval())) return false;
|
||||
|
||||
py_Ref object;
|
||||
int status_code = 200;
|
||||
if(py_istuple(py_retval())) {
|
||||
int length = py_tuple_len(py_retval());
|
||||
if(length == 2 || length == 3) {
|
||||
// "Hello, world!", 200
|
||||
object = py_tuple_getitem(py_retval(), 0);
|
||||
py_ItemRef status_code_object = py_tuple_getitem(py_retval(), 1);
|
||||
if(!py_checkint(status_code_object)) return false;
|
||||
status_code = py_toint(status_code_object);
|
||||
|
||||
if(length == 3) {
|
||||
// "Hello, world!", 200, {"Content-Type": "text/plain"}
|
||||
py_ItemRef headers_object = py_tuple_getitem(py_retval(), 2);
|
||||
if(!py_checktype(headers_object, tp_dict)) return false;
|
||||
bool ok = py_dict_apply(
|
||||
headers_object,
|
||||
[](py_Ref key, py_Ref value, void* ctx_) {
|
||||
if(!py_checkstr(key) || !py_checkstr(value)) return false;
|
||||
((hv::HttpContext*)ctx_)
|
||||
->response->SetHeader(py_tostr(key), py_tostr(value));
|
||||
return true;
|
||||
},
|
||||
ctx.get());
|
||||
if(!ok) return false;
|
||||
}
|
||||
} else {
|
||||
return TypeError("dispatcher return tuple must have 2 or 3 elements");
|
||||
}
|
||||
} else {
|
||||
// "Hello, world!"
|
||||
object = py_retval();
|
||||
}
|
||||
|
||||
switch(py_typeof(object)) {
|
||||
case tp_bytes: {
|
||||
int size;
|
||||
unsigned char* buf = py_tobytes(object, &size);
|
||||
ctx->response->Data(buf, size, false);
|
||||
break;
|
||||
}
|
||||
case tp_str: {
|
||||
c11_sv sv = py_tosv(object);
|
||||
ctx->response->String(std::string(sv.data, sv.size));
|
||||
break;
|
||||
}
|
||||
case tp_NoneType: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if(!py_json_dumps(object, 0)) return false;
|
||||
c11_sv sv = py_tosv(py_retval());
|
||||
ctx->response->String(std::string(sv.data, sv.size));
|
||||
ctx->response->SetContentType(APPLICATION_JSON);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mq_msg->second.store(status_code);
|
||||
}
|
||||
py_newbool(py_retval(), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer_start(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
int code = self->server.start();
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer_stop(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
int code = self->server.stop();
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer_ws_set_ping_interval(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(2);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
PY_CHECK_ARG_TYPE(1, tp_int);
|
||||
int interval = py_toint(py_arg(1));
|
||||
self->ws_service.setPingInterval(interval);
|
||||
py_newnone(py_retval());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer_ws_close(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(2);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
PY_CHECK_ARG_TYPE(1, tp_int);
|
||||
py_i64 channel = py_toint(py_arg(1));
|
||||
int code = reinterpret_cast<hv::WebSocketChannel*>(channel)->close();
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer_ws_send(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(3);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
PY_CHECK_ARG_TYPE(1, tp_int);
|
||||
PY_CHECK_ARG_TYPE(2, tp_str);
|
||||
py_i64 channel = py_toint(py_arg(1));
|
||||
const char* msg = py_tostr(py_arg(2));
|
||||
|
||||
hv::WebSocketChannel* p_channel = reinterpret_cast<hv::WebSocketChannel*>(channel);
|
||||
int code = p_channel->send(msg);
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool libhv_HttpServer_ws_recv(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
|
||||
libhv_HttpServer::WsMessage msg;
|
||||
if(!self->ws_mq.pop(&msg)) {
|
||||
py_newnone(py_retval());
|
||||
return true;
|
||||
}
|
||||
py_Ref data = py_newtuple(py_retval(), 2);
|
||||
switch(msg.type) {
|
||||
case WsMessageType::onopen: {
|
||||
// "onopen", (channel, request)
|
||||
assert(msg.request != nullptr);
|
||||
py_newstr(py_offset(data, 0), "onopen");
|
||||
py_Ref p = py_newtuple(py_offset(data, 1), 2);
|
||||
py_newint(py_offset(p, 0), (py_i64)msg.channel);
|
||||
libhv_HttpRequest_create(py_offset(p, 1), msg.request);
|
||||
break;
|
||||
}
|
||||
case WsMessageType::onclose: {
|
||||
// "onclose", channel
|
||||
py_newstr(py_offset(data, 0), "onclose");
|
||||
py_newint(py_offset(data, 1), (py_i64)msg.channel);
|
||||
break;
|
||||
}
|
||||
case WsMessageType::onmessage: {
|
||||
// "onmessage", (channel, body)
|
||||
py_newstr(py_offset(data, 0), "onmessage");
|
||||
py_Ref p = py_newtuple(py_offset(data, 1), 2);
|
||||
py_newint(py_offset(p, 0), (py_i64)msg.channel);
|
||||
c11_sv sv;
|
||||
sv.data = msg.body.data();
|
||||
sv.size = msg.body.size();
|
||||
py_newstrv(py_offset(p, 1), sv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
py_Type libhv_register_HttpServer(py_GlobalRef mod) {
|
||||
py_Type type = py_newtype("HttpServer", tp_object, mod, [](void* ud) {
|
||||
libhv_HttpServer* self = (libhv_HttpServer*)ud;
|
||||
self->~libhv_HttpServer();
|
||||
});
|
||||
|
||||
py_bindmagic(type, __new__, libhv_HttpServer__new__);
|
||||
py_bindmagic(type, __init__, libhv_HttpServer__init__);
|
||||
py_bindmethod(type, "start", libhv_HttpServer_start);
|
||||
py_bindmethod(type, "stop", libhv_HttpServer_stop);
|
||||
py_bindmethod(type, "dispatch", libhv_HttpServer_dispatch);
|
||||
|
||||
py_bindmethod(type, "ws_set_ping_interval", libhv_HttpServer_ws_set_ping_interval);
|
||||
py_bindmethod(type, "ws_close", libhv_HttpServer_ws_close);
|
||||
py_bindmethod(type, "ws_send", libhv_HttpServer_ws_send);
|
||||
py_bindmethod(type, "ws_recv", libhv_HttpServer_ws_recv);
|
||||
return type;
|
||||
}
|
||||
@ -1,124 +0,0 @@
|
||||
#include "HttpMessage.h"
|
||||
#include "libhv_bindings.hpp"
|
||||
#include "pocketpy.h"
|
||||
#include "http/client/WebSocketClient.h"
|
||||
|
||||
struct libhv_WebSocketClient {
|
||||
hv::WebSocketClient ws;
|
||||
|
||||
libhv_MQ<std::pair<WsMessageType, std::string>> mq;
|
||||
|
||||
libhv_WebSocketClient() {
|
||||
ws.onopen = [this]() {
|
||||
mq.push({WsMessageType::onopen, ""});
|
||||
};
|
||||
ws.onclose = [this]() {
|
||||
mq.push({WsMessageType::onclose, ""});
|
||||
};
|
||||
ws.onmessage = [this](const std::string& msg) {
|
||||
mq.push({WsMessageType::onmessage, msg});
|
||||
};
|
||||
|
||||
// reconnect: 1,2,4,8,10,10,10...
|
||||
reconn_setting_t reconn;
|
||||
reconn_setting_init(&reconn);
|
||||
reconn.min_delay = 1000;
|
||||
reconn.max_delay = 10000;
|
||||
reconn.delay_policy = 2;
|
||||
ws.setReconnect(&reconn);
|
||||
}
|
||||
};
|
||||
|
||||
py_Type libhv_register_WebSocketClient(py_GlobalRef mod) {
|
||||
py_Type type = py_newtype("WebSocketClient", tp_object, mod, [](void* ud) {
|
||||
libhv_WebSocketClient* self = (libhv_WebSocketClient*)ud;
|
||||
self->~libhv_WebSocketClient();
|
||||
});
|
||||
|
||||
py_bindmagic(type, __new__, [](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_WebSocketClient* self = (libhv_WebSocketClient*)
|
||||
py_newobject(py_retval(), py_totype(argv), 0, sizeof(libhv_WebSocketClient));
|
||||
new (self) libhv_WebSocketClient();
|
||||
return true;
|
||||
});
|
||||
|
||||
py_bindmethod(type, "open", [](int argc, py_Ref argv) {
|
||||
libhv_WebSocketClient* self = (libhv_WebSocketClient*)py_touserdata(argv);
|
||||
PY_CHECK_ARG_TYPE(1, tp_str);
|
||||
const char* url = py_tostr(py_arg(1));
|
||||
http_headers headers = DefaultHeaders;
|
||||
if(argc == 2) {
|
||||
// open(self, url)
|
||||
} else if(argc == 3) {
|
||||
// open(self, url, headers)
|
||||
if(!py_checktype(py_arg(2), tp_dict)) return false;
|
||||
bool ok = py_dict_apply(
|
||||
py_arg(2),
|
||||
[](py_Ref key, py_Ref value, void* ctx) {
|
||||
http_headers* p_headers = (http_headers*)ctx;
|
||||
if(!py_checkstr(key)) return false;
|
||||
if(!py_checkstr(value)) return false;
|
||||
p_headers->operator[] (py_tostr(key)) = py_tostr(value);
|
||||
return true;
|
||||
},
|
||||
&headers);
|
||||
if(!ok) return false;
|
||||
} else {
|
||||
return TypeError("open() takes 2 or 3 arguments");
|
||||
}
|
||||
int code = self->ws.open(url, headers);
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
});
|
||||
|
||||
py_bindmethod(type, "close", [](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_WebSocketClient* self = (libhv_WebSocketClient*)py_touserdata(argv);
|
||||
int code = self->ws.close();
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
});
|
||||
|
||||
py_bindmethod(type, "send", [](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(2);
|
||||
libhv_WebSocketClient* self = (libhv_WebSocketClient*)py_touserdata(argv);
|
||||
PY_CHECK_ARG_TYPE(1, tp_str);
|
||||
const char* msg = py_tostr(py_arg(1));
|
||||
int code = self->ws.send(msg);
|
||||
py_newint(py_retval(), code);
|
||||
return true;
|
||||
});
|
||||
|
||||
py_bindmethod(type, "recv", [](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
libhv_WebSocketClient* self = (libhv_WebSocketClient*)py_touserdata(py_arg(0));
|
||||
|
||||
std::pair<WsMessageType, std::string> mq_msg;
|
||||
if(!self->mq.pop(&mq_msg)) {
|
||||
py_newnone(py_retval());
|
||||
return true;
|
||||
} else {
|
||||
py_Ref p = py_newtuple(py_retval(), 2);
|
||||
switch(mq_msg.first) {
|
||||
case WsMessageType::onopen: {
|
||||
py_newstr(py_offset(p, 0), "onopen");
|
||||
py_newnone(py_offset(p, 1));
|
||||
break;
|
||||
}
|
||||
case WsMessageType::onclose: {
|
||||
py_newstr(py_offset(p, 0), "onclose");
|
||||
py_newnone(py_offset(p, 1));
|
||||
break;
|
||||
}
|
||||
case WsMessageType::onmessage: {
|
||||
py_newstr(py_offset(p, 0), "onmessage");
|
||||
py_newstrv(py_offset(p, 1), {mq_msg.second.data(), (int)mq_msg.second.size()});
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return type;
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
#include "libhv_bindings.hpp"
|
||||
#include "base/herr.h"
|
||||
|
||||
extern "C" void pk__add_module_libhv() {
|
||||
py_GlobalRef mod = py_newmodule("libhv");
|
||||
|
||||
libhv_register_HttpRequest(mod);
|
||||
libhv_register_HttpClient(mod);
|
||||
libhv_register_HttpServer(mod);
|
||||
libhv_register_WebSocketClient(mod);
|
||||
|
||||
py_bindfunc(mod, "strerror", [](int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
PY_CHECK_ARG_TYPE(0, tp_int);
|
||||
int code = py_toint(py_arg(0));
|
||||
const char* msg = hv_strerror(code);
|
||||
py_newstr(py_retval(), msg);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@ -110,11 +110,6 @@ if(PK_BUILD_MODULE_LZ4)
|
||||
add_definitions(-DPK_BUILD_MODULE_LZ4)
|
||||
endif()
|
||||
|
||||
if(PK_BUILD_MODULE_LIBHV)
|
||||
add_subdirectory(3rd/libhv)
|
||||
add_definitions(-DPK_BUILD_MODULE_LIBHV)
|
||||
endif()
|
||||
|
||||
if(PK_BUILD_MODULE_CUTE_PNG)
|
||||
add_subdirectory(3rd/cute_png)
|
||||
add_definitions(-DPK_BUILD_MODULE_CUTE_PNG)
|
||||
@ -181,10 +176,6 @@ if(PK_BUILD_MODULE_LZ4)
|
||||
target_link_libraries(${PROJECT_NAME} lz4)
|
||||
endif()
|
||||
|
||||
if(PK_BUILD_MODULE_LIBHV)
|
||||
target_link_libraries(${PROJECT_NAME} libhv_bindings)
|
||||
endif()
|
||||
|
||||
if(PK_BUILD_MODULE_CUTE_PNG)
|
||||
target_link_libraries(${PROJECT_NAME} cute_png)
|
||||
endif()
|
||||
|
||||
@ -15,7 +15,6 @@ option(PK_ENABLE_MIMALLOC "" OFF)
|
||||
|
||||
# modules
|
||||
option(PK_BUILD_MODULE_LZ4 "" OFF)
|
||||
option(PK_BUILD_MODULE_LIBHV "" OFF)
|
||||
option(PK_BUILD_MODULE_CUTE_PNG "" OFF)
|
||||
|
||||
# PK_IS_MAIN determines whether the project is being used from root
|
||||
|
||||
@ -15,8 +15,9 @@ cmake \
|
||||
../../.. \
|
||||
-DPK_BUILD_SHARED_LIB=ON \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DPK_ENABLE_OS=OFF \
|
||||
-DPK_ENABLE_DETERMINISM=ON \
|
||||
-DPK_BUILD_MODULE_LZ4=ON \
|
||||
-DPK_BUILD_MODULE_LIBHV=ON \
|
||||
-DPK_BUILD_CUTE_PNG=ON
|
||||
-DPK_BUILD_MODULE_CUTE_PNG=ON
|
||||
|
||||
cmake --build . --config Release
|
||||
21
build_darwin_libs.sh
Normal file
21
build_darwin_libs.sh
Normal file
@ -0,0 +1,21 @@
|
||||
set -e
|
||||
|
||||
python amalgamate.py
|
||||
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
FLAGS="-DPK_BUILD_STATIC_LIB=ON \
|
||||
-DPK_ENABLE_OS=OFF \
|
||||
-DPK_ENABLE_DETERMINISM=ON \
|
||||
-DPK_BUILD_MODULE_LZ4=ON \
|
||||
-DPK_BUILD_MODULE_CUTE_PNG=ON \
|
||||
"
|
||||
|
||||
cmake -G Xcode $FLAGS ..
|
||||
cmake --build . --config Release
|
||||
|
||||
cd ../
|
||||
|
||||
python scripts/merge_built_libraries.py build
|
||||
26
build_ios.sh
26
build_ios.sh
@ -1,26 +0,0 @@
|
||||
set -e
|
||||
|
||||
python amalgamate.py
|
||||
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
FLAGS="-DCMAKE_TOOLCHAIN_FILE=3rd/ios.toolchain.cmake \
|
||||
-DDEPLOYMENT_TARGET=13.0 \
|
||||
-DPK_BUILD_STATIC_LIB=ON"
|
||||
|
||||
cmake -B os64 -G Xcode $FLAGS -DPLATFORM=OS64 ..
|
||||
cmake --build os64 --config Release
|
||||
|
||||
cmake -B simulatorarm64 -G Xcode $FLAGS -DPLATFORM=SIMULATORARM64 ..
|
||||
cmake --build simulatorarm64 --config Release
|
||||
|
||||
HEADERS="../amalgamated/pocketpy.h"
|
||||
|
||||
xcodebuild -create-xcframework \
|
||||
-library os64/Release-iphoneos/libpocketpy.a -headers $HEADERS \
|
||||
-library simulatorarm64/Release-iphonesimulator/libpocketpy.a -headers $HEADERS \
|
||||
-output pocketpy.xcframework
|
||||
|
||||
|
||||
34
build_ios_libs.sh
Normal file
34
build_ios_libs.sh
Normal file
@ -0,0 +1,34 @@
|
||||
set -e
|
||||
|
||||
python amalgamate.py
|
||||
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
FLAGS="-DCMAKE_TOOLCHAIN_FILE=3rd/ios.toolchain.cmake \
|
||||
-DDEPLOYMENT_TARGET=13.0 \
|
||||
-DPK_BUILD_STATIC_LIB=ON \
|
||||
-DPK_ENABLE_OS=OFF \
|
||||
-DPK_ENABLE_DETERMINISM=ON \
|
||||
-DPK_BUILD_MODULE_LZ4=ON \
|
||||
-DPK_BUILD_MODULE_CUTE_PNG=ON \
|
||||
"
|
||||
|
||||
cmake -B os64 -G Xcode $FLAGS -DPLATFORM=OS64 ..
|
||||
cmake --build os64 --config Release
|
||||
|
||||
cmake -B simulatorarm64 -G Xcode $FLAGS -DPLATFORM=SIMULATORARM64 ..
|
||||
cmake --build simulatorarm64 --config Release
|
||||
|
||||
cd ../
|
||||
|
||||
HEADERS="amalgamated/pocketpy.h"
|
||||
|
||||
python scripts/merge_built_libraries.py build/os64
|
||||
python scripts/merge_built_libraries.py build/simulatorarm64
|
||||
|
||||
xcodebuild -create-xcframework \
|
||||
-library build/os64/libpocketpy.a -headers $HEADERS \
|
||||
-library build/simulatorarm64/libpocketpy.a -headers $HEADERS \
|
||||
-output build/pocketpy.xcframework
|
||||
@ -4,5 +4,4 @@
|
||||
-std=c11
|
||||
-Iinclude/
|
||||
-I3rd/lz4/
|
||||
-I3rd/libhv/include/
|
||||
-I3rd/cute_headers/include/
|
||||
@ -1,24 +0,0 @@
|
||||
---
|
||||
icon: package
|
||||
label: libhv
|
||||
---
|
||||
|
||||
!!!
|
||||
This module is optional. Set option `PK_BUILD_MODULE_LIBHV` to `ON` in your `CMakeLists.txt` to enable it.
|
||||
!!!
|
||||
|
||||
`libhv` is a git submodule located at `3rd/libhv/libhv`. If you cannot find it, please run the following command to initialize the submodule:
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
Simple bindings for [libhv](https://github.com/ithewei/libhv), which provides cross platform implementation of the following:
|
||||
+ HTTP server
|
||||
+ HTTP client
|
||||
+ WebSocket server
|
||||
+ WebSocket client
|
||||
|
||||
#### Source code
|
||||
|
||||
:::code source="../../include/typings/libhv.pyi" :::
|
||||
@ -27,12 +27,6 @@ void pk__add_module_conio();
|
||||
void pk__add_module_lz4();
|
||||
void pk__add_module_pkpy();
|
||||
|
||||
#ifdef PK_BUILD_MODULE_LIBHV
|
||||
void pk__add_module_libhv();
|
||||
#else
|
||||
#define pk__add_module_libhv()
|
||||
#endif
|
||||
|
||||
#ifdef PK_BUILD_MODULE_CUTE_PNG
|
||||
void pk__add_module_cute_png();
|
||||
#else
|
||||
|
||||
4
plugins/flutter/pocketpy/.gitignore
vendored
4
plugins/flutter/pocketpy/.gitignore
vendored
@ -27,3 +27,7 @@ migrate_working_dir/
|
||||
**/doc/api/
|
||||
.dart_tool/
|
||||
build/
|
||||
|
||||
ios/pocketpy/
|
||||
macos/pocketpy/
|
||||
|
||||
|
||||
@ -2,4 +2,12 @@
|
||||
|
||||
Official FFI bindings for pocketpy.
|
||||
|
||||
https://github.com/pocketpy/pocketpy
|
||||
https://github.com/pocketpy/pocketpy
|
||||
|
||||
## Special Notes
|
||||
|
||||
For MacOS and iOS, when you install this plugin,
|
||||
there is a script that will clone the pocketpy repository and build
|
||||
necessary binaries. This could take several minutes.
|
||||
|
||||
This plugin only works for iOS real device, not simulator.
|
||||
|
||||
22
plugins/flutter/pocketpy/example/ios/Podfile.lock
Normal file
22
plugins/flutter/pocketpy/example/ios/Podfile.lock
Normal file
@ -0,0 +1,22 @@
|
||||
PODS:
|
||||
- Flutter (1.0.0)
|
||||
- pocketpy (2.0.0):
|
||||
- Flutter
|
||||
|
||||
DEPENDENCIES:
|
||||
- Flutter (from `Flutter`)
|
||||
- pocketpy (from `.symlinks/plugins/pocketpy/ios`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Flutter:
|
||||
:path: Flutter
|
||||
pocketpy:
|
||||
:path: ".symlinks/plugins/pocketpy/ios"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
||||
pocketpy: 6bad04d7bd05a4408d335d6ad6813d31d1496124
|
||||
|
||||
PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
|
||||
|
||||
COCOAPODS: 1.15.2
|
||||
@ -10,10 +10,12 @@
|
||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
|
||||
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; };
|
||||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
||||
4DCA872872B6E0CAD3D6D62C /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EFF9DEBFC8DA1F2397A41670 /* Pods_RunnerTests.framework */; };
|
||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
||||
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
||||
F8239560C87F63DECE953F24 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 369C3E2CA8E4810CABA363B5 /* Pods_Runner.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -42,9 +44,13 @@
|
||||
/* Begin PBXFileReference section */
|
||||
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
|
||||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
|
||||
24CCA05467623A36B01E627A /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
|
||||
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
|
||||
331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
369C3E2CA8E4810CABA363B5 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
||||
45627CB2AA093EADB1068927 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
496E5DE1B7B0D8EBAEAB5451 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||
@ -55,19 +61,41 @@
|
||||
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
AFC5F00ED7B1F8A52E9F6DC0 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
|
||||
B29BC380D6DE4DE1C602C120 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = "<group>"; };
|
||||
CE1BE763A99EA4D0B227AFE7 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
|
||||
EFF9DEBFC8DA1F2397A41670 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
8D2F751458AC564B8B8186B4 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4DCA872872B6E0CAD3D6D62C /* Pods_RunnerTests.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
97C146EB1CF9000F007C117D /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F8239560C87F63DECE953F24 /* Pods_Runner.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
0F6BCADAD92A2AAE8C04713B /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
369C3E2CA8E4810CABA363B5 /* Pods_Runner.framework */,
|
||||
EFF9DEBFC8DA1F2397A41670 /* Pods_RunnerTests.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
331C8082294A63A400263BE5 /* RunnerTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -76,6 +104,19 @@
|
||||
path = RunnerTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
42959B066F5B690723DADF19 /* Pods */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
496E5DE1B7B0D8EBAEAB5451 /* Pods-Runner.debug.xcconfig */,
|
||||
CE1BE763A99EA4D0B227AFE7 /* Pods-Runner.release.xcconfig */,
|
||||
24CCA05467623A36B01E627A /* Pods-Runner.profile.xcconfig */,
|
||||
45627CB2AA093EADB1068927 /* Pods-RunnerTests.debug.xcconfig */,
|
||||
AFC5F00ED7B1F8A52E9F6DC0 /* Pods-RunnerTests.release.xcconfig */,
|
||||
B29BC380D6DE4DE1C602C120 /* Pods-RunnerTests.profile.xcconfig */,
|
||||
);
|
||||
path = Pods;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9740EEB11CF90186004384FC /* Flutter */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -94,6 +135,8 @@
|
||||
97C146F01CF9000F007C117D /* Runner */,
|
||||
97C146EF1CF9000F007C117D /* Products */,
|
||||
331C8082294A63A400263BE5 /* RunnerTests */,
|
||||
42959B066F5B690723DADF19 /* Pods */,
|
||||
0F6BCADAD92A2AAE8C04713B /* Frameworks */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
@ -128,8 +171,10 @@
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */;
|
||||
buildPhases = (
|
||||
701A59B631BA9D5ACDD9EA12 /* [CP] Check Pods Manifest.lock */,
|
||||
331C807D294A63A400263BE5 /* Sources */,
|
||||
331C807F294A63A400263BE5 /* Resources */,
|
||||
8D2F751458AC564B8B8186B4 /* Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@ -145,12 +190,14 @@
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
|
||||
buildPhases = (
|
||||
B7F4927D1785E993075CECFB /* [CP] Check Pods Manifest.lock */,
|
||||
9740EEB61CF901F6004384FC /* Run Script */,
|
||||
97C146EA1CF9000F007C117D /* Sources */,
|
||||
97C146EB1CF9000F007C117D /* Frameworks */,
|
||||
97C146EC1CF9000F007C117D /* Resources */,
|
||||
9705A1C41CF9048500538489 /* Embed Frameworks */,
|
||||
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
|
||||
19CA00A72D52C12D20E51DAE /* [CP] Embed Pods Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@ -222,6 +269,23 @@
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
19CA00A72D52C12D20E51DAE /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
@ -238,6 +302,28 @@
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
|
||||
};
|
||||
701A59B631BA9D5ACDD9EA12 /* [CP] Check Pods Manifest.lock */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
|
||||
"${PODS_ROOT}/Manifest.lock",
|
||||
);
|
||||
name = "[CP] Check Pods Manifest.lock";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
"$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
9740EEB61CF901F6004384FC /* Run Script */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
@ -253,6 +339,28 @@
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
|
||||
};
|
||||
B7F4927D1785E993075CECFB /* [CP] Check Pods Manifest.lock */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
|
||||
"${PODS_ROOT}/Manifest.lock",
|
||||
);
|
||||
name = "[CP] Check Pods Manifest.lock";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
@ -361,8 +469,10 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||
DEVELOPMENT_TEAM = A7A93GC9AY;
|
||||
DEVELOPMENT_TEAM = KKHHBB64L3;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
@ -371,6 +481,8 @@
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.pocketpyExample;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
STRIP_STYLE = "non-global";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
@ -379,6 +491,7 @@
|
||||
};
|
||||
331C8088294A63A400263BE5 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 45627CB2AA093EADB1068927 /* Pods-RunnerTests.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
@ -396,6 +509,7 @@
|
||||
};
|
||||
331C8089294A63A400263BE5 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = AFC5F00ED7B1F8A52E9F6DC0 /* Pods-RunnerTests.release.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
@ -411,6 +525,7 @@
|
||||
};
|
||||
331C808A294A63A400263BE5 /* Profile */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = B29BC380D6DE4DE1C602C120 /* Pods-RunnerTests.profile.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
@ -541,8 +656,10 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||
DEVELOPMENT_TEAM = A7A93GC9AY;
|
||||
DEVELOPMENT_TEAM = KKHHBB64L3;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
@ -551,6 +668,8 @@
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.pocketpyExample;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
STRIP_STYLE = "non-global";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@ -564,8 +683,10 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||
DEVELOPMENT_TEAM = A7A93GC9AY;
|
||||
DEVELOPMENT_TEAM = KKHHBB64L3;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
@ -574,6 +695,8 @@
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.pocketpyExample;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
STRIP_STYLE = "non-global";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
enableGPUValidationMode = "1"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
|
||||
@ -4,4 +4,7 @@
|
||||
<FileRef
|
||||
location = "group:Runner.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Pods/Pods.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import UIKit
|
||||
import Flutter
|
||||
|
||||
@UIApplicationMain
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate {
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
|
||||
@ -15,7 +15,7 @@ EXTERNAL SOURCES:
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
||||
pocketpy: 99ce4fe9fc8cccfda3633f5599c2d8f802c6d5e8
|
||||
pocketpy: 575448ea94df6d7281990c5b6020728e795fd046
|
||||
|
||||
PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
|
||||
|
||||
|
||||
@ -240,6 +240,7 @@
|
||||
33CC10EB2044A3C60003C045 /* Resources */,
|
||||
33CC110E2044A8840003C045 /* Bundle Framework */,
|
||||
3399D490228B24CF009A79C7 /* ShellScript */,
|
||||
A4D061C1E57F49C3123F636C /* [CP] Embed Pods Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@ -404,6 +405,23 @@
|
||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
A4D061C1E57F49C3123F636C /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
|
||||
5
plugins/flutter/pocketpy/ios/Classes/empty.c
Normal file
5
plugins/flutter/pocketpy/ios/Classes/empty.c
Normal file
@ -0,0 +1,5 @@
|
||||
void py_initialize();
|
||||
|
||||
__attribute__((used)) void ensure_no_tree_shaking(void) {
|
||||
py_initialize();
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
// Relative import to be able to reuse the C sources.
|
||||
// See the comment in ../{projectName}}.podspec for more information.
|
||||
#include "../../src/pocketpy.c"
|
||||
@ -17,12 +17,27 @@ A new Flutter FFI plugin project.
|
||||
# builds of apps using this FFI plugin. Podspec does not support relative
|
||||
# paths, so Classes contains a forwarder C file that relatively imports
|
||||
# `../src/*` so that the C sources can be shared among all target platforms.
|
||||
s.source = { :path => '.' }
|
||||
s.source_files = 'Classes/**/*'
|
||||
s.dependency 'Flutter'
|
||||
s.platform = :ios, '13.0'
|
||||
s.platform = :ios, '12.0'
|
||||
|
||||
s.swift_version = '5.0'
|
||||
|
||||
s.source = { :path => '.' }
|
||||
s.source_files = 'Classes/**/*'
|
||||
s.library = 'c'
|
||||
|
||||
# Flutter.framework does not contain a i386 slice.
|
||||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
|
||||
s.swift_version = '5.0'
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386',
|
||||
'OTHER_LDFLAGS' => '-force_load ' + __dir__ + '/pocketpy/build/pocketpy.xcframework/ios-arm64/libpocketpy.a',
|
||||
}
|
||||
|
||||
s.prepare_command = <<-CMD
|
||||
rm -rf pocketpy
|
||||
git clone --branch v2.1.3-patch --depth 1 https://github.com/pocketpy/pocketpy.git
|
||||
cd pocketpy
|
||||
git submodule update --init --recursive --depth 1
|
||||
bash build_ios_libs.sh
|
||||
CMD
|
||||
end
|
||||
|
||||
@ -14,7 +14,8 @@ void flutterPrint(Pointer<Char> text) {
|
||||
final PocketpyBindings pocket = () {
|
||||
DynamicLibrary dylib;
|
||||
if (Platform.isMacOS || Platform.isIOS) {
|
||||
dylib = DynamicLibrary.open('$_libName.framework/$_libName');
|
||||
// dylib = DynamicLibrary.open('$_libName.framework/$_libName');
|
||||
dylib = DynamicLibrary.process();
|
||||
} else if (Platform.isAndroid || Platform.isLinux) {
|
||||
dylib = DynamicLibrary.open('lib$_libName.so');
|
||||
} else if (Platform.isWindows) {
|
||||
|
||||
5
plugins/flutter/pocketpy/macos/Classes/empty.c
Normal file
5
plugins/flutter/pocketpy/macos/Classes/empty.c
Normal file
@ -0,0 +1,5 @@
|
||||
void py_initialize();
|
||||
|
||||
__attribute__((used)) void ensure_no_tree_shaking(void) {
|
||||
py_initialize();
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
// Relative import to be able to reuse the C sources.
|
||||
// See the comment in ../{projectName}}.podspec for more information.
|
||||
#include "../../src/pocketpy.c"
|
||||
@ -17,11 +17,25 @@ A new Flutter FFI plugin project.
|
||||
# builds of apps using this FFI plugin. Podspec does not support relative
|
||||
# paths, so Classes contains a forwarder C file that relatively imports
|
||||
# `../src/*` so that the C sources can be shared among all target platforms.
|
||||
s.source = { :path => '.' }
|
||||
s.source_files = 'Classes/**/*'
|
||||
s.dependency 'FlutterMacOS'
|
||||
|
||||
s.platform = :osx, '10.11'
|
||||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
|
||||
s.swift_version = '5.0'
|
||||
|
||||
s.source = { :path => '.' }
|
||||
s.source_files = 'Classes/**/*'
|
||||
s.library = 'c'
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
'OTHER_LDFLAGS' => '-force_load ' + __dir__ + '/pocketpy/build/libpocketpy.a',
|
||||
}
|
||||
|
||||
s.prepare_command = <<-CMD
|
||||
rm -rf pocketpy
|
||||
git clone --branch v2.1.3-patch --depth 1 https://github.com/pocketpy/pocketpy.git
|
||||
cd pocketpy
|
||||
git submodule update --init --recursive --depth 1
|
||||
bash build_darwin_libs.sh
|
||||
CMD
|
||||
end
|
||||
|
||||
|
||||
@ -14,11 +14,13 @@ include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
pocketpy
|
||||
GIT_REPOSITORY https://github.com/pocketpy/pocketpy.git
|
||||
GIT_TAG v2.1.3
|
||||
GIT_TAG v2.1.3-patch
|
||||
)
|
||||
|
||||
set(PK_ENABLE_OS OFF CACHE BOOL "" FORCE)
|
||||
set(PK_ENABLE_DETERMINISM ON CACHE BOOL "" FORCE)
|
||||
set(PK_BUILD_MODULE_LZ4 ON CACHE BOOL "" FORCE)
|
||||
set(PK_BUILD_MODULE_CUTE_PNG ON CACHE BOOL "" FORCE)
|
||||
set(PK_BUILD_SHARED_LIB ON CACHE BOOL "" FORCE)
|
||||
|
||||
set_target_properties(pocketpy PROPERTIES
|
||||
|
||||
@ -1 +0,0 @@
|
||||
// nothing
|
||||
31
scripts/merge_built_libraries.py
Normal file
31
scripts/merge_built_libraries.py
Normal file
@ -0,0 +1,31 @@
|
||||
import os, sys
|
||||
assert sys.platform == 'darwin', sys.platform
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
build_dir = sys.argv[1]
|
||||
output_dir = sys.argv[1]
|
||||
elif len(sys.argv) == 3:
|
||||
build_dir = sys.argv[1]
|
||||
output_dir = sys.argv[2]
|
||||
else:
|
||||
print('Usage: python merge_built_libraries.py <build_dir> [output_dir]')
|
||||
exit(1)
|
||||
|
||||
assert os.path.exists(build_dir), build_dir
|
||||
assert os.path.exists(output_dir), output_dir
|
||||
|
||||
archives = []
|
||||
|
||||
# get all .a files in build/3rd recursive
|
||||
for root, dirs, files in os.walk(build_dir):
|
||||
for file in files:
|
||||
if file.endswith('.a') and file.startswith('lib'):
|
||||
archives.append(os.path.join(root, file))
|
||||
|
||||
print('Merging the following static libraries:')
|
||||
for archive in archives:
|
||||
print('- ' + archive)
|
||||
|
||||
# libtool -static -o libpocketpy.a
|
||||
output_archive = os.path.join(output_dir, 'libpocketpy.a')
|
||||
os.system('libtool -static -o {} {}'.format(output_archive, ' '.join(archives)))
|
||||
@ -262,7 +262,6 @@ void VM__ctor(VM* self) {
|
||||
|
||||
pk__add_module_conio();
|
||||
pk__add_module_lz4(); // optional
|
||||
pk__add_module_libhv(); // optional
|
||||
pk__add_module_cute_png(); // optional
|
||||
pk__add_module_pkpy();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user