| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 1 | use std::io::{self, Write}; |
| David Tolnay | c9c197b | 2020-10-11 02:48:15 -0700 | [diff] [blame] | 2 | #[cfg(windows)] |
| 3 | use std::os::windows::fs as windows; |
| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 4 | use std::path::Path; |
| 5 | use std::process; |
| David Tolnay | c9c197b | 2020-10-11 02:48:15 -0700 | [diff] [blame] | 6 | #[cfg(windows)] |
| 7 | use std::{env, fs}; |
| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 8 | |
| David Tolnay | c9c197b | 2020-10-11 02:48:15 -0700 | [diff] [blame] | 9 | const MISSING: &str = " |
| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 10 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | When building `cxx` from a git clone, git's symlink support needs |
| 12 | to be enabled on platforms that have it off by default (Windows). |
| 13 | Either use: |
| 14 | |
| 15 | $ git config --global core.symlinks true |
| 16 | |
| 17 | prior to cloning, or else use: |
| 18 | |
| David Tolnay | 188d9f1 | 2020-10-11 02:37:51 -0700 | [diff] [blame] | 19 | $ git clone -c core.symlinks=true https://github.com/dtolnay/cxx |
| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 20 | |
| 21 | for the clone. |
| 22 | |
| David Tolnay | a000219 | 2020-10-11 03:10:19 -0700 | [diff] [blame] | 23 | Symlinks are only required when compiling locally from a clone of |
| 24 | the git repository---they are NOT required when building `cxx` as |
| 25 | a Cargo-managed (possibly transitive) build dependency downloaded |
| 26 | through crates.io. |
| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 28 | "; |
| 29 | |
| David Tolnay | c9c197b | 2020-10-11 02:48:15 -0700 | [diff] [blame] | 30 | #[cfg(windows)] |
| 31 | const DENIED: &str = " |
| 32 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 33 | When building `cxx` from a git clone on Windows we need Developer |
| 34 | Mode enabled for symlink support. |
| 35 | |
| 36 | To enable Developer Mode: go under Settings to Update & Security, |
| 37 | then 'For developers', and turn on the toggle for Developer Mode. |
| 38 | |
| 39 | For 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 | |
| 43 | Symlinks are only required when compiling locally from a clone of |
| 44 | the git repository---they are NOT required when building `cxx` as |
| 45 | a Cargo-managed (possibly transitive) build dependency downloaded |
| 46 | through crates.io. |
| 47 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 48 | "; |
| 49 | |
| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 50 | fn main() { |
| David Tolnay | c9c197b | 2020-10-11 02:48:15 -0700 | [diff] [blame] | 51 | if Path::new("src/syntax/mod.rs").exists() { |
| 52 | return; |
| David Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 53 | } |
| David Tolnay | c9c197b | 2020-10-11 02:48:15 -0700 | [diff] [blame] | 54 | |
| 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 Haller | 595ac27 | 2020-10-13 22:48:08 +0200 | [diff] [blame] | 64 | && fs::remove_dir(&to_dir).is_ok() |
| David Tolnay | c9c197b | 2020-10-11 02:48:15 -0700 | [diff] [blame] | 65 | && 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 Tolnay | 65b66f2 | 2020-10-11 02:34:08 -0700 | [diff] [blame] | 73 | } |