Skip to content

Commit 19feaba

Browse files
committed
Update to the 2018 edition
1 parent fa2ced6 commit 19feaba

13 files changed

+75
-107
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ keywords = ["build-dependencies"]
1515
readme = "README.md"
1616
categories = ["development-tools::build-utils"]
1717
exclude = ["/.travis.yml", "/appveyor.yml"]
18+
edition = "2018"
1819

1920
[dependencies]
2021
num_cpus = { version = "1.10", optional = true }

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ Next up, you'll want to write a build script like so:
2828
```rust,no_run
2929
// build.rs
3030
31-
extern crate cc;
32-
3331
fn main() {
3432
cc::Build::new()
3533
.file("foo.c")
@@ -143,8 +141,6 @@ required varies per platform, but there are three broad categories:
143141
`Build`:
144142

145143
```rust,no_run
146-
extern crate cc;
147-
148144
fn main() {
149145
cc::Build::new()
150146
.cpp(true) // Switch to C++ library compilation.
@@ -163,8 +159,6 @@ linked to the crate target.
163159
on `Build` (currently for GNU/Clang toolchains only):
164160

165161
```rust,no_run
166-
extern crate cc;
167-
168162
fn main() {
169163
cc::Build::new()
170164
// Switch to CUDA C++ library compilation using NVCC.

cc-test/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "cc-test"
33
version = "0.1.0"
44
authors = ["Alex Crichton <[email protected]>"]
5+
edition = "2018"
56

67
[lib]
78
name = "cc_test"

cc-test/build.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate cc;
2-
31
use std::env;
42
use std::fs;
53
use std::path::PathBuf;

cc-test/tests/all.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate cc_test;
2-
31
use cc_test::*;
42

53
#[link(name = "OptLinkage", kind = "static")]

src/com.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use std::ops::Deref;
1313
use std::os::windows::ffi::{OsStrExt, OsStringExt};
1414
use std::ptr::null_mut;
1515
use std::slice::from_raw_parts;
16-
use winapi::CoInitializeEx;
17-
use winapi::IUnknown;
18-
use winapi::Interface;
19-
use winapi::BSTR;
20-
use winapi::COINIT_MULTITHREADED;
21-
use winapi::{SysFreeString, SysStringLen};
22-
use winapi::{HRESULT, S_FALSE, S_OK};
16+
use crate::winapi::CoInitializeEx;
17+
use crate::winapi::IUnknown;
18+
use crate::winapi::Interface;
19+
use crate::winapi::BSTR;
20+
use crate::winapi::COINIT_MULTITHREADED;
21+
use crate::winapi::{SysFreeString, SysStringLen};
22+
use crate::winapi::{HRESULT, S_FALSE, S_OK};
2323

2424
pub fn initialize() -> Result<(), HRESULT> {
2525
let err = unsafe { CoInitializeEx(null_mut(), COINIT_MULTITHREADED) };

src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
//! Use the `Build` struct to compile `src/foo.c`:
4343
//!
4444
//! ```no_run
45-
//! extern crate cc;
46-
//!
4745
//! fn main() {
4846
//! cc::Build::new()
4947
//! .file("src/foo.c")

src/setup_config.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
use std::ffi::OsString;
1212
use std::ptr::null_mut;
13-
use winapi::Interface;
14-
use winapi::BSTR;
15-
use winapi::LPCOLESTR;
16-
use winapi::LPSAFEARRAY;
17-
use winapi::S_FALSE;
18-
use winapi::{CoCreateInstance, CLSCTX_ALL};
19-
use winapi::{IUnknown, IUnknownVtbl};
20-
use winapi::{HRESULT, LCID, LPCWSTR, PULONGLONG};
21-
use winapi::{LPFILETIME, ULONG};
13+
use crate::winapi::Interface;
14+
use crate::winapi::BSTR;
15+
use crate::winapi::LPCOLESTR;
16+
use crate::winapi::LPSAFEARRAY;
17+
use crate::winapi::S_FALSE;
18+
use crate::winapi::{CoCreateInstance, CLSCTX_ALL};
19+
use crate::winapi::{IUnknown, IUnknownVtbl};
20+
use crate::winapi::{HRESULT, LCID, LPCWSTR, PULONGLONG};
21+
use crate::winapi::{LPFILETIME, ULONG};
2222

23-
use com::{BStr, ComPtr};
23+
use crate::com::{BStr, ComPtr};
2424

2525
// Bindings to the Setup.Configuration stuff
2626
pub type InstanceState = u32;
@@ -196,7 +196,7 @@ impl SetupConfiguration {
196196
}
197197
pub fn enum_all_instances(&self) -> Result<EnumSetupInstances, i32> {
198198
let mut obj = null_mut();
199-
let this = try!(self.0.cast::<ISetupConfiguration2>());
199+
let this = self.0.cast::<ISetupConfiguration2>()?;
200200
let err = unsafe { this.EnumAllInstances(&mut obj) };
201201
if err < 0 {
202202
return Err(err);
@@ -249,7 +249,7 @@ impl SetupInstance {
249249
}
250250
pub fn product_path(&self) -> Result<OsString, i32> {
251251
let mut s = null_mut();
252-
let this = try!(self.0.cast::<ISetupInstance2>());
252+
let this = self.0.cast::<ISetupInstance2>()?;
253253
let err = unsafe { this.GetProductPath(&mut s) };
254254
let bstr = unsafe { BStr::from_raw(s) };
255255
if err < 0 {

src/windows_registry.rs

+50-60
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,7 @@
1313
1414
use std::process::Command;
1515

16-
use Tool;
17-
18-
#[cfg(windows)]
19-
macro_rules! otry {
20-
($expr:expr) => {
21-
match $expr {
22-
Some(val) => val,
23-
None => return None,
24-
}
25-
};
26-
}
16+
use crate::Tool;
2717

2818
/// Attempts to find a tool within an MSVC installation using the Windows
2919
/// registry as a point to search from.
@@ -173,9 +163,9 @@ pub fn find_vs_version() -> Result<VsVers, String> {
173163

174164
#[cfg(windows)]
175165
mod impl_ {
176-
use com;
177-
use registry::{RegistryKey, LOCAL_MACHINE};
178-
use setup_config::{EnumSetupInstances, SetupConfiguration, SetupInstance};
166+
use crate::com;
167+
use crate::registry::{RegistryKey, LOCAL_MACHINE};
168+
use crate::setup_config::{EnumSetupInstances, SetupConfiguration, SetupInstance};
179169
use std::env;
180170
use std::ffi::OsString;
181171
use std::fs::File;
@@ -184,7 +174,7 @@ mod impl_ {
184174
use std::mem;
185175
use std::path::{Path, PathBuf};
186176

187-
use Tool;
177+
use crate::Tool;
188178

189179
struct MsvcTool {
190180
tool: PathBuf,
@@ -226,10 +216,10 @@ mod impl_ {
226216
return Box::new(iter::empty());
227217
};
228218
Box::new(instances.filter_map(|instance| {
229-
let instance = otry!(instance.ok());
230-
let installation_name = otry!(instance.installation_name().ok());
231-
if otry!(installation_name.to_str()).starts_with("VisualStudio/16.") {
232-
Some(PathBuf::from(otry!(instance.installation_path().ok())))
219+
let instance = instance.ok()?;
220+
let installation_name = instance.installation_name().ok()?;
221+
if installation_name.to_str()?.starts_with("VisualStudio/16.") {
222+
Some(PathBuf::from(instance.installation_path().ok()?))
233223
} else {
234224
None
235225
}
@@ -264,16 +254,16 @@ mod impl_ {
264254
//
265255
// [online]: https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/
266256
fn vs15_instances() -> Option<EnumSetupInstances> {
267-
otry!(com::initialize().ok());
257+
com::initialize().ok()?;
268258

269-
let config = otry!(SetupConfiguration::new().ok());
259+
let config = SetupConfiguration::new().ok()?;
270260
config.enum_all_instances().ok()
271261
}
272262

273263
pub fn find_msvc_15(tool: &str, target: &str) -> Option<Tool> {
274-
let iter = otry!(vs15_instances());
264+
let iter = vs15_instances()?;
275265
for instance in iter {
276-
let instance = otry!(instance.ok());
266+
let instance = instance.ok()?;
277267
let tool = tool_from_vs15_instance(tool, target, &instance);
278268
if tool.is_some() {
279269
return tool;
@@ -324,7 +314,7 @@ mod impl_ {
324314

325315
fn tool_from_vs15_instance(tool: &str, target: &str, instance: &SetupInstance) -> Option<Tool> {
326316
let (bin_path, host_dylib_path, lib_path, include_path) =
327-
otry!(vs15_vc_paths(target, instance));
317+
vs15_vc_paths(target, instance)?;
328318
let tool_path = bin_path.join(tool);
329319
if !tool_path.exists() {
330320
return None;
@@ -340,7 +330,7 @@ mod impl_ {
340330
tool.include.push(atl_include_path);
341331
}
342332

343-
otry!(add_sdks(&mut tool, target));
333+
add_sdks(&mut tool, target)?;
344334

345335
Some(tool.into_tool())
346336
}
@@ -349,19 +339,19 @@ mod impl_ {
349339
target: &str,
350340
instance: &SetupInstance,
351341
) -> Option<(PathBuf, PathBuf, PathBuf, PathBuf)> {
352-
let instance_path: PathBuf = otry!(instance.installation_path().ok()).into();
342+
let instance_path: PathBuf = instance.installation_path().ok()?.into();
353343
let version_path =
354344
instance_path.join(r"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt");
355-
let mut version_file = otry!(File::open(version_path).ok());
345+
let mut version_file = File::open(version_path).ok()?;
356346
let mut version = String::new();
357-
otry!(version_file.read_to_string(&mut version).ok());
347+
version_file.read_to_string(&mut version).ok()?;
358348
let version = version.trim();
359349
let host = match host_arch() {
360350
X86 => "X86",
361351
X86_64 => "X64",
362352
_ => return None,
363353
};
364-
let target = otry!(lib_subdir(target));
354+
let target = lib_subdir(target)?;
365355
// The directory layout here is MSVC/bin/Host$host/$target/
366356
let path = instance_path.join(r"VC\Tools\MSVC").join(version);
367357
// This is the path to the toolchain for a particular target, running
@@ -384,7 +374,7 @@ mod impl_ {
384374

385375
fn atl_paths(target: &str, path: &Path) -> Option<(PathBuf, PathBuf)> {
386376
let atl_path = path.join("atlfmc");
387-
let sub = otry!(lib_subdir(target));
377+
let sub = lib_subdir(target)?;
388378
if atl_path.exists() {
389379
Some((atl_path.join("lib").join(sub), atl_path.join("include")))
390380
} else {
@@ -395,15 +385,15 @@ mod impl_ {
395385
// For MSVC 14 we need to find the Universal CRT as well as either
396386
// the Windows 10 SDK or Windows 8.1 SDK.
397387
pub fn find_msvc_14(tool: &str, target: &str) -> Option<Tool> {
398-
let vcdir = otry!(get_vc_dir("14.0"));
399-
let mut tool = otry!(get_tool(tool, &vcdir, target));
400-
otry!(add_sdks(&mut tool, target));
388+
let vcdir = get_vc_dir("14.0")?;
389+
let mut tool = get_tool(tool, &vcdir, target)?;
390+
add_sdks(&mut tool, target)?;
401391
Some(tool.into_tool())
402392
}
403393

404394
fn add_sdks(tool: &mut MsvcTool, target: &str) -> Option<()> {
405-
let sub = otry!(lib_subdir(target));
406-
let (ucrt, ucrt_version) = otry!(get_ucrt_dir());
395+
let sub = lib_subdir(target)?;
396+
let (ucrt, ucrt_version) = get_ucrt_dir()?;
407397

408398
tool.path
409399
.push(ucrt.join("bin").join(&ucrt_version).join(sub));
@@ -438,10 +428,10 @@ mod impl_ {
438428

439429
// For MSVC 12 we need to find the Windows 8.1 SDK.
440430
pub fn find_msvc_12(tool: &str, target: &str) -> Option<Tool> {
441-
let vcdir = otry!(get_vc_dir("12.0"));
442-
let mut tool = otry!(get_tool(tool, &vcdir, target));
443-
let sub = otry!(lib_subdir(target));
444-
let sdk81 = otry!(get_sdk81_dir());
431+
let vcdir = get_vc_dir("12.0")?;
432+
let mut tool = get_tool(tool, &vcdir, target)?;
433+
let sub = lib_subdir(target)?;
434+
let sdk81 = get_sdk81_dir()?;
445435
tool.path.push(sdk81.join("bin").join(sub));
446436
let sdk_lib = sdk81.join("lib").join("winv6.3");
447437
tool.libs.push(sdk_lib.join("um").join(sub));
@@ -454,10 +444,10 @@ mod impl_ {
454444

455445
// For MSVC 11 we need to find the Windows 8 SDK.
456446
pub fn find_msvc_11(tool: &str, target: &str) -> Option<Tool> {
457-
let vcdir = otry!(get_vc_dir("11.0"));
458-
let mut tool = otry!(get_tool(tool, &vcdir, target));
459-
let sub = otry!(lib_subdir(target));
460-
let sdk8 = otry!(get_sdk8_dir());
447+
let vcdir = get_vc_dir("11.0")?;
448+
let mut tool = get_tool(tool, &vcdir, target)?;
449+
let sub = lib_subdir(target)?;
450+
let sdk8 = get_sdk8_dir()?;
461451
tool.path.push(sdk8.join("bin").join(sub));
462452
let sdk_lib = sdk8.join("lib").join("win8");
463453
tool.libs.push(sdk_lib.join("um").join(sub));
@@ -494,7 +484,7 @@ mod impl_ {
494484
tool
495485
})
496486
.filter_map(|mut tool| {
497-
let sub = otry!(vc_lib_subdir(target));
487+
let sub = vc_lib_subdir(target)?;
498488
tool.libs.push(path.join("lib").join(sub));
499489
tool.include.push(path.join("include"));
500490
let atlmfc_path = path.join("atlmfc");
@@ -511,8 +501,8 @@ mod impl_ {
511501
// trying to find.
512502
fn get_vc_dir(ver: &str) -> Option<PathBuf> {
513503
let key = r"SOFTWARE\Microsoft\VisualStudio\SxS\VC7";
514-
let key = otry!(LOCAL_MACHINE.open(key.as_ref()).ok());
515-
let path = otry!(key.query_str(ver).ok());
504+
let key = LOCAL_MACHINE.open(key.as_ref()).ok()?;
505+
let path = key.query_str(ver).ok()?;
516506
Some(path.into())
517507
}
518508

@@ -524,10 +514,10 @@ mod impl_ {
524514
// Returns a pair of (root, version) for the ucrt dir if found
525515
fn get_ucrt_dir() -> Option<(PathBuf, String)> {
526516
let key = r"SOFTWARE\Microsoft\Windows Kits\Installed Roots";
527-
let key = otry!(LOCAL_MACHINE.open(key.as_ref()).ok());
528-
let root = otry!(key.query_str("KitsRoot10").ok());
529-
let readdir = otry!(Path::new(&root).join("lib").read_dir().ok());
530-
let max_libdir = otry!(readdir
517+
let key = LOCAL_MACHINE.open(key.as_ref()).ok()?;
518+
let root = key.query_str("KitsRoot10").ok()?;
519+
let readdir = Path::new(&root).join("lib").read_dir().ok()?;
520+
let max_libdir = readdir
531521
.filter_map(|dir| dir.ok())
532522
.map(|dir| dir.path())
533523
.filter(|dir| dir
@@ -536,7 +526,7 @@ mod impl_ {
536526
.and_then(|c| c.as_os_str().to_str())
537527
.map(|c| c.starts_with("10.") && dir.join("ucrt").is_dir())
538528
.unwrap_or(false))
539-
.max());
529+
.max()?;
540530
let version = max_libdir.components().last().unwrap();
541531
let version = version.as_os_str().to_str().unwrap().to_string();
542532
Some((root.into(), version))
@@ -552,19 +542,19 @@ mod impl_ {
552542
// asciibetically to find the newest one as that is what vcvars does.
553543
fn get_sdk10_dir() -> Option<(PathBuf, String)> {
554544
let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0";
555-
let key = otry!(LOCAL_MACHINE.open(key.as_ref()).ok());
556-
let root = otry!(key.query_str("InstallationFolder").ok());
557-
let readdir = otry!(Path::new(&root).join("lib").read_dir().ok());
545+
let key = LOCAL_MACHINE.open(key.as_ref()).ok()?;
546+
let root = key.query_str("InstallationFolder").ok()?;
547+
let readdir = Path::new(&root).join("lib").read_dir().ok()?;
558548
let mut dirs = readdir
559549
.filter_map(|dir| dir.ok())
560550
.map(|dir| dir.path())
561551
.collect::<Vec<_>>();
562552
dirs.sort();
563-
let dir = otry!(dirs
553+
let dir = dirs
564554
.into_iter()
565555
.rev()
566556
.filter(|dir| dir.join("um").join("x64").join("kernel32.lib").is_file())
567-
.next());
557+
.next()?;
568558
let version = dir.components().last().unwrap();
569559
let version = version.as_os_str().to_str().unwrap().to_string();
570560
Some((root.into(), version))
@@ -576,15 +566,15 @@ mod impl_ {
576566
// instead of user mode applications, we would care.
577567
fn get_sdk81_dir() -> Option<PathBuf> {
578568
let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1";
579-
let key = otry!(LOCAL_MACHINE.open(key.as_ref()).ok());
580-
let root = otry!(key.query_str("InstallationFolder").ok());
569+
let key = LOCAL_MACHINE.open(key.as_ref()).ok()?;
570+
let root = key.query_str("InstallationFolder").ok()?;
581571
Some(root.into())
582572
}
583573

584574
fn get_sdk8_dir() -> Option<PathBuf> {
585575
let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0";
586-
let key = otry!(LOCAL_MACHINE.open(key.as_ref()).ok());
587-
let root = otry!(key.query_str("InstallationFolder").ok());
576+
let key = LOCAL_MACHINE.open(key.as_ref()).ok()?;
577+
let root = key.query_str("InstallationFolder").ok()?;
588578
Some(root.into())
589579
}
590580

0 commit comments

Comments
 (0)