Cobol file compilation
This commit is contained in:
+21
-7
@@ -8,6 +8,8 @@ use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct ApiConfig {
|
||||
@@ -35,13 +37,6 @@ struct Argument {
|
||||
source: String,
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
struct Student {
|
||||
st_id: [u8; 5],
|
||||
first_name: [u8; 20],
|
||||
last_name: [u8; 20],
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = read_conf("api.yaml")?;
|
||||
@@ -53,6 +48,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
for endpoint in config.endpoints.into_iter() {
|
||||
println!("Binding route {}", endpoint.path);
|
||||
|
||||
let cobol_path = Path::new(&endpoint.cobol_source);
|
||||
let working_dir = cobol_path.parent().unwrap_or_else(|| Path::new("."));
|
||||
let file_name = cobol_path.file_name()
|
||||
.ok_or("Invalid COBOL filename")?;
|
||||
let library_name = Path::new(file_name)
|
||||
.with_extension("so");
|
||||
let file_name_str = file_name.to_str().ok_or("Filename conversion error")?;
|
||||
let library_name_str = library_name.to_str().ok_or("Library name conversion error")?;
|
||||
let output = Command::new("cobc")
|
||||
.current_dir(working_dir)
|
||||
.args(["-m", "-O", "-o", library_name_str, file_name_str])
|
||||
.output()?;
|
||||
|
||||
if !output.status.success() {
|
||||
eprintln!("COBOL Compilation failed:\n{}", String::from_utf8_lossy(&output.stderr));
|
||||
std::process::exit(1);
|
||||
}
|
||||
println!("Compilation successful: {} generated.", endpoint.cobol_source.replace(".cbl", ".so").as_str());
|
||||
|
||||
let path = endpoint.path.clone();
|
||||
|
||||
app = app.route(&path, get(cobol_handler).layer(Extension(Arc::new(endpoint))));
|
||||
|
||||
Reference in New Issue
Block a user