| 
 | 1 | +# onnxruntime requires execinfo.h to build, which only works on glibc-based systems, so alpine is out...  | 
 | 2 | +FROM debian:bullseye-slim as base  | 
 | 3 | + | 
 | 4 | +RUN apt-get update && apt-get -y dist-upgrade  | 
 | 5 | + | 
 | 6 | +FROM base AS onnxruntime  | 
 | 7 | + | 
 | 8 | +RUN apt-get install -y \  | 
 | 9 | +    git \  | 
 | 10 | +    bash \  | 
 | 11 | +    python3 \  | 
 | 12 | +    cmake \  | 
 | 13 | +    git \  | 
 | 14 | +    build-essential \  | 
 | 15 | +    llvm \  | 
 | 16 | +    locales  | 
 | 17 | + | 
 | 18 | +# onnxruntime built in tests need en_US.UTF-8 available  | 
 | 19 | +# Uncomment en_US.UTF-8, then generate  | 
 | 20 | +RUN sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen && locale-gen  | 
 | 21 | + | 
 | 22 | +# build onnxruntime  | 
 | 23 | +RUN mkdir -p /opt/onnxruntime/tmp  | 
 | 24 | +# onnxruntime build relies on being in a git repo, so can't just get a tarball  | 
 | 25 | +# it's a big repo, so fetch shallowly  | 
 | 26 | +RUN cd /opt/onnxruntime/tmp && \  | 
 | 27 | +    git clone --recursive --depth 1 --shallow-submodules https://github.com/Microsoft/onnxruntime  | 
 | 28 | + | 
 | 29 | +# use version that onnxruntime-sys expects  | 
 | 30 | +RUN cd /opt/onnxruntime/tmp/onnxruntime && \  | 
 | 31 | +    git fetch --depth 1 origin tag v1.6.0 && \  | 
 | 32 | +    git checkout v1.6.0  | 
 | 33 | + | 
 | 34 | +RUN /opt/onnxruntime/tmp/onnxruntime/build.sh --config RelWithDebInfo --build_shared_lib --parallel  | 
 | 35 | + | 
 | 36 | +# Build ort-customops, linked against the onnxruntime built above.  | 
 | 37 | +# No tags / releases yet - that commit is from 2021-02-16  | 
 | 38 | +RUN mkdir -p /opt/ort-customops/tmp && \  | 
 | 39 | +    cd /opt/ort-customops/tmp && \  | 
 | 40 | +    git clone --recursive https://github.com/microsoft/ort-customops.git && \  | 
 | 41 | +    cd ort-customops && \  | 
 | 42 | +    git checkout 92f6b51106c9e9143c452e537cb5e41d2dcaa266  | 
 | 43 | + | 
 | 44 | +RUN cd /opt/ort-customops/tmp/ort-customops && \  | 
 | 45 | +    ./build.sh -D ONNXRUNTIME_LIB_DIR=/opt/onnxruntime/tmp/onnxruntime/build/Linux/RelWithDebInfo  | 
 | 46 | + | 
 | 47 | + | 
 | 48 | +# install rust toolchain  | 
 | 49 | +FROM base AS rust-toolchain  | 
 | 50 | + | 
 | 51 | +ARG RUST_VERSION=1.50.0  | 
 | 52 | + | 
 | 53 | +RUN apt-get install -y \  | 
 | 54 | +    curl  | 
 | 55 | + | 
 | 56 | +# install rust toolchain  | 
 | 57 | +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y  --default-toolchain $RUST_VERSION  | 
 | 58 | + | 
 | 59 | +ENV PATH $PATH:/root/.cargo/bin  | 
 | 60 | + | 
 | 61 | + | 
 | 62 | +# build onnxruntime-rs  | 
 | 63 | +FROM rust-toolchain as onnxruntime-rs  | 
 | 64 | +# clang & llvm needed by onnxruntime-sys  | 
 | 65 | +RUN apt-get install -y \  | 
 | 66 | +    build-essential \  | 
 | 67 | +    llvm-dev \  | 
 | 68 | +    libclang-dev \  | 
 | 69 | +    clang  | 
 | 70 | + | 
 | 71 | +RUN mkdir -p \  | 
 | 72 | +    /onnxruntime-rs/build/onnxruntime-sys/src/ \  | 
 | 73 | +    /onnxruntime-rs/build/onnxruntime/src/ \  | 
 | 74 | +    /onnxruntime-rs/build/onnxruntime/tests/ \  | 
 | 75 | +    /opt/onnxruntime/lib \  | 
 | 76 | +    /opt/ort-customops/lib  | 
 | 77 | + | 
 | 78 | +COPY --from=onnxruntime /opt/onnxruntime/tmp/onnxruntime/build/Linux/RelWithDebInfo/libonnxruntime.so /opt/onnxruntime/lib/  | 
 | 79 | +COPY --from=onnxruntime /opt/ort-customops/tmp/ort-customops/out/Linux/libortcustomops.so /opt/ort-customops/lib/  | 
 | 80 | + | 
 | 81 | +WORKDIR /onnxruntime-rs/build  | 
 | 82 | + | 
 | 83 | +ENV ORT_STRATEGY=system  | 
 | 84 | +# this has /lib/ appended to it and is used as a lib search path in onnxruntime-sys's build.rs  | 
 | 85 | +ENV ORT_LIB_LOCATION=/opt/onnxruntime/  | 
 | 86 | + | 
 | 87 | +ENV ONNXRUNTIME_RS_TEST_ORT_CUSTOMOPS_LIB=/opt/ort-customops/lib/libortcustomops.so  | 
 | 88 | + | 
 | 89 | +# create enough of an empty project that dependencies can build  | 
 | 90 | +COPY /Cargo.lock /Cargo.toml /onnxruntime-rs/build/  | 
 | 91 | +COPY /onnxruntime/Cargo.toml /onnxruntime-rs/build/onnxruntime/  | 
 | 92 | +COPY /onnxruntime-sys/Cargo.toml /onnxruntime-sys/build.rs /onnxruntime-rs/build/onnxruntime-sys/  | 
 | 93 | + | 
 | 94 | +CMD cargo test  | 
 | 95 | + | 
 | 96 | +# build dependencies and clean the bogus contents of our two packages  | 
 | 97 | +RUN touch \  | 
 | 98 | +        onnxruntime/src/lib.rs \  | 
 | 99 | +        onnxruntime/tests/integration_tests.rs \  | 
 | 100 | +        onnxruntime-sys/src/lib.rs \  | 
 | 101 | +    && cargo build --tests \  | 
 | 102 | +    && cargo clean --package onnxruntime-sys \  | 
 | 103 | +    && cargo clean --package onnxruntime \  | 
 | 104 | +    && rm -rf \  | 
 | 105 | +        onnxruntime/src/ \  | 
 | 106 | +        onnxruntime/tests/ \  | 
 | 107 | +        onnxruntime-sys/src/  | 
 | 108 | + | 
 | 109 | +# now build the actual source  | 
 | 110 | +COPY /test-models test-models  | 
 | 111 | +COPY /onnxruntime-sys/src onnxruntime-sys/src  | 
 | 112 | +COPY /onnxruntime/src onnxruntime/src  | 
 | 113 | +COPY /onnxruntime/tests onnxruntime/tests  | 
 | 114 | + | 
 | 115 | +RUN ln -s /opt/onnxruntime/lib/libonnxruntime.so /opt/onnxruntime/lib/libonnxruntime.so.1.6.0  | 
 | 116 | +ENV LD_LIBRARY_PATH=/opt/onnxruntime/lib  | 
 | 117 | + | 
 | 118 | +RUN cargo build --tests  | 
0 commit comments