Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cryptography,pydantic_core, pycrdt -- rust based pkg #904

Merged
merged 25 commits into from
May 7, 2024
Merged
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
4 changes: 2 additions & 2 deletions emci/rattler_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def build_with_rattler(recipe=None, recipes_dir=None, emscripten_wasm32=False):

# add conda forge and emscripten-forge channels
cmd.extend([
"-c", "microsoft",
"-c", "https://repo.mamba.pm/emscripten-forge",
"-c", "conda-forge",
"-c", "https://repo.mamba.pm/emscripten-forge"
"-c", "microsoft",
])

# pass existing env vars to subprocess
Expand Down
5 changes: 3 additions & 2 deletions recipes/recipes/pytester/rattler_recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ outputs:
version: ${{ version }}

build:
number: 4
number: 6

noarch: python

requirements:
Expand All @@ -33,7 +34,7 @@ outputs:
name: pytester-run
version: ${{ version }}
build:
number: 4
number: 6
noarch: generic
requirements:
run:
Expand Down
23 changes: 23 additions & 0 deletions recipes/recipes/rust/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
47 changes: 47 additions & 0 deletions recipes/recipes/rust/activate-rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

echo "Activating Rust"



export RUSTUP_HOME=$BUILD_PREFIX/.rustup
export CARGO_HOME=$BUILD_PREFIX/.cargo
export PATH=$CARGO_HOME/bin:$PATH


#echo $PKG_VERSION > ${PREFIX}/.rust_version

# is there a .bashenv file?
if [ -f ${PREFIX}/.bashenv ]; then
# create a backup of the .bashenv file
cp ${PREFIX}/.bashenv ${PREFIX}/.bashenv.bak
fi


# load the rust version from the .rust_version file

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y #--default-toolchain=1.78.0
rustup install nightly-2024-04-22
rustup default nightly-2024-04-22
rustup target add wasm32-unknown-emscripten




export OPENSSL_INCLUDE_PATH=$PREFIX/include
export OPENSSL_LIBRARY_PATH=$PREFIX/lib
export OPENSSL_DIR=$PREFIX/lib
export WASM32_UNKNOWN_EMSCRIPTEN_OPENSSL_LIB_DIR=$PREFIX/lib
export WASM32_UNKNOWN_EMSCRIPTEN_OPENSSL_DIR=$PREFIX/lib
export WASM32_UNKNOWN_EMSCRIPTEN_OPENSSL_INCLUDE_DIR=$PREFIX/include


export PYO3_CROSS=1
export PYO3_PYTHON=python3
export PYO3_CROSS_PYTHON_VERSION=$PY_VER
export PYO3_CROSS_LIB_DIR=$PREFIX/lib
export PYO3_CROSS_INCLUDE_DIR=$PREFIX/include
export PYO3_PYTHON=python

export CARGO_BUILD_TARGET="wasm32-unknown-emscripten"
export LDFLAGS="$LDFLAGS -L${PREFIX}/lib"
7 changes: 7 additions & 0 deletions recipes/recipes/rust/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mkdir -p ${PREFIX}/etc/conda/activate.d
mkdir -p ${PREFIX}/etc/conda/deactivate.d


cp "${RECIPE_DIR}"/activate-rust.sh ${PREFIX}/etc/conda/activate.d/activate_z-${PKG_NAME}.sh
cp "${RECIPE_DIR}"/deactivate-rust.sh ${PREFIX}/etc/conda/deactivate.d/deactivate_z-${PKG_NAME}.sh

14 changes: 14 additions & 0 deletions recipes/recipes/rust/deactivate-rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

echo "Deactivating Rust"

unset CARGO_HOME
unset RUSTUP_HOME



# is there a .bashenv.bak file?
if [ -f ${PREFIX}/.bashenv.bak ]; then
# restore the .bashenv file
mv ${PREFIX}/.bashenv.bak ${PREFIX}/.bashenv
fi
22 changes: 22 additions & 0 deletions recipes/recipes/rust/rattler_recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
context:
name: rust
version: "1.79.0"

package:
name: ${{ name|lower }}
version: ${{ version }}


build:
number: 29

requirements:
build:
- curl

about:
summary: rust

extra:
recipe-maintainers:
- DerThorsten
4 changes: 2 additions & 2 deletions recipes/recipes_emscripten/cryptography/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
export LDFLAGS="$LDFLAGS -L${PREFIX}/lib"
${PYTHON} -m pip install .
${PYTHON} -m pip install . -vvv

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From aeadf0c7223c0b8c7e209f6b555dfc91de31a34c Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Mon, 29 Jan 2024 16:34:05 -0800
Subject: [PATCH] Tell rust-lang/libc that time_t is 64 bits

