PORTNAME=	cairo
DISTVERSIONPREFIX=	v
DISTVERSION=	2.9.2
CATEGORIES=	lang
PKGNAMESUFFIX=	-language

MAINTAINER=	yuri@FreeBSD.org
COMMENT=	Turing-complete language for creating provable programs
WWW=		https://www.cairo-lang.org/ \
		https://cairo-by-example.com/ \
		https://github.com/starkware-libs/cairo

LICENSE=	APACHE20
LICENSE_FILE=	${WRKSRC}/LICENSE

BROKEN_i386=	compilation fails: error: undefined symbol: __atomic_load

BUILD_DEPENDS=	gmake:devel/gmake
LIB_DEPENDS=	libzstd.so:archivers/zstd

USES=		cargo perl5 pkgconfig
USE_PERL5=	build

USE_GITHUB=	yes
GH_ACCOUNT=	starkware-libs

CARGO_CRATES=	addr2line-0.22.0 \
		adler-1.0.2 \
		aes-0.8.4 \
		ahash-0.8.11 \
		aho-corasick-1.1.3 \
		allocator-api2-0.2.18 \
		anstream-0.6.15 \
		anstyle-1.0.8 \
		anstyle-parse-0.2.5 \
		anstyle-query-1.1.1 \
		anstyle-wincon-3.0.4 \
		anyhow-1.0.86 \
		ark-ec-0.4.2 \
		ark-ff-0.4.2 \
		ark-ff-asm-0.4.2 \
		ark-ff-macros-0.4.2 \
		ark-poly-0.4.2 \
		ark-secp256k1-0.4.0 \
		ark-secp256r1-0.4.0 \
		ark-serialize-0.4.2 \
		ark-serialize-derive-0.4.2 \
		ark-std-0.4.0 \
		arrayvec-0.7.4 \
		ascii-canvas-3.0.0 \
		assert_fs-1.1.2 \
		assert_matches-1.5.0 \
		async-channel-2.3.1 \
		atomic-waker-1.1.2 \
		autocfg-1.3.0 \
		backtrace-0.3.73 \
		base64-0.22.1 \
		base64ct-1.6.0 \
		bimap-0.6.3 \
		bincode-2.0.0-rc.3 \
		bincode_derive-2.0.0-rc.3 \
		bit-set-0.5.3 \
		bit-vec-0.6.3 \
		bitflags-1.3.2 \
		bitflags-2.6.0 \
		bitvec-1.0.1 \
		block-buffer-0.10.4 \
		bstr-1.10.0 \
		bumpalo-3.16.0 \
		byte-slice-cast-1.2.2 \
		byteorder-1.5.0 \
		bytes-1.7.1 \
		bzip2-0.4.4 \
		bzip2-sys-0.1.11+1.0.8 \
		cairo-lang-macro-0.1.1 \
		cairo-lang-macro-attributes-0.1.0 \
		cairo-lang-macro-stable-1.0.0 \
		cairo-vm-1.0.1 \
		camino-1.1.7 \
		cc-1.1.7 \
		cfg-if-1.0.0 \
		cipher-0.4.4 \
		clap-4.5.13 \
		clap_builder-4.5.13 \
		clap_derive-4.5.13 \
		clap_lex-0.7.2 \
		colorchoice-1.0.2 \
		colored-2.1.0 \
		concurrent-queue-2.5.0 \
		console-0.15.8 \
		const-fnv1a-hash-1.1.0 \
		const_format-0.2.32 \
		const_format_proc_macros-0.2.32 \
		constant_time_eq-0.1.5 \
		convert_case-0.6.0 \
		core-foundation-0.9.4 \
		core-foundation-sys-0.8.6 \
		cpufeatures-0.2.12 \
		crc32fast-1.4.2 \
		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 \
		crunchy-0.2.2 \
		crypto-bigint-0.5.5 \
		crypto-common-0.1.6 \
		data-encoding-2.6.0 \
		deranged-0.3.11 \
		derivative-2.2.0 \
		diff-0.1.13 \
		difflib-0.4.0 \
		diffy-0.3.0 \
		digest-0.10.7 \
		dirs-next-2.0.0 \
		dirs-sys-next-0.1.2 \
		doc-comment-0.3.3 \
		dyn-clone-1.0.17 \
		either-1.13.0 \
		ena-0.14.3 \
		encode_unicode-0.3.6 \
		encoding_rs-0.8.34 \
		env_filter-0.1.2 \
		env_logger-0.11.5 \
		equivalent-1.0.1 \
		errno-0.3.9 \
		event-listener-5.3.1 \
		event-listener-strategy-0.5.2 \
		fastrand-2.1.0 \
		fixedbitset-0.4.2 \
		flate2-1.0.31 \
		fnv-1.0.7 \
		foreign-types-0.3.2 \
		foreign-types-shared-0.1.1 \
		form_urlencoded-1.2.1 \
		funty-2.0.0 \
		futures-0.3.30 \
		futures-channel-0.3.31 \
		futures-core-0.3.31 \
		futures-executor-0.3.30 \
		futures-io-0.3.31 \
		futures-macro-0.3.31 \
		futures-sink-0.3.31 \
		futures-task-0.3.31 \
		futures-timer-3.0.3 \
		futures-util-0.3.31 \
		genco-0.17.9 \
		genco-macros-0.17.9 \
		generic-array-0.14.7 \
		getopts-0.2.21 \
		getrandom-0.2.15 \
		gimli-0.29.0 \
		glob-0.3.1 \
		globset-0.4.14 \
		globwalk-0.9.1 \
		good_lp-1.8.1 \
		governor-0.7.0 \
		h2-0.4.5 \
		hashbrown-0.12.3 \
		hashbrown-0.13.2 \
		hashbrown-0.14.5 \
		heck-0.4.1 \
		heck-0.5.0 \
		hermit-abi-0.3.9 \
		hex-0.4.3 \
		hmac-0.12.1 \
		http-1.1.0 \
		http-body-1.0.1 \
		http-body-util-0.1.2 \
		httparse-1.9.4 \
		humantime-2.1.0 \
		hyper-1.4.1 \
		hyper-rustls-0.27.2 \
		hyper-tls-0.6.0 \
		hyper-util-0.1.7 \
		id-arena-2.2.1 \
		idna-0.5.0 \
		ignore-0.4.22 \
		impl-trait-for-tuples-0.2.2 \
		indent-0.1.1 \
		indexmap-1.9.3 \
		indexmap-2.3.0 \
		indicatif-0.17.8 \
		indoc-2.0.5 \
		inout-0.1.3 \
		instant-0.1.13 \
		ipnet-2.9.0 \
		is_terminal_polyfill-1.70.1 \
		itertools-0.10.5 \
		itertools-0.11.0 \
		itertools-0.12.1 \
		itoa-1.0.11 \
		jobserver-0.1.32 \
		jod-thread-0.1.2 \
		js-sys-0.3.69 \
		keccak-0.1.5 \
		lalrpop-0.20.2 \
		lalrpop-util-0.20.2 \
		lambdaworks-crypto-0.7.0 \
		lambdaworks-math-0.7.0 \
		lazy_static-1.5.0 \
		libc-0.2.155 \
		libredox-0.1.3 \
		linkme-0.3.31 \
		linkme-impl-0.3.31 \
		linux-raw-sys-0.4.14 \
		lock_api-0.4.12 \
		log-0.4.22 \
		lru-0.12.4 \
		lsp-server-0.7.7 \
		lsp-types-0.95.0 \
		matchers-0.1.0 \
		matrixmultiply-0.2.4 \
		memchr-2.7.4 \
		mime-0.3.17 \
		minilp-0.2.2 \
		minimal-lexical-0.2.1 \
		miniz_oxide-0.7.4 \
		mio-1.0.1 \
		native-tls-0.2.12 \
		ndarray-0.13.1 \
		new_debug_unreachable-1.0.6 \
		no-std-compat-0.4.1 \
		nom-7.1.3 \
		nonzero_ext-0.3.0 \
		nu-ansi-term-0.46.0 \
		num-bigint-0.4.6 \
		num-complex-0.2.4 \
		num-conv-0.1.0 \
		num-integer-0.1.46 \
		num-modular-0.5.1 \
		num-prime-0.4.4 \
		num-traits-0.1.43 \
		num-traits-0.2.19 \
		num_threads-0.1.7 \
		number_prefix-0.4.0 \
		object-0.36.3 \
		once_cell-1.19.0 \
		oorandom-11.1.4 \
		openssl-0.10.66 \
		openssl-macros-0.1.1 \
		openssl-probe-0.1.5 \
		openssl-src-300.3.1+3.3.1 \
		openssl-sys-0.9.103 \
		overload-0.1.1 \
		parity-scale-codec-3.6.12 \
		parity-scale-codec-derive-3.6.12 \
		parking-2.2.0 \
		parking_lot-0.12.3 \
		parking_lot_core-0.9.10 \
		password-hash-0.4.2 \
		paste-1.0.15 \
		path-clean-1.0.1 \
		pathdiff-0.2.1 \
		pbkdf2-0.11.0 \
		percent-encoding-2.3.1 \
		petgraph-0.6.5 \
		phf_shared-0.10.0 \
		pico-args-0.5.0 \
		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 \
		precomputed-hash-0.1.1 \
		predicates-3.1.2 \
		predicates-core-1.0.8 \
		predicates-tree-1.0.11 \
		pretty_assertions-1.4.0 \
		proc-macro-crate-3.1.0 \
		proc-macro2-1.0.86 \
		pulldown-cmark-0.12.2 \
		pulldown-cmark-escape-0.11.0 \
		quanta-0.12.3 \
		quote-1.0.36 \
		radium-0.7.0 \
		rand-0.8.5 \
		rand_chacha-0.3.1 \
		rand_core-0.6.4 \
		raw-cpuid-11.2.0 \
		rawpointer-0.2.1 \
		rayon-1.10.0 \
		rayon-core-1.12.1 \
		redox_syscall-0.5.3 \
		redox_users-0.4.5 \
		regex-1.11.0 \
		regex-automata-0.1.10 \
		regex-automata-0.4.8 \
		regex-syntax-0.6.29 \
		regex-syntax-0.8.5 \
		relative-path-1.9.3 \
		reqwest-0.12.5 \
		rfc6979-0.4.0 \
		ring-0.17.8 \
		rstest-0.19.0 \
		rstest_macros-0.19.0 \
		rust-analyzer-salsa-0.17.0-pre.6 \
		rust-analyzer-salsa-macros-0.17.0-pre.6 \
		rust_decimal-1.35.0 \
		rustc-demangle-0.1.24 \
		rustc-hash-1.1.0 \
		rustc_version-0.4.0 \
		rustix-0.38.34 \
		rustls-0.23.12 \
		rustls-pemfile-2.1.3 \
		rustls-pki-types-1.8.0 \
		rustls-webpki-0.102.6 \
		rustversion-1.0.17 \
		ryu-1.0.18 \
		same-file-1.0.6 \
		scarb-metadata-1.13.0 \
		scarb-proc-macro-server-types-0.1.0 \
		scarb-stable-hash-1.0.0 \
		schannel-0.1.23 \
		schemars-0.8.21 \
		schemars_derive-0.8.21 \
		scopeguard-1.2.0 \
		security-framework-2.11.1 \
		security-framework-sys-2.11.1 \
		semver-1.0.23 \
		serde-1.0.204 \
		serde_derive-1.0.204 \
		serde_derive_internals-0.29.1 \
		serde_json-1.0.122 \
		serde_repr-0.1.19 \
		serde_spanned-0.6.7 \
		serde_urlencoded-0.7.1 \
		sha1-0.10.6 \
		sha2-0.10.8 \
		sha3-0.10.8 \
		sharded-slab-0.1.7 \
		signal-hook-registry-1.4.2 \
		siphasher-0.3.11 \
		slab-0.4.9 \
		smallvec-1.13.2 \
		smol_str-0.2.2 \
		socket2-0.5.7 \
		spin-0.9.8 \
		spinning_top-0.3.0 \
		sprs-0.7.1 \
		stable_deref_trait-1.2.0 \
		starknet-crypto-0.6.2 \
		starknet-crypto-codegen-0.3.3 \
		starknet-curve-0.4.2 \
		starknet-ff-0.3.7 \
		starknet-types-core-0.1.5 \
		string_cache-0.8.7 \
		strsim-0.11.1 \
		subtle-2.6.1 \
		syn-1.0.109 \
		syn-2.0.72 \
		sync_wrapper-1.0.1 \
		system-configuration-0.5.1 \
		system-configuration-sys-0.5.0 \
		tap-1.0.1 \
		tempfile-3.12.0 \
		term-0.7.0 \
		termtree-0.4.1 \
		test-case-3.3.1 \
		test-case-core-3.3.1 \
		test-case-macros-3.3.1 \
		test-log-0.2.16 \
		test-log-macros-0.2.16 \
		thiserror-1.0.63 \
		thiserror-impl-1.0.63 \
		thiserror-impl-no-std-2.0.2 \
		thiserror-no-std-2.0.2 \
		thread_local-1.1.8 \
		time-0.3.36 \
		time-core-0.1.2 \
		time-macros-0.2.18 \
		tiny-keccak-2.0.2 \
		tinyvec-1.8.0 \
		tinyvec_macros-0.1.1 \
		tokio-1.39.2 \
		tokio-macros-2.4.0 \
		tokio-native-tls-0.3.1 \
		tokio-rustls-0.26.0 \
		tokio-util-0.7.11 \
		toml-0.8.19 \
		toml_datetime-0.6.8 \
		toml_edit-0.21.1 \
		toml_edit-0.22.20 \
		tower-0.4.13 \
		tower-layer-0.3.2 \
		tower-service-0.3.2 \
		tracing-0.1.40 \
		tracing-attributes-0.1.27 \
		tracing-chrome-0.7.2 \
		tracing-core-0.1.32 \
		tracing-log-0.2.0 \
		tracing-subscriber-0.3.18 \
		triomphe-0.1.14 \
		try-lock-0.2.5 \
		typenum-1.17.0 \
		unescaper-0.1.5 \
		unicase-2.8.0 \
		unicode-bidi-0.3.15 \
		unicode-ident-1.0.12 \
		unicode-normalization-0.1.23 \
		unicode-segmentation-1.11.0 \
		unicode-width-0.1.13 \
		unicode-xid-0.2.4 \
		untrusted-0.9.0 \
		url-2.5.2 \
		utf8parse-0.2.2 \
		valuable-0.1.0 \
		vcpkg-0.2.15 \
		version_check-0.9.5 \
		virtue-0.0.13 \
		walkdir-2.5.0 \
		want-0.3.1 \
		wasi-0.11.0+wasi-snapshot-preview1 \
		wasm-bindgen-0.2.92 \
		wasm-bindgen-backend-0.2.92 \
		wasm-bindgen-futures-0.4.42 \
		wasm-bindgen-macro-0.2.92 \
		wasm-bindgen-macro-support-0.2.92 \
		wasm-bindgen-shared-0.2.92 \
		web-sys-0.3.69 \
		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.52.0 \
		wyz-0.5.1 \
		xshell-0.2.6 \
		xshell-macros-0.2.6 \
		xxhash-rust-0.8.12 \
		yansi-0.5.1 \
		zerocopy-0.7.35 \
		zerocopy-derive-0.7.35 \
		zeroize-1.8.1 \
		zeroize_derive-1.4.2 \
		zip-0.6.6 \
		zstd-0.11.2+zstd.1.5.2 \
		zstd-safe-5.0.2+zstd.1.5.2 \
		zstd-sys-2.0.13+zstd.1.5.6

