SUMMARY="A tool for generating C binding to Rust code"
DESCRIPTION="cbindgen creates C/C++11 headers \
for Rust libraries which expose a public C API."
HOMEPAGE="https://github.com/eqrion/cbindgen"
COPYRIGHT="2018-2021 cbindgen contributors"
LICENSE="MPL v2.0"
REVISION="1"
SOURCE_URI="$HOMEPAGE/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="70f810d2b9e5a2db570431872c26377813fb27a63d817cb16b2d69fa3741d066"
SOURCE_FILENAME="cbindgen-$portVersion.tar.gz"

SOURCE_URI_2="https://static.crates.io/crates/proc-macro2/proc-macro2-1.0.21.crate"
CHECKSUM_SHA256_2="36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"

SOURCE_URI_3="https://static.crates.io/crates/libc/libc-0.2.77.crate"
CHECKSUM_SHA256_3="f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"

SOURCE_URI_4="https://static.crates.io/crates/syn/syn-1.0.41.crate"
CHECKSUM_SHA256_4="6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"

SOURCE_URI_5="https://static.crates.io/crates/unicode-xid/unicode-xid-0.2.1.crate"
CHECKSUM_SHA256_5="f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"

SOURCE_URI_6="https://static.crates.io/crates/cfg-if/cfg-if-0.1.10.crate"
CHECKSUM_SHA256_6="4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"

SOURCE_URI_7="https://static.crates.io/crates/serde_derive/serde_derive-1.0.116.crate"
CHECKSUM_SHA256_7="f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8"

SOURCE_URI_8="https://static.crates.io/crates/serde/serde-1.0.116.crate"
CHECKSUM_SHA256_8="96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5"

SOURCE_URI_9="https://static.crates.io/crates/autocfg/autocfg-1.0.1.crate"
CHECKSUM_SHA256_9="cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"

SOURCE_URI_10="https://static.crates.io/crates/ryu/ryu-1.0.5.crate"
CHECKSUM_SHA256_10="71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"

SOURCE_URI_11="https://static.crates.io/crates/ppv-lite86/ppv-lite86-0.2.9.crate"
CHECKSUM_SHA256_11="c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"

SOURCE_URI_12="https://static.crates.io/crates/serde_json/serde_json-1.0.57.crate"
CHECKSUM_SHA256_12="164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"

SOURCE_URI_13="https://static.crates.io/crates/unicode-width/unicode-width-0.1.8.crate"
CHECKSUM_SHA256_13="9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"

SOURCE_URI_14="https://static.crates.io/crates/log/log-0.4.11.crate"
CHECKSUM_SHA256_14="4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"

SOURCE_URI_15="https://static.crates.io/crates/itoa/itoa-0.4.6.crate"
CHECKSUM_SHA256_15="dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"

SOURCE_URI_16="https://static.crates.io/crates/ansi_term/ansi_term-0.11.0.crate"
CHECKSUM_SHA256_16="ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"

SOURCE_URI_17="https://static.crates.io/crates/bitflags/bitflags-1.2.1.crate"
CHECKSUM_SHA256_17="cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"

SOURCE_URI_18="https://static.crates.io/crates/hashbrown/hashbrown-0.9.1.crate"
CHECKSUM_SHA256_18="d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"

SOURCE_URI_19="https://static.crates.io/crates/strsim/strsim-0.8.0.crate"
CHECKSUM_SHA256_19="8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"

SOURCE_URI_20="https://static.crates.io/crates/remove_dir_all/remove_dir_all-0.5.3.crate"
CHECKSUM_SHA256_20="3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"

SOURCE_URI_21="https://static.crates.io/crates/unicode-segmentation/unicode-segmentation-1.6.0.crate"
CHECKSUM_SHA256_21="e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"

SOURCE_URI_22="https://static.crates.io/crates/vec_map/vec_map-0.8.2.crate"
CHECKSUM_SHA256_22="f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"

SOURCE_URI_23="https://static.crates.io/crates/indexmap/indexmap-1.6.0.crate"
CHECKSUM_SHA256_23="55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"

SOURCE_URI_24="https://static.crates.io/crates/textwrap/textwrap-0.11.0.crate"
CHECKSUM_SHA256_24="d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"

SOURCE_URI_25="https://static.crates.io/crates/heck/heck-0.3.3.crate"
CHECKSUM_SHA256_25="6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"

SOURCE_URI_26="https://static.crates.io/crates/quote/quote-1.0.7.crate"
CHECKSUM_SHA256_26="aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"

SOURCE_URI_27="https://static.crates.io/crates/getrandom/getrandom-0.1.15.crate"
CHECKSUM_SHA256_27="fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"

SOURCE_URI_28="https://static.crates.io/crates/atty/atty-0.2.14.crate"
CHECKSUM_SHA256_28="d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"

SOURCE_URI_29="https://static.crates.io/crates/rand_core/rand_core-0.5.1.crate"
CHECKSUM_SHA256_29="90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"

SOURCE_URI_30="https://static.crates.io/crates/clap/clap-2.33.3.crate"
CHECKSUM_SHA256_30="37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"

