Skip to content

Commit 99036cb

Browse files
RReversermitsuhiko
authored andcommitted
Propagate cfg guards from rust-url (#19)
Guard APIs that depend on `Url::to_file_path` and `Url::from_directory_path` on the same platforms as rust-url. This allows to compile rust-sourcemap on other platforms (e.g. wasm32-unknown-unknown) without errors.
1 parent 29f829f commit 99036cb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(any(unix, windows, target_os = "redox")), allow(unused_imports))]
2+
13
use std::collections::HashMap;
24
use std::convert::AsRef;
35
use std::env;
@@ -25,6 +27,7 @@ pub struct SourceMapBuilder {
2527
source_contents: Vec<Option<String>>,
2628
}
2729

30+
#[cfg(any(unix, windows, target_os = "redox"))]
2831
fn resolve_local_reference(base: &Url, reference: &str) -> Option<PathBuf> {
2932
let url = match base.join(reference) {
3033
Ok(url) => {
@@ -109,6 +112,7 @@ impl SourceMapBuilder {
109112

110113
/// Loads source contents from locally accessible files if referenced
111114
/// accordingly. Returns the number of loaded source contents
115+
#[cfg(any(unix, windows, target_os = "redox"))]
112116
pub fn load_local_source_contents(&mut self, base_path: Option<&Path>) -> Result<usize> {
113117
let mut abs_path = env::current_dir()?;
114118
if let Some(path) = base_path {

src/types.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct RewriteOptions<'a> {
2525
pub with_source_contents: bool,
2626
/// If enabled local source contents that are not in the
2727
/// file are automatically inlined.
28+
#[cfg(any(unix, windows, target_os = "redox"))]
2829
pub load_local_source_contents: bool,
2930
/// The base path to the used for source reference resolving
3031
/// when loading local source contents is used.
@@ -40,6 +41,7 @@ impl<'a> Default for RewriteOptions<'a> {
4041
RewriteOptions {
4142
with_names: true,
4243
with_source_contents: true,
44+
#[cfg(any(unix, windows, target_os = "redox"))]
4345
load_local_source_contents: false,
4446
base_path: None,
4547
strip_prefixes: &[][..],
@@ -730,8 +732,12 @@ impl SourceMap {
730732
.set_source_contents(raw.src_id, self.get_source_contents(token.get_src_id()));
731733
}
732734
}
733-
if options.load_local_source_contents {
734-
builder.load_local_source_contents(options.base_path)?;
735+
736+
#[cfg(any(unix, windows, target_os = "redox"))]
737+
{
738+
if options.load_local_source_contents {
739+
builder.load_local_source_contents(options.base_path)?;
740+
}
735741
}
736742

737743
let mut prefixes = vec![];

0 commit comments

Comments
 (0)