spack/lib.rs
1/* Copyright 2022-2023 Danny McClanahan */
2/* SPDX-License-Identifier: (Apache-2.0 OR MIT) */
3
4//! Rust wrappers for [`spack`]. For use in [build scripts].
5//!
6//! [`spack`]: https://github.com/spack/spack
7//! [build scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
8
9#![deny(unsafe_code)]
10// Turn all warnings into errors!
11// #![deny(warnings)]
12// Warn for missing docs in general, and hard require crate-level docs.
13// #![warn(missing_docs)]
14#![warn(rustdoc::missing_crate_level_docs)]
15/* Make all doctests fail if they produce any warnings. */
16#![doc(test(attr(deny(warnings))))]
17
18pub mod commands;
19mod lock;
20pub mod metadata_spec;
21pub mod subprocess;
22pub mod summoning;
23pub mod utils;
24
25pub use subprocess::spack::SpackInvocation;
26
27use displaydoc::Display;
28use thiserror::Error;
29
30/// Constants defining available versions of spack.
31///
32/// Currently, this crate avoids maintaining a git repository (the typical way
33/// spack is distributed) in favor of a checksummed directory corresponding to a
34/// precise spack release. The main reason for this is to enable experimental
35/// support for wasm compilation via emscripten (see the
36/// [`wasm`](crate::utils::wasm) module). Until upstream support for emscripten
37/// is merged, the cached build output in `opt/` may refer to packages which are
38/// unavailable in spack proper, causing an exception when spack is invoked.
39///
40/// Figuring out a nicer way to select a compatible spack version (which also
41/// works across the entire cargo build graph, which may invoke this crate
42/// multiple times) is on the horizon, but until then hardcoding this
43/// information is slightly easier to work with.
44pub mod versions {
45 use hex_literal::hex;
46
47 pub mod patches {
48 use super::hex;
49
50 pub const PATCHES_SPACK_URL: &str =
51 "https://github.com/cosmicexplorer/spack/archive/refs/tags/cargo-patches-v5.tar.gz";
52 pub const PATCHES_SHA256SUM: [u8; 32] =
53 hex!("f63f78227ef477ac3811d8e73aa69ad482aaee66a974fb04a0c43aab6b4119ab");
54 pub const PATCHES_TOPLEVEL_COMPONENT: &str = "spack-cargo-patches-v5";
55 }
56
57 /// The most recently released version of spack.
58 pub mod develop {
59 use super::hex;
60
61 pub const MOST_RECENT_HARDCODED_SPACK_URL: &str =
62 "https://github.com/spack/spack/archive/refs/tags/v0.23.1.tar.gz";
63 pub const MOST_RECENT_HARDCODED_URL_SHA256SUM: [u8; 32] =
64 hex!("32ca622c49448a3b4e398eb1397d8ff9a6aa987a248de621261e24e65f287593");
65 pub const MOST_RECENT_HARDCODED_SPACK_ARCHIVE_TOPLEVEL_COMPONENT: &str = "spack-0.23.1";
66 }
67
68 /// A spack branch with support for emscripten as a compiler, enabling
69 /// compilation to wasm.
70 pub mod emcc {
71 use super::hex;
72
73 pub const EMCC_CAPABLE_SPACK_URL: &str =
74 "https://github.com/cosmicexplorer/spack/archive/refs/tags/v0.20.0.dev0-emcc.tar.gz";
75 pub const EMCC_URL_SHA256SUM: [u8; 32] =
76 hex!("fc45a31f0f98f9a781eae8a58e38c13980addd20302c0a7f32dc084e55ba7f2f");
77 pub const EMCC_SPACK_ARCHIVE_TOPLEVEL_COMPONENT: &str = "spack-0.20.0.dev0-emcc";
78 }
79}
80
81/// Errors that can occur.
82#[derive(Debug, Display, Error)]
83#[ignore_extra_doc_attributes]
84pub enum Error {
85 /// spack summoning error: {0}
86 ///
87 /// This will occur if spack itself cannot be set up.
88 Summoning(#[from] subprocess::spack::InvocationSummoningError),
89 /// spack command failed: {0}
90 SpackCommand(#[from] commands::CommandError),
91}