Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions packages/onnx/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package:
name: onnx
version: 1.15.0
top-level:
- onnx

source:
url: https://files.pythonhosted.org/packages/source/o/onnx/onnx-1.15.0.tar.gz
sha256: b18461a7d38f286618ca2a6e78062a2a9c634ce498e631e708a8041b00094825
patches:
- patches/0001-use-host-protoc.patch
- patches/0002-remove-unsupported-linker-flag.patch

build:
script: |
protoc_dir="${PKGDIR}/.protoc"
if [ ! -x "${protoc_dir}/bin/protoc" ]; then
mkdir -p "${protoc_dir}"
curl --fail --location --silent --show-error \
"https://github.com/protocolbuffers/protobuf/releases/download/v22.3/protoc-22.3-linux-x86_64.zip" \
--output "${protoc_dir}/protoc.zip"
echo "0f8070d762eb8a2f5a13a47713a553f989f9d9b556e7e3ebfa2bd6464e2ecaeb ${protoc_dir}/protoc.zip" \
| sha256sum --check
unzip -q -o "${protoc_dir}/protoc.zip" -d "${protoc_dir}"
fi
export PROTOC="${protoc_dir}/bin/protoc"
export CMAKE_ARGS="${CMAKE_ARGS:-} -DPYTHON_INCLUDE_DIR=${PYTHONINCLUDE} -DPYTHON_INCLUDE_DIRS=${PYTHONINCLUDE} -DPYTHON_LIBRARIES=dummy"
cflags: "-DGOOGLE_PROTOBUF_NO_THREAD_SAFETY"
post: |
rm -rf onnx/backend/test

requirements:
run:
- numpy
- protobuf

test:
imports:
- onnx
- onnx.checker
- onnx.helper

about:
home: https://onnx.ai/
PyPI: https://pypi.org/project/onnx
summary: Open Neural Network Exchange
license: Apache-2.0

extra:
recipe-maintainers:
- metalmancode
15 changes: 15 additions & 0 deletions packages/onnx/patches/0001-use-host-protoc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -262,7 +262,11 @@
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE)
message(STATUS "Download and build Protobuf from ${ProtobufURL}")
FetchContent_MakeAvailable(Protobuf Abseil)
- set(ONNX_PROTOC_EXECUTABLE $<TARGET_FILE:protobuf::protoc>)
+ if(NOT DEFINED ENV{PROTOC} OR "$ENV{PROTOC}" STREQUAL "")
+ message(FATAL_ERROR
+ "PROTOC must point to a host-native protoc 22.3 binary")
+ endif()
+ set(ONNX_PROTOC_EXECUTABLE "$ENV{PROTOC}")
set(Protobuf_VERSION "4.22.3")
# Change back the BUILD_SHARED_LIBS to control the onnx project.

11 changes: 11 additions & 0 deletions packages/onnx/patches/0002-remove-unsupported-linker-flag.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -587,8 +587,6 @@
target_link_libraries(onnx_cpp2py_export
PRIVATE "-Wl,--whole-archive" $<TARGET_FILE:onnx>
"-Wl,--no-whole-archive")
- set_target_properties(onnx_cpp2py_export
- PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
endif()

target_link_libraries(onnx_cpp2py_export PRIVATE onnx)
29 changes: 29 additions & 0 deletions packages/onnx/test_onnx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pytest_pyodide import run_in_pyodide


@run_in_pyodide(packages=["onnx"])
def test_onnx_create_check_and_serialize(selenium):
import onnx
from onnx import TensorProto, checker, helper

node = helper.make_node("Relu", ["input"], ["output"])
graph = helper.make_graph(
[node],
"browser_graph",
[helper.make_tensor_value_info("input", TensorProto.FLOAT, [1, 2])],
[helper.make_tensor_value_info("output", TensorProto.FLOAT, [1, 2])],
)
model = helper.make_model(
graph,
producer_name="pyodide-recipes",
opset_imports=[helper.make_opsetid("", 18)],
)

checker.check_model(model)
payload = model.SerializeToString()
restored = onnx.load_model_from_string(payload)
checker.check_model(restored)

assert payload
assert restored.graph.name == "browser_graph"
assert restored.graph.node[0].op_type == "Relu"