blob: 6c9d22d8104029c1a18201e1e12eebf589c4b7d2 [file] [log] [blame]
David Tolnay65b66f22020-10-11 02:34:08 -07001use std::io::{self, Write};
David Tolnayc9c197b2020-10-11 02:48:15 -07002#[cfg(windows)]
3use std::os::windows::fs as windows;
David Tolnay65b66f22020-10-11 02:34:08 -07004use std::path::Path;
5use std::process;
David Tolnayc9c197b2020-10-11 02:48:15 -07006#[cfg(windows)]
7use std::{env, fs};
David Tolnay65b66f22020-10-11 02:34:08 -07008
David Tolnayc9c197b2020-10-11 02:48:15 -07009const MISSING: &str = "
David Tolnay65b66f22020-10-11 02:34:08 -070010~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11When building `cxx` from a git clone, git's symlink support needs
12to be enabled on platforms that have it off by default (Windows).
13Either use:
14
15 $ git config --global core.symlinks true
16
17prior to cloning, or else use:
18
David Tolnay188d9f12020-10-11 02:37:51 -070019 $ git clone -c core.symlinks=true https://github.com/dtolnay/cxx
David Tolnay65b66f22020-10-11 02:34:08 -070020
21for the clone.
22
David Tolnaya0002192020-10-11 03:10:19 -070023Symlinks are only required when compiling locally from a clone of
24the git repository---they are NOT required when building `cxx` as
25a Cargo-managed (possibly transitive) build dependency downloaded
26through crates.io.
David Tolnay65b66f22020-10-11 02:34:08 -070027~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28";
29
David Tolnayc9c197b2020-10-11 02:48:15 -070030#[cfg(windows)]
31const DENIED: &str = "
32~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33When building `cxx` from a git clone on Windows we need Developer
34Mode enabled for symlink support.
35
36To enable Developer Mode: go under Settings to Update & Security,
37then 'For developers', and turn on the toggle for Developer Mode.
38
39For more explanation of symlinks in Windows, see these resources:
40> https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
41> https://docs.microsoft.com/windows/uwp/get-started/enable-your-device-for-development
42
43Symlinks are only required when compiling locally from a clone of
44the git repository---they are NOT required when building `cxx` as
45a Cargo-managed (possibly transitive) build dependency downloaded
46through crates.io.
47~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48";
49
David Tolnay65b66f22020-10-11 02:34:08 -070050fn main() {
David Tolnayc9c197b2020-10-11 02:48:15 -070051 if Path::new("src/syntax/mod.rs").exists() {
52 return;
David Tolnay65b66f22020-10-11 02:34:08 -070053 }
David Tolnayc9c197b2020-10-11 02:48:15 -070054
55 #[allow(unused_mut)]
56 let mut message = MISSING;
57
58 #[cfg(windows)]
59 if let Some(out_dir) = env::var_os("OUT_DIR") {
60 let parent_dir = Path::new(&out_dir).join("symlink");
61 let from_dir = parent_dir.join("from");
62 let to_dir = parent_dir.join("to");
63 if fs::create_dir_all(&from_dir).is_ok()
Jan Haller595ac272020-10-13 22:48:08 +020064 && fs::remove_dir(&to_dir).is_ok()
David Tolnayc9c197b2020-10-11 02:48:15 -070065 && windows::symlink_dir(&from_dir, &to_dir).is_err()
66 {
67 message = DENIED;
68 }
69 }
70
71 let _ = io::stderr().write_all(message.as_bytes());
72 process::exit(1);
David Tolnay65b66f22020-10-11 02:34:08 -070073}