diff --git a/README.md b/README.md index d35dc9c6dbb..057a50a39af 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ Some examples (assume `nixpkgs` had the overlay applied): }; } ``` +- See more examples in directory `examples`. For more details, see also the source code of `./rust-overlay.nix`. diff --git a/examples/cross-aarch64/.cargo/config b/examples/cross-aarch64/.cargo/config new file mode 100644 index 00000000000..62b7477c0b5 --- /dev/null +++ b/examples/cross-aarch64/.cargo/config @@ -0,0 +1,3 @@ +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-unknown-linux-gnu-gcc" +runner = "qemu-aarch64" diff --git a/examples/cross-aarch64/Cargo.lock b/examples/cross-aarch64/Cargo.lock new file mode 100644 index 00000000000..cd0a92ffdbb --- /dev/null +++ b/examples/cross-aarch64/Cargo.lock @@ -0,0 +1,98 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "cc" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cross-aarch64" +version = "0.1.0" +dependencies = [ + "openssl", +] + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3" + +[[package]] +name = "openssl" +version = "0.10.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + +[[package]] +name = "openssl-sys" +version = "0.9.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] +name = "vcpkg" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" diff --git a/examples/cross-aarch64/Cargo.toml b/examples/cross-aarch64/Cargo.toml new file mode 100644 index 00000000000..58a1dafcdd1 --- /dev/null +++ b/examples/cross-aarch64/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "cross-aarch64" +version = "0.1.0" +edition = "2018" + +[dependencies] +openssl = "0.10.32" diff --git a/examples/cross-aarch64/Makefile b/examples/cross-aarch64/Makefile new file mode 100644 index 00000000000..8204d2af784 --- /dev/null +++ b/examples/cross-aarch64/Makefile @@ -0,0 +1,9 @@ +.PHONY: all test + +test: all + nix-shell ./shell.nix --command \ + "cargo test --target aarch64-unknown-linux-gnu" + +all: Cargo.toml Cargo.lock src/main.rs + nix-shell ./shell.nix --command \ + "cargo test --target aarch64-unknown-linux-gnu --no-run" diff --git a/examples/cross-aarch64/shell.nix b/examples/cross-aarch64/shell.nix new file mode 100644 index 00000000000..bf24aa13350 --- /dev/null +++ b/examples/cross-aarch64/shell.nix @@ -0,0 +1,18 @@ +with import { + crossSystem = "aarch64-linux"; + overlays = [ (import ../..) ]; +}; +mkShell { + nativeBuildInputs = [ + # Manual `buildPackages` is required here. See: https://github.com/NixOS/nixpkgs/issues/49526 + # build = host = x86_64, target = aarch64 + buildPackages.rust-bin.stable.latest.rust + buildPackages.pkg-config + # build = host = target = x86_64, just to avoid re-build. + pkgsBuildBuild.qemu + ]; + buildInputs = [ + # build = x86_64, host = target = aarch64 + openssl + ]; +} diff --git a/examples/cross-aarch64/src/main.rs b/examples/cross-aarch64/src/main.rs new file mode 100644 index 00000000000..967680f4087 --- /dev/null +++ b/examples/cross-aarch64/src/main.rs @@ -0,0 +1,7 @@ +#[test] +fn test_openssl_version() { + openssl::init(); + assert!(openssl::version::version().starts_with("OpenSSL ")); +} + +fn main() {}