use std::env::{current_dir, set_current_dir}; use std::fs::{create_dir_all, metadata, read_to_string, write}; use std::path::Path; use std::process::Command; mod parse; const TARGET_TAG: &str = "v3.1.5"; fn main() { assert_eq!( current_dir().unwrap(), Path::new(env!("CARGO_MANIFEST_DIR")), "running in the wrong place" ); create_dir_all("out").unwrap(); set_current_dir("out").unwrap(); if metadata("orig").is_err() { println!("cloning wxWidgets source..."); let git_clone = Command::new("git") .args(&[ "clone", "--quiet", "https://github.com/wxWidgets/wxWidgets.git", "orig", ]) .status() .unwrap(); assert!(git_clone.success()); let git_config = Command::new("git") .args(&[ "-C", "orig", "config", "--local", "advice.detachedHead", "false", ]) .status() .unwrap(); assert!(git_config.success()); } let git_tag = Command::new("git") .args(&["-C", "orig", "describe"]) .output() .unwrap(); if String::from_utf8(git_tag.stdout).unwrap().trim() != TARGET_TAG { let git_checkout = Command::new("git") .args(&["-C", "orig", "checkout", "--quiet", TARGET_TAG]) .status() .unwrap(); assert!(git_checkout.success()); } if metadata("new").is_err() { println!("creating wx crate..."); let cargo_new = Command::new("cargo") .args(&[ "new", "--quiet", "--vcs", "none", "--lib", "--name", "wx", "new", ]) .status() .unwrap(); assert!(cargo_new.success()); } // we're putting the hello world example out here because yolo create_dir_all("new/examples").unwrap(); write( "new/examples/hello_world.rs", r#" // wxWidgets "Hello World" Program struct MyApp; impl wx::App for MyApp { fn on_init() { let frame = MyFrame::new(); frame.show(true); } } struct MyFrame { base: wx::FrameBase, } impl wx::Frame for MyFrame { fn new() -> Self { let base = wx::FrameBase::new(None, wx::Id::Any, "Hello World"); let file_menu = wx::Menu::new(); } wx::main!(MyApp); class MyFrame : public wxFrame { public: MyFrame(); private: void OnHello(wxCommandEvent& event); void OnExit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); }; MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, "Hello World") { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", "Help string shown in status bar for this menu item"); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT); wxMenu *menuHelp = new wxMenu; menuHelp->Append(wxID_ABOUT); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); menuBar->Append(menuHelp, "&Help"); SetMenuBar( menuBar ); CreateStatusBar(); SetStatusText("Welcome to wxWidgets!"); Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello); Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); } void MyFrame::OnExit(wxCommandEvent& event) { Close(true); } void MyFrame::OnAbout(wxCommandEvent& event) { wxMessageBox("This is a wxWidgets Hello World example", "About Hello World", wxOK | wxICON_INFORMATION); } void MyFrame::OnHello(wxCommandEvent& event) { wxLogMessage("Hello world from wxWidgets!"); } "#, ) .unwrap(); let wx_h_text = read_to_string("orig/include/wx/wx.h").unwrap(); let lib_root_h = parse::parse(&wx_h_text); dbg!(lib_root_h); }