| 1 |
// Copyright Mozilla Foundation. See the COPYRIGHT |
| 2 |
// file at the top-level directory of this distribution. |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 5 |
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 6 |
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 7 |
// option. This file may not be copied, modified, or distributed |
| 8 |
// except according to those terms. |
| 9 |
|
| 10 |
extern crate cheddar; |
| 11 |
|
| 12 |
use std::io::prelude::*; |
| 13 |
use std::fs::File; |
| 14 |
|
| 15 |
fn replace(path: &str) -> std::io::Result<()> { |
| 16 |
let mut f = try!(File::open(path)); |
| 17 |
let mut s = String::new(); |
| 18 |
try!(f.read_to_string(&mut s)); |
| 19 |
s = s.replace("#ifndef cheddar_generated_encoding_rs_h", "// Copyright Mozilla Foundation. See the COPYRIGHT |
| 20 |
// file at the top-level directory of this distribution. |
| 21 |
// |
| 22 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 23 |
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 24 |
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 25 |
// option. This file may not be copied, modified, or distributed |
| 26 |
// except according to those terms. |
| 27 |
|
| 28 |
// THIS IS A GENERATED FILE. PLEASE DO NOT EDIT. |
| 29 |
// Instead, please regenerate using encoding_c/build.rs. |
| 30 |
|
| 31 |
#ifndef cheddar_generated_encoding_rs_h"); |
| 32 |
s = s.replace("uint16_t", "char16_t"); |
| 33 |
s = s.replace("uintptr_t", "size_t"); |
| 34 |
s = s.replace("Encoding", "ENCODING_RS_ENCODING"); |
| 35 |
s = s.replace("Encoder", "ENCODING_RS_ENCODER"); |
| 36 |
s = s.replace("Decoder", "ENCODING_RS_DECODER"); |
| 37 |
s = s.replace("ENCODING_RS_ENCODING.html", "Encoding.html"); |
| 38 |
s = s.replace("ENCODING_RS_ENCODER.html", "Encoder.html"); |
| 39 |
s = s.replace("ENCODING_RS_DECODER.html", "Decoder.html"); |
| 40 |
s = s.replace("#include <stdbool.h>", |
| 41 |
"#include <stdbool.h>\n#include \"encoding_rs_statics.h\""); |
| 42 |
let mut f = try!(File::create(path)); |
| 43 |
try!(f.write_all(s.as_bytes())); |
| 44 |
Ok(()) |
| 45 |
} |
| 46 |
|
| 47 |
fn main() { |
| 48 |
println!("cargo:rerun-if-changed=src/lib.rs"); |
| 49 |
|
| 50 |
let path = "include/encoding_rs.h"; |
| 51 |
|
| 52 |
cheddar::Cheddar::new() |
| 53 |
.expect("could not read manifest") |
| 54 |
.run_build(path); |
| 55 |
|
| 56 |
match replace(path) { |
| 57 |
Ok(_) => {} |
| 58 |
Err(e) => println!("Performing replacements failed {}.", e), |
| 59 |
} |
| 60 |
} |