Skip to content

Commit

Permalink
Support sourceMappingURL custom section
Browse files Browse the repository at this point in the history
This fixes building for `wasm32-unknown-unknown` on newest
nightly Rust.
  • Loading branch information
koute committed Feb 8, 2018
1 parent 1a3bb5d commit a3328fb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/wasm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub struct Context {
pub fn_pointer_tables: Option< FnPointerTable >,
pub data: Vec< Data >,
pub module_name: Option< String >,
pub source_mapping_url: Option< String >,
next_function_index: u32,
next_type_index: u32
}
Expand Down Expand Up @@ -398,6 +399,7 @@ impl Context {
fn_pointer_tables: Default::default(),
data: Default::default(),
module_name: Default::default(),
source_mapping_url: Default::default(),
next_function_index: 0,
next_type_index: 0
}
Expand Down Expand Up @@ -619,6 +621,12 @@ impl Context {
kind => panic!( "unknown name section chunk type: {}", kind )
}
}
} else if section.name() == "sourceMappingURL" {
let payload = take( section.payload_mut() );
let mut p: &[u8] = &payload;
let url_length = u32::from( pw::VarUint32::deserialize( &mut p ).unwrap() );
let url = str::from_utf8( &p[ 0..url_length as usize ] ).expect( "invalid sourceMappingURL" );
ctx.source_mapping_url = Some( url.to_owned() );
} else {
panic!( "unsupported custom section: '{}'", section.name() );
}
Expand Down Expand Up @@ -898,6 +906,17 @@ impl Context {
));
}

if let Some( source_mapping_url ) = self.source_mapping_url {
let mut section_bytes = Vec::new();
write_with_length( &mut section_bytes, move |body| {
write_string( body, "sourceMappingURL" );
write_string( body, &source_mapping_url );
});
sections.push( pw::Section::Custom(
pw::CustomSection::deserialize( &mut section_bytes.as_slice() ).unwrap()
));
}

pw::Module::new( sections )
}

Expand Down

0 comments on commit a3328fb

Please sign in to comment.