OPENSSLINC=	/usr/include
OPENSSLLIB=	/usr/lib

PLIST_FILES=	bin/cairo-compile bin/cairo-format bin/cairo-language-server bin/cairo-run bin/cairo-test \
		bin/generate-syntax bin/sierra-compile bin/starknet-compile bin/starknet-sierra-compile

do-install: # workaround for error: found a virtual manifest at `/usr/ports/lang/cairo/work/cairo-2.0.1/Cargo.toml` instead of a package manifest
	# executables
.for e in ${PLIST_FILES:S/bin\///}
	${INSTALL_PROGRAM} ${WRKDIR}/target/release/${e} ${STAGEDIR}${PREFIX}/bin
.endfor
	# corelib
	${MKDIR} ${STAGEDIR}${PREFIX}/lib/cairo-lang
	cd ${WRKSRC} && ${COPYTREE_SHARE} corelib ${STAGEDIR}${PREFIX}/lib/cairo-lang

do-test: install # quick tests
	${PREFIX}/bin/cairo-run --single-file ${FILESDIR}/hello_world.cairo
	${PREFIX}/bin/cairo-run --single-file ${FILESDIR}/op_overloading.cairo

# https://github.com/lambdaclass/cairo-by-example/issues/119: How to run the testsuite?

.include <bsd.port.mk>
