aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: b2207a673c969b0e5a83d207320b05f1f112eaed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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);
}