See upstream PR:
https://github.com/rust-lang/libc/pull/3569#event-11634944887
---
src/rust/Cargo.toml | 3 +++
1 file changed, 3 insertions(+)

diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml
index 2322486d0..52e7231d7 100644
--- a/src/rust/Cargo.toml
+++ b/src/rust/Cargo.toml
@@ -7,6 +7,9 @@ publish = false
# This specifies the MSRV
rust-version = "1.63.0"

+[patch.crates-io]
+libc = { git = 'https://github.com/hoodmane/libc.git', branch = 'emscripten-time_t-64-bit-2' }
+
[dependencies]
once_cell = "1"
cfg-if = "1"
--
2.25.1
47 changes: 47 additions & 0 deletions recipes/recipes_emscripten/cryptography/rattler_recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
context:
name: cryptography
version: '42.0.2'

package:
name: cryptography
version: ${{ version }}

source:
- url: https://files.pythonhosted.org/packages/0f/6f/40f1b5c6bafc809dd21a9e577458ecc1d8062a7e10148d140f402b535eaa/cryptography-${{version}}.tar.gz
sha256: e0ec52ba3c7f1b7d813cd52649a5b3ef1fc0d433219dc8c93827c57eab6cf888
patches:
- patches/0001-Tell-rust-lang-libc-that-time_t-is-64-bits.patch

build:
number: 2

requirements:
build:
- cross-python_${{target_platform}}
- cffi == 1.15.1
- openssl
- setuptools-rust
- rust

host:
- python
- openssl
- cffi == 1.15.1
run:
- cffi == 1.15.1
tests:
- script: pytester
requirements:
build:
- pytester
run:
- pytester-run
files:
recipe:
- test_import_cryptography.py

extra:
emscripten_tests:
python:
pytest_files:
- test_import_cryptography.py
35 changes: 0 additions & 35 deletions recipes/recipes_emscripten/cryptography/recipe.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
def test_import_cryptography():
import cryptography
import cryptography.fernet
from cryptography.hazmat.primitives.padding import ANSIX923, PKCS7
import cryptography.hazmat
import cryptography.utils
import cryptography.x509




6 changes: 6 additions & 0 deletions recipes/recipes_emscripten/pycrdt/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash


export MATURIN_PYTHON_SYSCONFIGDATA_DIR=${PREFIX}/etc/conda/_sysconfigdata__emscripten_wasm32-emscripten.py
${PYTHON} -m pip install . -vvv

41 changes: 41 additions & 0 deletions recipes/recipes_emscripten/pycrdt/rattler_recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
context:
name: pycrdt
version: '0.8.19'

package:
name: ${{name}}
version: ${{ version }}

source:
- url: https://github.com/jupyter-server/pycrdt/archive/refs/tags/v${{version}}.tar.gz
sha256: 7284bd052c1b7ee56d1f3ffbc7dcd0c72181c6cd92ae3744c63ee80373827b48

build:
number: 0

requirements:
build:
- cross-python_${{target_platform}}
- cffi == 1.15.1
- setuptools-rust
- rust
- maturin

host:
- python
- openssl
- cffi == 1.15.1
run:
- cffi == 1.15.1
- typing_extensions

tests:
- script: pytester
requirements:
build:
- pytester
run:
- pytester-run
files:
recipe:
- test_pycrdt.py
38 changes: 38 additions & 0 deletions recipes/recipes_emscripten/pycrdt/test_pycrdt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json
from pycrdt import Array, Doc, Map, Text

def callback(events, event):
events.append(
dict(
delta=event.delta,
path=event.path,
)
)


def test_str():
doc = Doc()
map2 = Map({"key": "val"})
array1 = Array([2, 3, map2])
map1 = Map({"foo": array1})
array0 = Array([0, 1, None, map1])
doc["array"] = array0
assert str(array0) == '[0.0,1.0,null,{"foo":[2.0,3.0,{"key":"val"}]}]'


def test_nested():
doc = Doc()
text1 = Text("my_text1")
array1 = Array([0, "foo", 2])
text2 = Text("my_text2")
map1 = Map({"foo": [3, 4, 5], "bar": "hello", "baz": text2})
array0 = Array([text1, array1, map1])
doc["array"] = array0
ref = [
"my_text1",
[0, "foo", 2],
{"bar": "hello", "foo": [3, 4, 5], "baz": "my_text2"},
]
assert json.loads(str(array0)) == ref
assert isinstance(array0[2], Map)
assert isinstance(array0[2]["baz"], Text)
6 changes: 6 additions & 0 deletions recipes/recipes_emscripten/pydantic_core/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash


export MATURIN_PYTHON_SYSCONFIGDATA_DIR=${PREFIX}/etc/conda/_sysconfigdata__emscripten_wasm32-emscripten.py
${PYTHON} -m pip install . -vvv

Loading