SOURCE_URI_31="https://static.crates.io/crates/rand_chacha/rand_chacha-0.2.2.crate"
CHECKSUM_SHA256_31="f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"

SOURCE_URI_32="https://static.crates.io/crates/rand/rand-0.7.3.crate"
CHECKSUM_SHA256_32="6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"

SOURCE_URI_33="https://static.crates.io/crates/tempfile/tempfile-3.1.0.crate"
CHECKSUM_SHA256_33="7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"

SOURCE_URI_34="https://static.crates.io/crates/toml/toml-0.5.6.crate"
CHECKSUM_SHA256_34="ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"

SOURCE_URI_35="https://static.crates.io/crates/heck/heck-0.3.1.crate"
CHECKSUM_SHA256_35="20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"

SOURCE_URI_36="https://static.crates.io/crates/serial_test/serial_test-0.5.0.crate"
CHECKSUM_SHA256_36="1b15f74add9a9d4a3eb2bf739c9a427d266d3895b53d992c3a7c234fec2ff1f1"

SOURCE_URI_37="https://static.crates.io/crates/redox_syscall/redox_syscall-0.1.57.crate"
CHECKSUM_SHA256_37="41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"

SOURCE_URI_38="https://static.crates.io/crates/winapi/winapi-0.3.9.crate"
CHECKSUM_SHA256_38="5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"

SOURCE_URI_39="https://static.crates.io/crates/lazy_static/lazy_static-1.4.0.crate"
CHECKSUM_SHA256_39="e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"

SOURCE_URI_40="https://static.crates.io/crates/parking_lot/parking_lot-0.10.2.crate"
CHECKSUM_SHA256_40="d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"

SOURCE_URI_41="https://static.crates.io/crates/serial_test_derive/serial_test_derive-0.5.0.crate"
CHECKSUM_SHA256_41="65f59259be9fc1bf677d06cc1456e97756004a1a5a577480f71430bd7c17ba33"

SOURCE_URI_42="https://static.crates.io/crates/hermit-abi/hermit-abi-0.1.16.crate"
CHECKSUM_SHA256_42="4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151"

SOURCE_URI_43="https://static.crates.io/crates/rand_hc/rand_hc-0.2.0.crate"
CHECKSUM_SHA256_43="ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"

SOURCE_URI_44="https://static.crates.io/crates/winapi-x86_64-pc-windows-gnu/winapi-x86_64-pc-windows-gnu-0.4.0.crate"
CHECKSUM_SHA256_44="712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

SOURCE_URI_45="https://static.crates.io/crates/winapi-i686-pc-windows-gnu/winapi-i686-pc-windows-gnu-0.4.0.crate"
CHECKSUM_SHA256_45="ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"

SOURCE_URI_46="https://static.crates.io/crates/lock_api/lock_api-0.3.4.crate"
CHECKSUM_SHA256_46="c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"

SOURCE_URI_47="https://static.crates.io/crates/parking_lot_core/parking_lot_core-0.7.2.crate"
CHECKSUM_SHA256_47="d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"

SOURCE_URI_48="https://static.crates.io/crates/wasi/wasi-0.9.0+wasi-snapshot-preview1.crate"
CHECKSUM_SHA256_48="cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"

SOURCE_URI_49="https://static.crates.io/crates/scopeguard/scopeguard-1.1.0.crate"
CHECKSUM_SHA256_49="d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"

SOURCE_URI_50="https://static.crates.io/crates/smallvec/smallvec-1.4.2.crate"
CHECKSUM_SHA256_50="fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"

SOURCE_URI_51="https://static.crates.io/crates/cloudabi/cloudabi-0.0.3.crate"
CHECKSUM_SHA256_51="ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"


ARCHITECTURES="all !x86_gcc2 ?x86"
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
commandBinDir=$prefix/bin
fi

PROVIDES="
	cbindgen$secondaryArchSuffix = $portVersion
	cmd:cbindgen
	"

REQUIRES="
	haiku$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cargo$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	"

defineDebugInfoPackage cbindgen$secondaryArchSuffix \
	"$commandBinDir"/cbindgen

BUILD()
{
	export CARGO_HOME=$sourceDir/../cargo
	vendor=$CARGO_HOME/haiku
	mkdir -p "$vendor"
	for i in $(seq 2 51); do
		eval "srcDir=\$sourceDir$i"
		eval "sha256sum=\$CHECKSUM_SHA256_$i"
		set -- "$srcDir"/*
		ln -sf "$1" "$vendor"
		cat <<-EOF >"$vendor/${1##*/}/.cargo-checksum.json"
		{
		  "package": "$sha256sum",
		  "files": {}
		}
		EOF
	done

	cat <<-EOF >"$CARGO_HOME"/config
	[source.haiku]
	directory = "$vendor"

	[source.crates-io]
	replace-with = "haiku"
	EOF

	cargo build --release --frozen
}

INSTALL()
{
	install -m 755 -d "$commandBinDir" "$docDir"
	install -m 755 target/release/cbindgen "$commandBinDir"
	install -m 644 README.md "$docDir"
}

TEST()
{
	export CARGO_HOME=$sourceDir/../cargo
	cargo test --release --frozen
}
