forked from woelper/oculante
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
150 lines (135 loc) · 4.65 KB
/
build.rs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use std::env;
use std::fs::read_to_string;
use std::fs::remove_file;
use std::fs::File;
use std::io::Read;
use std::io::Write;
use std::path::Path;
#[allow(dead_code)]
fn setup_heif() {
let out_dir = env::var("OUT_DIR").unwrap();
let heif_path = format!("{out_dir}/libheif");
println!("heif is at {heif_path}");
#[cfg(target_os = "linux")]
{
use std::fs::create_dir_all;
use std::fs::remove_dir_all;
use std::process::Command;
_ = remove_dir_all(&heif_path);
// _ = remove_dir_all("libheif");
Command::new("git")
.args(["clone", "git@github.com:strukturag/libheif.git", &heif_path])
.status()
.unwrap();
println!("Creating heif build dir");
create_dir_all(format!("{heif_path}/build")).unwrap();
// Command::new("git")
// .args(["clone", "git@github.com:strukturag/libheif.git", "libheif"])
// .status()
// .unwrap();
// Command::new("cd").args(["libheif"]).status().unwrap();
// Command::new("mkdir").args(["build"]).status().unwrap();
// Command::new("cd").args(["build"]).status().unwrap();
println!("Running cmake / heif");
Command::new("cmake")
.args(["--preset=release", ".."])
.current_dir(format!("{heif_path}/build"))
.status()
.unwrap();
println!("Running make / heif");
Command::new("make")
.current_dir(format!("{heif_path}/build"))
.status()
.unwrap();
Command::new("export")
.args([format!("PKG_CONFIG_PATH={heif_path}/build")])
.current_dir(format!("{heif_path}/build"))
.status()
.unwrap();
println!("cargo:rustc-link-search=native={}/build", heif_path);
// env::set_var("PKG_CONFIG_PATH", format!("{heif_path}/build"));
}
#[cfg(target_os = "windows")]
{
use std::process::Command;
Command::new("git")
.args(["clone", "https://github.com/Microsoft/vcpkg.git"])
.status()
.unwrap();
Command::new("cd").args(["vcpkg"]).status().unwrap();
Command::new("./bootstrap-vcpkg.bat").status().unwrap();
Command::new("./vcpkg")
.args(["integrate", "install"])
.status()
.unwrap();
Command::new("./vcpkg")
.args(["install", "libheif"])
.status()
.unwrap();
}
}
fn main() {
println!("Build script");
// #[cfg(windows)]
match std::process::Command::new("convert")
.args(vec!["res/oculante.png", "icon.ico"])
.spawn()
{
Ok(_b) => println!("Converted icon"),
Err(e) => eprintln!("Error converting icon {:?}. Is imagemagick installed?", e),
}
// insert version into plist
let mut plist: String = "".into();
File::open("res/info.plist")
.unwrap()
.read_to_string(&mut plist)
.unwrap();
File::create("Info.plist")
.unwrap()
.write_all(
plist
.replace("VERSION", env!("CARGO_PKG_VERSION"))
.as_bytes(),
)
.unwrap();
// insert version into AUR PKGBUILD
let mut pkgbuild = String::new();
File::open("res/pkgbuild")
.unwrap()
.read_to_string(&mut pkgbuild)
.unwrap();
File::create("PKGBUILD")
.unwrap()
.write_all(
pkgbuild
.replace("$$VERSION$$", env!("CARGO_PKG_VERSION"))
.as_bytes(),
)
.unwrap();
if cfg!(target_os = "windows") {
let mut res = winres::WindowsResource::new();
res.set_icon("icon.ico");
_ = res.compile();
}
let shortcut_file = "shortcuts.txt";
if Path::new(shortcut_file).is_file() {
let mut readme: String = "".into();
File::open("README.md")
.unwrap()
.read_to_string(&mut readme)
.unwrap();
let readme_wo_keys = readme.split("### Shortcuts:").nth(0).unwrap().to_string();
use std::io::prelude::*;
let shortcuts = read_to_string(shortcut_file).unwrap();
let mouse_keys = "`mouse wheel` = zoom\n\n`left mouse`,`middle mouse` = pan\n\n`ctrl + mouse wheel` = prev/next image in folder\n\n`Right mouse` pick color from image (in paint mode)\n\n";
let new_readme = format!("{readme_wo_keys}### Shortcuts:\n{mouse_keys}\n{shortcuts}");
File::create("README.md")
.unwrap()
.write_all(new_readme.as_bytes())
.unwrap();
remove_file(shortcut_file).unwrap();
}
// #[cfg(feature = "heif")]
// setup_heif();
// panic!();
}