generate header by running cbindgen directly
This commit is contained in:
		
							parent
							
								
									02f629c68b
								
							
						
					
					
						commit
						f524038625
					
				
					 3 changed files with 1 additions and 58 deletions
				
			
		|  | @ -8,7 +8,6 @@ description = "C bindings for the servicepoint crate." | |||
| homepage = "https://docs.rs/crate/servicepoint_binding_c" | ||||
| repository = "https://git.berlin.ccc.de/servicepoint/servicepoint" | ||||
| readme = "README.md" | ||||
| links = "servicepoint" | ||||
| keywords = ["cccb", "cccb-servicepoint", "cbindgen"] | ||||
| 
 | ||||
| [lib] | ||||
|  |  | |||
							
								
								
									
										56
									
								
								build.rs
									
										
									
									
									
								
							
							
						
						
									
										56
									
								
								build.rs
									
										
									
									
									
								
							|  | @ -1,56 +0,0 @@ | |||
| //! Build script generating the header for the `servicepoint` C library.
 | ||||
| //!
 | ||||
| //! When the environment variable `SERVICEPOINT_HEADER_OUT` is set, the header is copied there from
 | ||||
| //! the out directory. This can be used to use the build script as a command line tool from other
 | ||||
| //! build tools.
 | ||||
| 
 | ||||
| use std::{env, fs}; | ||||
| 
 | ||||
| fn main() { | ||||
|     let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||||
|     let is_recursive = env::var("SERVICEPOINT_IS_BUILDING") | ||||
|         .unwrap_or("".to_string()) | ||||
|         == "true"; | ||||
|     unsafe { | ||||
|         env::set_var("SERVICEPOINT_IS_BUILDING", "true"); | ||||
|     } | ||||
| 
 | ||||
|     println!("cargo::rerun-if-changed={crate_dir}/src"); | ||||
|     println!("cargo::rerun-if-changed={crate_dir}/build.rs"); | ||||
|     println!("cargo::rerun-if-changed={crate_dir}/Cargo.toml"); | ||||
|     println!("cargo::rerun-if-changed={crate_dir}/Cargo.lock"); | ||||
|     println!("cargo::rerun-if-changed={crate_dir}/cbindgen.toml"); | ||||
|     println!("cargo::rerun-if-env-changed=SERVICEPOINT_HEADER_OUT"); | ||||
| 
 | ||||
|     let config = | ||||
|         cbindgen::Config::from_file(crate_dir.clone() + "/cbindgen.toml") | ||||
|             .unwrap(); | ||||
| 
 | ||||
|     let output_dir = &env::var("OUT_DIR").unwrap(); | ||||
|     let header_file = output_dir.clone() + "/servicepoint.h"; | ||||
| 
 | ||||
|     let bindings = cbindgen::generate_with_config(crate_dir, config) | ||||
|         .expect("Servicepoint header could not be generated"); | ||||
| 
 | ||||
|     bindings.write_to_file(&header_file); | ||||
|     println!("cargo:include={output_dir}"); | ||||
| 
 | ||||
|     if is_recursive { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     if let Ok(header_out) = env::var("SERVICEPOINT_HEADER_OUT") { | ||||
|         if !fs::exists(&header_out).unwrap() { | ||||
|             panic!( | ||||
|                 "SERVICEPOINT_HEADER_OUT is not set to an existing directory" | ||||
|             ); | ||||
|         } | ||||
| 
 | ||||
|         let header_copy = header_out + "/servicepoint.h"; | ||||
| 
 | ||||
|         println!("cargo:warning=Copying header to {header_copy}"); | ||||
|         fs::copy(header_file, &header_copy) | ||||
|             .expect("header could not be copied to SERVICEPOINT_HEADER_OUT"); | ||||
|         println!("cargo::rerun-if-changed={header_copy}"); | ||||
|     } | ||||
| } | ||||
|  | @ -3,4 +3,4 @@ set -e | |||
| 
 | ||||
| SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" | ||||
| 
 | ||||
| SERVICEPOINT_HEADER_OUT="$SCRIPT_PATH/include" cargo build --release | ||||
| cbindgen --config $SCRIPT_PATH/cbindgen.toml --crate servicepoint_binding_c --output $SCRIPT_PATH/include/servicepoint.h | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter