aboutsummaryrefslogtreecommitdiff
path: root/tools/cargo/build.rs
blob: 6c9d22d8104029c1a18201e1e12eebf589c4b7d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::io::{self, Write};
#[cfg(windows)]
use std::os::windows::fs as windows;
use std::path::Path;
use std::process;
#[cfg(windows)]
use std::{env, fs};

const MISSING: &str = "
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When building `cxx` from a git clone, git's symlink support needs
to be enabled on platforms that have it off by default (Windows).
Either use:

   $ git config --global core.symlinks true

prior to cloning, or else use:

   $ git clone -c core.symlinks=true https://github.com/dtolnay/cxx

for the clone.

Symlinks are only required when compiling locally from a clone of
the git repository---they are NOT required when building `cxx` as
a Cargo-managed (possibly transitive) build dependency downloaded
through crates.io.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
";

#[cfg(windows)]
const DENIED: &str = "
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When building `cxx` from a git clone on Windows we need Developer
Mode enabled for symlink support.

To enable Developer Mode: go under Settings to Update & Security,
then 'For developers', and turn on the toggle for Developer Mode.

For more explanation of symlinks in Windows, see these resources:
> https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
> https://docs.microsoft.com/windows/uwp/get-started/enable-your-device-for-development

Symlinks are only required when compiling locally from a clone of
the git repository---they are NOT required when building `cxx` as
a Cargo-managed (possibly transitive) build dependency downloaded
through crates.io.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
";

fn main() {
    if Path::new("src/syntax/mod.rs").exists() {
        return;
    }

    #[allow(unused_mut)]
    let mut message = MISSING;

    #[cfg(windows)]
    if let Some(out_dir) = env::var_os("OUT_DIR") {
        let parent_dir = Path::new(&out_dir).join("symlink");
        let from_dir = parent_dir.join("from");
        let to_dir = parent_dir.join("to");
        if fs::create_dir_all(&from_dir).is_ok()
            && fs::remove_dir(&to_dir).is_ok()
            && windows::symlink_dir(&from_dir, &to_dir).is_err()
        {
            message = DENIED;
        }
    }

    let _ = io::stderr().write_all(message.as_bytes());
    process::exit(1);
}