PORTNAME=	qcs-sdk-python
DISTVERSIONPREFIX=	python/v
DISTVERSION=	0.20.1
PORTREVISION=	8
CATEGORIES=	devel python
#MASTER_SITES=	PYPI
PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
DISTNAME=	${PORTNAME:S/-/_/g}-${DISTVERSION}

MAINTAINER=	yuri@FreeBSD.org
COMMENT=	Python interface for the QCS Rust SDK
WWW=		https://github.com/rigetti/qcs-sdk-rust

LICENSE=	APACHE20

BUILD_DEPENDS=	${PYTHON_PKGNAMEPREFIX}maturin>=1.2.3:devel/py-maturin@${PY_FLAVOR} \
		${PYTHON_PKGNAMEPREFIX}poetry-core>=1.0.0:devel/py-poetry-core@${PY_FLAVOR}
RUN_DEPENDS=	${PYNUMPY}

USES=		cargo python
USE_PYTHON=	pep517 autoplist

USE_GITHUB=	yes
GH_ACCOUNT=	rigetti
GH_PROJECT=	qcs-sdk-rust

RUSTFLAGS=	${ARCH:S/i386/YES/:C/^[a-z].*//:S/YES/-C target-feature=+sse,+sse2/} # add sse sse2 target-features only on i386

CARGO_CRATES=	addr2line-0.24.1 \
		adler2-2.0.0 \
		aho-corasick-1.1.3 \
		ansi_term-0.12.1 \
		anyhow-1.0.89 \
		approx-0.5.1 \
		arc-swap-1.7.1 \
		assert2-0.3.15 \
		assert2-macros-0.3.15 \
		async-socks5-0.5.1 \
		async-stream-0.3.5 \
		async-stream-impl-0.3.5 \
		async-trait-0.1.82 \
		atomic-0.6.0 \
		atty-0.2.14 \
		autocfg-1.3.0 \
		axum-0.6.20 \
		axum-core-0.3.4 \
		backoff-0.4.0 \
		backtrace-0.3.74 \
		base64-0.13.1 \
		base64-0.21.7 \
		base64-0.22.1 \
		bindgen-0.53.3 \
		bitflags-1.3.2 \
		bitflags-2.6.0 \
		block-buffer-0.10.4 \
		built-0.6.1 \
		bumpalo-3.16.0 \
		bytecount-0.6.8 \
		bytemuck-1.18.0 \
		byteorder-1.5.0 \
		bytes-1.7.2 \
		cached-0.44.0 \
		cached_proc_macro-0.17.0 \
		cached_proc_macro_types-0.1.1 \
		cargo-lock-9.0.0 \
		cc-1.1.21 \
		cexpr-0.4.0 \
		cfg-expr-0.15.8 \
		cfg-if-0.1.10 \
		cfg-if-1.0.0 \
		chrono-0.4.38 \
		clang-sys-0.29.3 \
		clap-2.34.0 \
		console-0.15.8 \
		convert_case-0.4.0 \
		core-foundation-0.9.4 \
		core-foundation-sys-0.8.7 \
		cpufeatures-0.2.14 \
		crossbeam-0.8.4 \
		crossbeam-channel-0.5.13 \
		crossbeam-deque-0.8.5 \
		crossbeam-epoch-0.9.18 \
		crossbeam-queue-0.3.11 \
		crossbeam-utils-0.8.20 \
		crypto-common-0.1.6 \
		ct-logs-0.8.0 \
		darling-0.14.4 \
		darling-0.20.10 \
		darling_core-0.14.4 \
		darling_core-0.20.10 \
		darling_macro-0.14.4 \
		darling_macro-0.20.10 \
		deranged-0.3.11 \
		derive_builder-0.12.0 \
		derive_builder-0.20.1 \
		derive_builder_core-0.12.0 \
		derive_builder_core-0.20.1 \
		derive_builder_macro-0.12.0 \
		derive_builder_macro-0.20.1 \
		derive_more-0.99.18 \
		diff-0.1.13 \
		digest-0.10.7 \
		dircpy-0.3.19 \
		dirs-5.0.1 \
		dirs-sys-0.4.1 \
		either-1.13.0 \
		encode_unicode-0.3.6 \
		encoding_rs-0.8.34 \
		enum-as-inner-0.5.1 \
		env_logger-0.7.1 \
		equivalent-1.0.1 \
		erased-serde-0.3.31 \
		errno-0.3.9 \
		fastrand-2.1.1 \
		figment-0.10.19 \
		fixedbitset-0.4.2 \
		float-cmp-0.9.0 \
		fnv-1.0.7 \
		form_urlencoded-1.2.1 \
		futures-0.3.30 \
		futures-channel-0.3.30 \
		futures-core-0.3.30 \
		futures-executor-0.3.30 \
		futures-io-0.3.30 \
		futures-macro-0.3.30 \
		futures-sink-0.3.30 \
		futures-task-0.3.30 \
		futures-timer-3.0.3 \
		futures-util-0.3.30 \
		generic-array-0.14.7 \
		getrandom-0.2.15 \
		gimli-0.31.0 \
		glob-0.3.1 \
		h2-0.3.26 \
		handlebars-4.5.0 \
		hashbrown-0.12.3 \
		hashbrown-0.13.2 \
		hashbrown-0.14.5 \
		headers-0.3.9 \
		headers-core-0.2.0 \
		heck-0.4.1 \
		heck-0.5.0 \
		hermit-abi-0.1.19 \
		hermit-abi-0.3.9 \
		hermit-abi-0.4.0 \
		hex-0.4.3 \
		home-0.5.9 \
		http-0.2.12 \
		http-body-0.4.6 \
		http-range-header-0.3.1 \
		httparse-1.9.4 \
		httpdate-1.0.3 \
		humantime-1.3.0 \
		hyper-0.14.30 \
		hyper-proxy-0.9.1 \
		hyper-rustls-0.22.1 \
		hyper-rustls-0.24.2 \
		hyper-socks2-0.8.0 \
		hyper-timeout-0.4.1 \
		ident_case-1.0.1 \
		idna-0.5.0 \
		indexmap-1.9.3 \
		indexmap-2.5.0 \
		indoc-2.0.5 \
		inlinable_string-0.1.15 \
		insta-1.40.0 \
		instant-0.1.13 \
		inventory-0.3.15 \
		ipnet-2.10.0 \
		is-terminal-0.4.13 \
		itertools-0.11.0 \
		itertools-0.12.1 \
		itoa-1.0.11 \
		jobserver-0.1.32 \
		js-sys-0.3.70 \
		jsonwebtoken-9.3.0 \
		jwalk-0.8.1 \
		lazy_static-1.5.0 \
		lazycell-1.3.0 \
		lexical-7.0.1 \
		lexical-core-1.0.1 \
		lexical-parse-float-1.0.1 \
		lexical-parse-integer-1.0.1 \
		lexical-util-1.0.2 \
		lexical-write-float-1.0.1 \
		lexical-write-integer-1.0.1 \
		libc-0.2.158 \
		libloading-0.5.2 \
		libloading-0.8.5 \
		libm-0.2.8 \
		libquil-sys-0.4.0 \
		libredox-0.1.3 \
		linked-hash-map-0.5.6 \
		linux-raw-sys-0.4.14 \
		lock_api-0.4.12 \
		log-0.4.22 \
		maplit-1.0.2 \
		matchers-0.1.0 \
		matchit-0.7.3 \
		matrixmultiply-0.3.9 \
		memchr-2.7.4 \
		memoffset-0.9.1 \
		mime-0.3.17 \
		mime_guess-2.0.5 \
		minimal-lexical-0.2.1 \
		miniz_oxide-0.8.0 \
		mio-1.0.2 \
		multimap-0.10.0 \
		nalgebra-0.29.0 \
		nalgebra-macros-0.1.0 \
		ndarray-0.15.6 \
		nom-5.1.3 \
		nom-7.1.3 \
		nom_locate-4.2.0 \
		nu-ansi-term-0.46.0 \
		num-0.4.3 \
		num-bigint-0.4.6 \
		num-complex-0.4.6 \
		num-conv-0.1.0 \
		num-integer-0.1.46 \
		num-iter-0.1.45 \
		num-rational-0.4.2 \
		num-traits-0.2.19 \
		numpy-0.20.0 \
		object-0.36.4 \
		once_cell-1.19.0 \
		openssl-probe-0.1.5 \
		opentelemetry-0.20.0 \
		opentelemetry-0.23.0 \
		opentelemetry-http-0.9.0 \
		opentelemetry-otlp-0.16.0 \
		opentelemetry-proto-0.6.0 \
		opentelemetry-stdout-0.4.0 \
		opentelemetry_api-0.20.0 \
		opentelemetry_sdk-0.20.0 \
		opentelemetry_sdk-0.23.0 \
		option-ext-0.2.0 \
		ordered-float-3.9.2 \
		ordered-float-4.2.2 \
		overload-0.1.1 \
		parking_lot-0.12.3 \
		parking_lot_core-0.9.10 \
		paste-1.0.15 \
		pbjson-0.6.0 \
		pbjson-build-0.6.2 \
		pbjson-types-0.6.0 \
		pear-0.2.9 \
		pear_codegen-0.2.9 \
		peeking_take_while-0.1.2 \
		pem-3.0.4 \
		percent-encoding-2.3.1 \
		pest-2.7.13 \
		pest_derive-2.7.13 \
		pest_generator-2.7.13 \
		pest_meta-2.7.13 \
		petgraph-0.6.5 \
		pin-project-1.1.5 \
		pin-project-internal-1.1.5 \
		pin-project-lite-0.2.14 \
		pin-utils-0.1.0 \
		pkg-config-0.3.30 \
		portable-atomic-1.7.0 \
		powerfmt-0.2.0 \
		ppv-lite86-0.2.20 \
		prettyplease-0.2.22 \
		proc-macro2-1.0.86 \
		proc-macro2-diagnostics-0.10.1 \
		prost-0.12.6 \
		prost-build-0.12.6 \
		prost-derive-0.12.6 \
		prost-types-0.12.6 \
		pyo3-0.20.3 \
		pyo3-asyncio-0.20.0 \
		pyo3-build-config-0.20.3 \
		pyo3-build-config-0.22.3 \
		pyo3-ffi-0.20.3 \
		pyo3-log-0.8.4 \
		pyo3-macros-0.20.3 \
		pyo3-macros-backend-0.20.3 \
		pyo3-opentelemetry-0.3.2-dev.1 \
		pyo3-opentelemetry-macros-0.3.2-rc.0 \
		pyo3-tracing-subscriber-0.1.2-dev.1 \
		qcs-api-0.2.1 \
		qcs-api-client-common-0.10.2 \
		qcs-api-client-grpc-0.10.2 \
		qcs-api-client-openapi-0.11.2 \
		quick-error-1.2.3 \
		quote-1.0.37 \
		rand-0.8.5 \
		rand_chacha-0.3.1 \
		rand_core-0.6.4 \
		rand_distr-0.4.3 \
		rawpointer-0.2.1 \
		rayon-1.10.0 \
		rayon-core-1.12.1 \
		redox_syscall-0.5.4 \
		redox_users-0.4.6 \
		regex-1.10.6 \
		regex-automata-0.1.10 \
		regex-automata-0.4.7 \
		regex-syntax-0.6.29 \
		regex-syntax-0.8.4 \
		reqwest-0.11.27 \
		reqwest-middleware-0.2.5 \
		reqwest-tracing-0.4.8 \
		rigetti-pyo3-0.3.6 \
		rigetti-pyo3-0.4.1 \
		ring-0.16.20 \
		ring-0.17.8 \
		rmp-0.8.14 \
		rmp-serde-1.3.0 \
		rstest-0.17.0 \
		rstest_macros-0.17.0 \
		rustc-demangle-0.1.24 \
		rustc-hash-1.1.0 \
		rustc_version-0.4.1 \
		rustix-0.38.37 \
		rustls-0.19.1 \
		rustls-0.21.12 \
		rustls-0.22.4 \
		rustls-native-certs-0.5.0 \
		rustls-native-certs-0.6.3 \
		rustls-native-certs-0.7.3 \
		rustls-pemfile-1.0.4 \
		rustls-pemfile-2.1.3 \
		rustls-pki-types-1.8.0 \
		rustls-webpki-0.101.7 \
		rustls-webpki-0.102.8 \
		rustversion-1.0.17 \
		ryu-1.0.18 \
		safe_arch-0.7.2 \
		same-file-1.0.6 \
		schannel-0.1.24 \
		scoped-tls-1.0.1 \
		scopeguard-1.2.0 \
		sct-0.6.1 \
		sct-0.7.1 \
		security-framework-2.11.1 \
		security-framework-sys-2.11.1 \
		semver-1.0.23 \
		serde-1.0.210 \
		serde_derive-1.0.210 \
		serde_json-1.0.128 \
		serde_spanned-0.6.7 \
		serde_urlencoded-0.7.1 \
		sha1-0.10.6 \
		sha2-0.10.8 \
		sharded-slab-0.1.7 \
		shellexpand-3.1.0 \
		shlex-0.1.1 \
		shlex-1.3.0 \
		simba-0.6.0 \
		similar-2.6.0 \
		simple_asn1-0.6.2 \
		simple_logger-4.3.3 \
		slab-0.4.9 \
		smallvec-1.13.2 \
		socket2-0.5.7 \
		spin-0.5.2 \
		spin-0.9.8 \
		static_assertions-1.1.0 \
		statrs-0.16.1 \
		strsim-0.8.0 \
		strsim-0.10.0 \
		strsim-0.11.1 \
		strum-0.26.3 \
		strum_macros-0.26.4 \
		subtle-2.6.1 \
		syn-1.0.109 \
		syn-2.0.77 \
		sync_wrapper-0.1.2 \
		system-configuration-0.5.1 \
		system-configuration-sys-0.5.0 \
		system-deps-6.2.2 \
		target-lexicon-0.12.16 \
		task-local-extensions-0.1.4 \
		tempfile-3.12.0 \
		termcolor-1.4.1 \
		test-case-3.3.1 \
		test-case-core-3.3.1 \
		test-case-macros-3.3.1 \
		textwrap-0.11.0 \
		thiserror-1.0.63 \
		thiserror-impl-1.0.63 \
		thread_local-1.1.8 \
		time-0.3.36 \
		time-core-0.1.2 \
		time-macros-0.2.18 \
		tinyvec-1.8.0 \
		tinyvec_macros-0.1.1 \
		tokio-1.40.0 \
		tokio-io-timeout-1.2.0 \
		tokio-macros-2.4.0 \
		tokio-rustls-0.22.0 \
		tokio-rustls-0.24.1 \
		tokio-rustls-0.25.0 \
		tokio-socks-0.5.2 \
		tokio-stream-0.1.16 \
		tokio-util-0.7.12 \
		toml-0.7.8 \
		toml-0.8.19 \
		toml_datetime-0.6.8 \
		toml_edit-0.19.15 \
		toml_edit-0.22.21 \
		tonic-0.11.0 \
		tonic-build-0.11.0 \
		tonic-web-0.11.0 \
		tower-0.4.13 \
		tower-http-0.4.4 \
		tower-layer-0.3.3 \
		tower-service-0.3.3 \
		tracing-0.1.40 \
		tracing-attributes-0.1.27 \
		tracing-core-0.1.32 \
		tracing-log-0.1.4 \
		tracing-log-0.2.0 \
		tracing-opentelemetry-0.20.0 \
		tracing-opentelemetry-0.24.0 \
		tracing-serde-0.1.3 \
		tracing-subscriber-0.3.18 \
		try-lock-0.2.5 \
		typenum-1.17.0 \
		ucd-trie-0.1.6 \
		uncased-0.9.10 \
		unic-char-property-0.9.0 \
		unic-char-range-0.9.0 \
		unic-common-0.9.0 \
		unic-ucd-ident-0.9.0 \
		unic-ucd-version-0.9.0 \
		unicase-2.7.0 \
		unicode-bidi-0.3.15 \
		unicode-ident-1.0.13 \
		unicode-normalization-0.1.24 \
		unicode-width-0.1.14 \
		unindent-0.2.3 \
		untrusted-0.7.1 \
		untrusted-0.9.0 \
		url-2.5.2 \
		urlencoding-2.1.3 \
		urlpattern-0.2.0 \
		uuid-1.10.0 \
		valuable-0.1.0 \
		vec_map-0.8.2 \
		version-compare-0.2.0 \
		version_check-0.9.5 \
		walkdir-2.5.0 \
		want-0.3.1 \
		warp-0.3.7 \
		wasi-0.11.0+wasi-snapshot-preview1 \
		wasm-bindgen-0.2.93 \
		wasm-bindgen-backend-0.2.93 \
		wasm-bindgen-futures-0.4.43 \
		wasm-bindgen-macro-0.2.93 \
		wasm-bindgen-macro-support-0.2.93 \
		wasm-bindgen-shared-0.2.93 \
		web-sys-0.3.70 \
		web-time-1.1.0 \
		webpki-0.21.4 \
		webpki-roots-0.25.4 \
		which-3.1.1 \
		wide-0.7.28 \
		winapi-0.3.9 \
		winapi-i686-pc-windows-gnu-0.4.0 \
		winapi-util-0.1.9 \
		winapi-x86_64-pc-windows-gnu-0.4.0 \
		windows-sys-0.48.0 \
		windows-sys-0.52.0 \
		windows-sys-0.59.0 \
		windows-targets-0.48.5 \
		windows-targets-0.52.6 \
		windows_aarch64_gnullvm-0.48.5 \
		windows_aarch64_gnullvm-0.52.6 \
		windows_aarch64_msvc-0.48.5 \
		windows_aarch64_msvc-0.52.6 \
		windows_i686_gnu-0.48.5 \
		windows_i686_gnu-0.52.6 \
		windows_i686_gnullvm-0.52.6 \
		windows_i686_msvc-0.48.5 \
		windows_i686_msvc-0.52.6 \
		windows_x86_64_gnu-0.48.5 \
		windows_x86_64_gnu-0.52.6 \
		windows_x86_64_gnullvm-0.48.5 \
		windows_x86_64_gnullvm-0.52.6 \
		windows_x86_64_msvc-0.48.5 \
		windows_x86_64_msvc-0.52.6 \
		winnow-0.5.40 \
		winnow-0.6.18 \
		winreg-0.50.0 \
		yansi-1.0.1 \
		zerocopy-0.7.35 \
		zerocopy-derive-0.7.35 \
		zeroize-1.8.1 \
		zeromq-src-0.2.6+4.3.4 \
		zmq-0.10.0 \
		zmq-sys-0.12.0 \
		quil-rs@git+https://github.com/rigetti/quil-rs?tag=quil-py/v0.12.1\#a0f2776893d3ce33eb9f29449f3b4b0e9ed24174

CARGO_BUILD=	no
CARGO_INSTALL=	no
CARGO_TEST=	no
CARGO_TARGET_DIR=	${WRKSRC}/crates/python

MAKE_ENV=	${CARGO_ENV}
TEST_ENV=	${MAKE_ENV} PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
TEST_WRKSRC=	${BUILD_WRKDIR}

WRKSRC_SUBDIR=	crates/python

BINARY_ALIAS=	python3=${PYTHON_CMD}

post-patch:
	@${MKDIR} ${WRKDIR}/quil-rs-quil-py
	@${MV} ${WRKDIR}/quil-rs-quil-py-v0.12.1 ${WRKDIR}/quil-rs-quil-py/v0.12.1
	# prevent breakage due to crates/.cargo inclusion
	@${REINPLACE_CMD} \
		-e 's|members = \["crates/\*"\]|members = ["crates/python"]|' \
		${WRKSRC}/../../Cargo.toml

.include <bsd.port.mk>
