Skip to content

Commit

Permalink
Revert "Set the location of the zip via environment variable"
Browse files Browse the repository at this point in the history
This reverts commit c5ad832.
  • Loading branch information
AlexWaygood committed Jun 7, 2024
1 parent c5ad832 commit a5f2bcb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
6 changes: 0 additions & 6 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,3 @@ benchmark = "bench -p ruff_benchmark --bench linter --bench formatter --"
# See: https://github.com/astral-sh/ruff/issues/11503
[target.'cfg(all(target_env="msvc", target_os = "windows"))']
rustflags = ["-C", "target-feature=+crt-static"]

[env]
# Location for where to put the zip containing our vendored typeshed stubs
# that the red-knot crate creates at build time.
# The location is relative to the `OUT_DIR` environment variable that cargo sets.
RUFF_VENDORED_TYPESHED_ZIP = "/vendored_typeshed.zip"
6 changes: 2 additions & 4 deletions crates/red_knot/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use zip::write::{FileOptions, ZipWriter};
use zip::CompressionMethod;

const TYPESHED_SOURCE_DIR: &str = "vendor/typeshed";
const TYPESHED_ZIP_LOCATION: &str = "zipped_typeshed.zip";

/// Recursively zip the contents of an entire directory.
///
Expand Down Expand Up @@ -59,16 +60,13 @@ fn main() {
);
let out_dir = std::env::var("OUT_DIR").unwrap();

// This environment variable is set in `.cargo/config.toml`
let typeshed_destination = std::env::var("RUFF_VENDORED_TYPESHED_ZIP").unwrap();

// N.B. Deliberately using `format!()` instead of `Path::join()` here,
// so that we use `/` as a path separator on all platforms.
// That enables us to load the typeshed zip at compile time in `module.rs`
// (otherwise we'd have to dynamically determine the exact path to the typeshed zip
// based on the default path separator for the specific platform we're on,
// which can't be done at compile time.)
let zipped_typeshed_location = format!("{out_dir}{typeshed_destination}");
let zipped_typeshed_location = format!("{out_dir}/{TYPESHED_ZIP_LOCATION}");

let zipped_typeshed = File::create(zipped_typeshed_location).unwrap();
zip_dir(TYPESHED_SOURCE_DIR, zipped_typeshed).unwrap();
Expand Down
5 changes: 3 additions & 2 deletions crates/red_knot/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,10 @@ mod tests {

#[test]
fn typeshed_zip_created_at_build_time() -> anyhow::Result<()> {
// The RUFF_VENDORED_TYPESHED_ZIP environment variable is set in `.cargo/config.toml`
// The file path here is hardcoded in this crate's `build.rs` script.
// Luckily this crate will fail to build if this file isn't available at build time.
const TYPESHED_ZIP_BYTES: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), env!("RUFF_VENDORED_TYPESHED_ZIP")));
include_bytes!(concat!(env!("OUT_DIR"), "/zipped_typeshed.zip"));
assert!(!TYPESHED_ZIP_BYTES.is_empty());
let mut typeshed_zip_archive = ZipArchive::new(Cursor::new(TYPESHED_ZIP_BYTES))?;

Expand Down

0 comments on commit a5f2bcb

Please sign in to comment.