Skip to content

Visual Studio Code, rebuilt in Rust

Rust
1.1 KB
Raw Blame
// The VS Code tree the port reads (milestone 22): $VSCODE_SRC (relative to the repo root), else upstream/.
// Included by the build scripts of app, diff, exthost and files, which export it as env!("VSCODE_SRC");
// port/tools/vscode-src.sh and port/tools/vscode-src.ts resolve it the same way.
fn emit_vscode_src() -> std::path::PathBuf {
    println!("cargo::rerun-if-env-changed=VSCODE_SRC");
    let repo = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../..");
    let src = repo.join(std::env::var_os("VSCODE_SRC").unwrap_or_else(|| "upstream".into()));
    let src = src.canonicalize().unwrap_or_else(|error| panic!("VSCODE_SRC {}: {error} (README.md: clone VS Code into upstream/)", src.display()));
    // Windows canonicalizes to `\\?\C:\...`, where the `/` of include_str!(concat!(env!("VSCODE_SRC"), "/src/...")) is no separator.
    let src = match src.to_str().and_then(|path| path.strip_prefix(r"\\?\")) {
        Some(path) => std::path::PathBuf::from(path),
        None => src,
    };
    println!("cargo::rustc-env=VSCODE_SRC={}", src.display());
    src
}