forked from zed-industries/zed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy
extension_api
Rust files to OUT_DIR
when building `extension…
…` to work around rust-analyzer limitation (zed-industries#16064) Copies rust files from extension_api/wit to the OUT_DIR to allow including them from within the crate, which is supported by rust-analyzer. This allows rust-analyzer to deal with the included files. It doesn't currently support files outside the crate. Release Notes: - N/A
- Loading branch information
1 parent
550e139
commit 6f104fe
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
copy_extension_api_rust_files() | ||
} | ||
|
||
// rust-analyzer doesn't support include! for files from outside the crate. | ||
// Copy them to the OUT_DIR, so we can include them from there, which is supported. | ||
fn copy_extension_api_rust_files() -> Result<(), Box<dyn std::error::Error>> { | ||
let out_dir = env::var("OUT_DIR")?; | ||
let input_dir = PathBuf::from("../extension_api/wit"); | ||
let output_dir = PathBuf::from(out_dir); | ||
|
||
for entry in fs::read_dir(&input_dir)? { | ||
let entry = entry?; | ||
let path = entry.path(); | ||
if path.is_dir() { | ||
for subentry in fs::read_dir(&path)? { | ||
let subentry = subentry?; | ||
let subpath = subentry.path(); | ||
if subpath.extension() == Some(std::ffi::OsStr::new("rs")) { | ||
let relative_path = subpath.strip_prefix(&input_dir)?; | ||
let destination = output_dir.join(relative_path); | ||
|
||
fs::create_dir_all(destination.parent().unwrap())?; | ||
fs::copy(&subpath, &destination)?; | ||
println!("cargo:rerun-if-changed={}", subpath.display()); | ||
} | ||
} | ||
} else if path.extension() == Some(std::ffi::OsStr::new("rs")) { | ||
let relative_path = path.strip_prefix(&input_dir)?; | ||
let destination = output_dir.join(relative_path); | ||
|
||
fs::create_dir_all(destination.parent().unwrap())?; | ||
fs::copy(&path, &destination)?; | ||
println!("cargo:rerun-if-changed={}", path.display()); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters