[librsvg: 13/33] Move the c_api sources to src/c_api




commit 47b8889ca57d94f568d83eaf126cd2e402d962c1
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Oct 29 18:13:33 2020 -0600

    Move the c_api sources to src/c_api

 Cargo.toml                             |  1 +
 build.rs                               | 62 ++++++++++++++++++++++++++++++++-
 librsvg/Cargo.toml                     | 41 ----------------------
 librsvg/build.rs                       | 63 ----------------------------------
 {librsvg => src/c_api}/c_api.rs        |  0
 {librsvg => src/c_api}/color_utils.rs  |  0
 {librsvg => src/c_api}/dpi.rs          |  0
 {librsvg => src/c_api}/messages.rs     |  0
 src/c_api/mod.rs                       | 56 ++++++++++++++++++++++++++++++
 {librsvg => src/c_api}/pixbuf_utils.rs |  0
 {librsvg => src/c_api}/sizing.rs       |  0
 src/lib.rs                             |  1 +
 12 files changed, 119 insertions(+), 105 deletions(-)
---
diff --git a/Cargo.toml b/Cargo.toml
index 0f12b559..f545ed1a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2018"
 
 [lib]
 name = "librsvg"
+crate-type = [ "staticlib", "rlib" ]
 
 [dependencies]
 bitflags = "1.0"
diff --git a/build.rs b/build.rs
index 178935e1..3a73d6bd 100644
--- a/build.rs
+++ b/build.rs
@@ -1,6 +1,8 @@
+use regex::Regex;
 use std::env;
 use std::fs::File;
-use std::io::{self, BufWriter, Write};
+use std::io::prelude::*;
+use std::io::{self, BufReader, BufWriter, Write};
 use std::path::Path;
 use std::process;
 
@@ -10,6 +12,7 @@ fn main() {
     find_libxml2();
     check_for_pangoft2();
     generate_srgb_tables();
+    write_version();
 }
 
 fn find_libxml2() {
@@ -125,3 +128,60 @@ fn generate_srgb_tables() {
     print_table(&mut file, "LINEARIZE", linearize, 256);
     print_table(&mut file, "UNLINEARIZE", unlinearize, 256);
 }
+
+fn write_version() {
+    let mut major = None;
+    let mut minor = None;
+    let mut micro = None;
+
+    {
+        let file = File::open("configure.ac")
+            .expect("builds must take place within the librsvg source tree");
+
+        let major_regex = Regex::new(r#"^m4_define\(\[rsvg_major_version\],\[(\d+)\]\)"#).unwrap();
+        let minor_regex = Regex::new(r#"^m4_define\(\[rsvg_minor_version\],\[(\d+)\]\)"#).unwrap();
+        let micro_regex = Regex::new(r#"^m4_define\(\[rsvg_micro_version\],\[(\d+)\]\)"#).unwrap();
+
+        for line in BufReader::new(file).lines() {
+            if let Ok(line) = line {
+                if let Some(nums) = major_regex.captures(&line) {
+                    major = Some(String::from(
+                        nums.get(1).expect("major_regex matched once").as_str(),
+                    ));
+                } else if let Some(nums) = minor_regex.captures(&line) {
+                    minor = Some(String::from(
+                        nums.get(1).expect("minor_regex matched once").as_str(),
+                    ));
+                } else if let Some(nums) = micro_regex.captures(&line) {
+                    micro = Some(String::from(
+                        nums.get(1).expect("micro_regex matched once").as_str(),
+                    ));
+                }
+            }
+        }
+    }
+
+    let output = Path::new(&env::var("OUT_DIR").unwrap()).join("version.rs");
+    let mut file = File::create(output).expect("open version.rs for writing");
+    file.write_all(
+        format!(
+            r#"
+use std::os::raw::c_uint;
+
+#[no_mangle]
+pub static rsvg_major_version: c_uint = {};
+
+#[no_mangle]
+pub static rsvg_minor_version: c_uint = {};
+
+#[no_mangle]
+pub static rsvg_micro_version: c_uint = {};
+"#,
+            major.expect("major version is set"),
+            minor.expect("minor version is set"),
+            micro.expect("micro version is set")
+        )
+        .as_bytes(),
+    )
+    .expect("write version.rs");
+}
diff --git a/librsvg/c_api.rs b/src/c_api/c_api.rs
similarity index 100%
rename from librsvg/c_api.rs
rename to src/c_api/c_api.rs
diff --git a/librsvg/color_utils.rs b/src/c_api/color_utils.rs
similarity index 100%
rename from librsvg/color_utils.rs
rename to src/c_api/color_utils.rs
diff --git a/librsvg/dpi.rs b/src/c_api/dpi.rs
similarity index 100%
rename from librsvg/dpi.rs
rename to src/c_api/dpi.rs
diff --git a/librsvg/messages.rs b/src/c_api/messages.rs
similarity index 100%
rename from librsvg/messages.rs
rename to src/c_api/messages.rs
diff --git a/src/c_api/mod.rs b/src/c_api/mod.rs
new file mode 100644
index 00000000..86a0d9b5
--- /dev/null
+++ b/src/c_api/mod.rs
@@ -0,0 +1,56 @@
+#![allow(clippy::missing_safety_doc)]
+
+#[rustfmt::skip]
+pub use c_api::{
+    rsvg_error_get_type,
+    rsvg_handle_close,
+    rsvg_handle_flags_get_type,
+    rsvg_handle_get_base_uri,
+    rsvg_handle_get_dimensions,
+    rsvg_handle_get_dimensions_sub,
+    rsvg_handle_get_geometry_for_element,
+    rsvg_handle_get_geometry_for_layer,
+    rsvg_handle_get_intrinsic_dimensions,
+    rsvg_handle_get_intrinsic_size_in_pixels,
+    rsvg_handle_get_pixbuf_sub,
+    rsvg_handle_get_position_sub,
+    rsvg_handle_has_sub,
+    rsvg_handle_internal_set_testing,
+    rsvg_handle_new_from_data,
+    rsvg_handle_new_from_file,
+    rsvg_handle_new_from_gfile_sync,
+    rsvg_handle_new_from_stream_sync,
+    rsvg_handle_new_with_flags,
+    rsvg_handle_read_stream_sync,
+    rsvg_handle_render_cairo_sub,
+    rsvg_handle_render_element,
+    rsvg_handle_render_document,
+    rsvg_handle_render_layer,
+    rsvg_handle_set_base_gfile,
+    rsvg_handle_set_base_uri,
+    rsvg_handle_set_dpi_x_y,
+    rsvg_handle_set_size_callback,
+    rsvg_handle_write,
+};
+
+pub use color_utils::rsvg_css_parse_color;
+
+pub use dpi::{rsvg_set_default_dpi, rsvg_set_default_dpi_x_y};
+
+#[rustfmt::skip]
+pub use pixbuf_utils::{
+    rsvg_pixbuf_from_file,
+    rsvg_pixbuf_from_file_at_max_size,
+    rsvg_pixbuf_from_file_at_size,
+    rsvg_pixbuf_from_file_at_zoom,
+    rsvg_pixbuf_from_file_at_zoom_with_max,
+};
+
+#[macro_use]
+mod messages;
+
+mod c_api;
+mod color_utils;
+mod dpi;
+pub mod pixbuf_utils;
+mod sizing;
diff --git a/librsvg/pixbuf_utils.rs b/src/c_api/pixbuf_utils.rs
similarity index 100%
rename from librsvg/pixbuf_utils.rs
rename to src/c_api/pixbuf_utils.rs
diff --git a/librsvg/sizing.rs b/src/c_api/sizing.rs
similarity index 100%
rename from librsvg/sizing.rs
rename to src/c_api/sizing.rs
diff --git a/src/lib.rs b/src/lib.rs
index 8949ce8c..550a914a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -90,6 +90,7 @@ mod api;
 mod aspect_ratio;
 mod attributes;
 mod bbox;
+mod c_api;
 mod color;
 mod cond;
 mod css;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]