diff --git a/Cargo.lock b/Cargo.lock index 0bb3538..44acf68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1007,7 +1007,7 @@ dependencies = [ [[package]] name = "ruxgo" -version = "0.9.5" +version = "0.9.6" dependencies = [ "bytes", "clap", diff --git a/Cargo.toml b/Cargo.toml index 961eaac..0913528 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruxgo" -version = "0.9.5" +version = "0.9.6" edition = "2021" authors = ["Zewei Yang "] description = "A Cargo-like build tool for building C and C++ applications" diff --git a/apps/nginx/README.md b/apps/nginx/README.md new file mode 100644 index 0000000..c18a40e --- /dev/null +++ b/apps/nginx/README.md @@ -0,0 +1,24 @@ +# Build and Run [`nginx`](https://github.com/nginx/nginx) on RuxOS + +Firstly, you need to copy `config_linux.toml` from `ruxgo/apps/nginx/ruxos` and place it in the `ruxos/apps/c/rux-nginx` at the same level as `nginx-1.24.0`. + +Then, switch to `ruxos/apps/c/rux-nginx` directory. If `nginx-1.24.0` does not exist, execute the following prerequisite commands (if it does, it is not required): + +```bash +wget https://nginx.org/download/nginx-1.24.0.tar.gz +tar -zxvf nginx-1.24.0.tar.gz && rm -f nginx-1.24.0.tar.gz +``` + +After that, you need to execute the following command: + +```bash +./create_nginx_img.sh +``` + +Finally, execute the following commands to build and run it: + +```bash +# Build and Run +ruxgo -b +ruxgo -r +``` diff --git a/apps/nginx/ruxos/config_linux.toml b/apps/nginx/ruxos/config_linux.toml index b179c32..a1829cc 100644 --- a/apps/nginx/ruxos/config_linux.toml +++ b/apps/nginx/ruxos/config_linux.toml @@ -5,12 +5,12 @@ compiler = "gcc" [os] name = "ruxos" services = ["alloc","paging","irq","fp_simd","multitask","fs","blkfs", - "net","pipe","epoll","poll","rtc","select","virtio-9p"] -ulib = "ruxlibc" + "net","pipe","epoll","poll","rtc","select","virtio-9p","signal"] +ulib = "ruxmusl" [os.platform] name = "aarch64-qemu-virt" -smp = "4" +smp = "1" mode = "release" log = "info" @@ -19,51 +19,51 @@ blk = "y" net = "y" v9p = "y" v9p_path = "./html" -graphic = "n" disk_img = "fat32.img" -args = "./nginx_app" -net_dev = "user" ### src to compile [[targets]] name = "libcore" -src = "nginx-1.24.0/src/core" +src = "./nginx-1.24.0/src/core" src_exclude = ["ngx_regex.c","ngx_thread_pool.c"] -include_dir = ["./objs","nginx-1.24.0/src/core","nginx-1.24.0/src/event", - "nginx-1.24.0/src/event/modules","nginx-1.24.0/src/os/unix"] -type = "object" -cflags = "-Wno-format" -ldflags = "-r" +include_dir = ["./objs","./nginx-1.24.0/src/core","./nginx-1.24.0/src/event", + "./nginx-1.24.0/src/event/modules","./nginx-1.24.0/src/os/unix"] +type = "static" +cflags = "" +archive = "ar" +ldflags = "rcs" [[targets]] name = "libevent" -src = "nginx-1.24.0/src/event" +src = "./nginx-1.24.0/src/event" src_exclude = ["/modules","ngx_event_acceptex.c","ngx_event_connectex.c", "ngx_event_openssl_stapling.c","ngx_event_openssl.c"] -include_dir = ["./objs","nginx-1.24.0/src/core","nginx-1.24.0/src/event", - "nginx-1.24.0/src/event/modules","nginx-1.24.0/src/os/unix"] -type = "object" -cflags = "-Wno-format" -ldflags = "-r" +include_dir = ["./objs","./nginx-1.24.0/src/core","./nginx-1.24.0/src/event", + "./nginx-1.24.0/src/event/modules","./nginx-1.24.0/src/os/unix"] +type = "static" +cflags = "" +archive = "ar" +ldflags = "rcs" [[targets]] name = "libevent_modules" -src = "nginx-1.24.0/src/event/modules" +src = "./nginx-1.24.0/src/event/modules" src_exclude = [ "ngx_devpoll_module.c","ngx_eventport_module.c", "ngx_iocp_module.c","ngx_kqueue_module.c", "ngx_poll_module.c","ngx_win32_poll_module.c", "ngx_win32_select_module.c" ] -include_dir = ["./objs","nginx-1.24.0/src/core","nginx-1.24.0/src/event", - "nginx-1.24.0/src/event/modules","nginx-1.24.0/src/os/unix"] -type = "object" -cflags = "-Wno-format" -ldflags = "-r" +include_dir = ["./objs","./nginx-1.24.0/src/core","./nginx-1.24.0/src/event", + "./nginx-1.24.0/src/event/modules","./nginx-1.24.0/src/os/unix"] +type = "static" +cflags = "" +archive = "ar" +ldflags = "rcs" [[targets]] name = "libos_unix" -src = "nginx-1.24.0/src/os/unix" +src = "./nginx-1.24.0/src/os/unix" src_exclude = [ "ngx_darwin_init.c","ngx_darwin_sendfile_chain.c", "ngx_file_aio_read.c","ngx_freebsd_init.c", @@ -71,26 +71,28 @@ src_exclude = [ "ngx_solaris_init.c","ngx_solaris_sendfilev_chain.c", "ngx_thread_cond.c","ngx_thread_id.c","ngx_thread_mutex.c" ] -include_dir = ["./objs","nginx-1.24.0/src/core","nginx-1.24.0/src/event", - "nginx-1.24.0/src/event/modules","nginx-1.24.0/src/os/unix"] -type = "object" -cflags = "-Wno-format" -ldflags = "-r" +include_dir = ["./objs","./nginx-1.24.0/src/core","./nginx-1.24.0/src/event", + "./nginx-1.24.0/src/event/modules","./nginx-1.24.0/src/os/unix"] +type = "static" +cflags = "" +archive = "ar" +ldflags = "rcs" [[targets]] name = "libhttp" -src = "nginx-1.24.0/src/http" +src = "./nginx-1.24.0/src/http" src_exclude = ["/modules","/v2","ngx_http_file_cache.c", "ngx_http_huff_decode.c","ngx_http_huff_encode.c"] -include_dir = ["nginx-1.24.0/src/http","nginx-1.24.0/src/http/modules","nginx-1.24.0/src/core", - "nginx-1.24.0/src/event","nginx-1.24.0/src/event/modules","nginx-1.24.0/src/os/unix","./objs"] -type = "object" -cflags = "-Wno-format" -ldflags = "-r" +include_dir = ["./nginx-1.24.0/src/http","./nginx-1.24.0/src/http/modules","./nginx-1.24.0/src/core", + "./nginx-1.24.0/src/event","./nginx-1.24.0/src/event/modules","./nginx-1.24.0/src/os/unix","./objs"] +type = "static" +cflags = "" +archive = "ar" +ldflags = "rcs" [[targets]] name = "libhttp_modules" -src = "nginx-1.24.0/src/http/modules" +src = "./nginx-1.24.0/src/http/modules" src_exclude = [ "/perl","ngx_http_addition_filter_module.c", "ngx_http_auth_basic_module.c","ngx_http_auth_request_module.c", @@ -104,30 +106,24 @@ src_exclude = [ "ngx_http_slice_filter_module.c","ngx_http_ssl_module.c", "ngx_http_stub_status_module.c","ngx_http_xslt_filter_module.c" ] -include_dir = ["nginx-1.24.0/src/http","nginx-1.24.0/src/http/modules", - "nginx-1.24.0/src/core","nginx-1.24.0/src/event", - "nginx-1.24.0/src/event/modules","nginx-1.24.0/src/os/unix","./objs"] -type = "object" -cflags = "-Wno-format" -ldflags = "-r" - -[[targets]] -name = "libobjs" -src = "./objs" -include_dir = ["./objs","nginx-1.24.0/src/core","nginx-1.24.0/src/event", - "nginx-1.24.0/src/event/modules","nginx-1.24.0/src/os/unix"] -type = "object" -cflags = "-Wno-format" -ldflags = "-r" +include_dir = ["./nginx-1.24.0/src/http","./nginx-1.24.0/src/http/modules", + "./nginx-1.24.0/src/core","./nginx-1.24.0/src/event", + "./nginx-1.24.0/src/event/modules","./nginx-1.24.0/src/os/unix","./objs"] +type = "static" +cflags = "" +archive = "ar" +ldflags = "rcs" ### linker [[targets]] name = "ruxos_nginx" -src = "" -include_dir = "" +src = "./objs" +src_exclude = ["./objs/nginx-1.24.0"] +include_dir = ["./objs","./nginx-1.24.0/src/core","./nginx-1.24.0/src/event", + "./nginx-1.24.0/src/event/modules","./nginx-1.24.0/src/os/unix"] type = "exe" -cflags = "-Wno-format" +cflags = "" linker = "rust-lld -flavor gnu" ldflags = "" -deps = ["libobjs","libcore","libevent","libevent_modules", +deps = ["libcore","libevent","libevent_modules", "libos_unix","libhttp","libhttp_modules"] \ No newline at end of file diff --git a/src/commands.rs b/src/commands.rs index d0d24c1..5637bd6 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -612,7 +612,7 @@ pub fn run( let path = Path::new(&os_config.platform.qemu.disk_img); if path.exists() { log( - LogLevel::Log, + LogLevel::Info, &format!( "disk image \"{}\" already exists!", os_config.platform.qemu.disk_img @@ -624,7 +624,7 @@ pub fn run( } // create loaded app file systems if needed if !build_config.app.is_empty() && &os_config.platform.qemu.v9p == "y" { - crate_app_fs(build_config, os_config); + create_app_fs(build_config, os_config); } // enable qemu gdb guest if needed if &os_config.platform.qemu.debug == "y" { @@ -1148,41 +1148,43 @@ int main(int argc, char **argv) } // Creates the app file system and related content -pub fn crate_app_fs(build_config: &BuildConfig, os_config: &OSConfig) { +pub fn create_app_fs(build_config: &BuildConfig, os_config: &OSConfig) { // Copys the dynamic_lib if needed - let actual_lib_name = "libc.so"; let lib_name = format!("ld-musl-{}.so.1", os_config.platform.arch.as_str()); - let src_path = Path::new(RUXMUSL_DIR).join(format!("install/lib/{}", actual_lib_name)); - let dest_path = Path::new(&os_config.platform.qemu.v9p_path).join("lib"); - if let Err(e) = fs::create_dir_all(&dest_path) { + let lib_src = Path::new(RUXMUSL_DIR).join("install/lib/libc.so"); + let lib_dest = Path::new(&os_config.platform.qemu.v9p_path).join("lib"); + if let Err(e) = fs::create_dir_all(&lib_dest) { log( LogLevel::Error, &format!("Failed to create directories: {}", e), ); std::process::exit(1); } - if src_path.exists() { - if let Err(err) = fs::copy(&src_path, dest_path.join(lib_name)) { + if lib_src.exists() { + if let Err(err) = fs::copy(&lib_src, lib_dest.join(lib_name)) { log(LogLevel::Error, &format!("Failed to copy file: {}", err)); std::process::exit(1); } } else { - log(LogLevel::Error, "The ruxmusl dynamic library does not exist"); + log( + LogLevel::Error, + "The ruxmusl dynamic library does not exist", + ); std::process::exit(1); } + // Copys the bin file - let app_dest_bin = Path::new(&os_config.platform.qemu.v9p_path).join("bin"); - if let Err(e) = fs::create_dir_all(&app_dest_bin) { + let app_src = Path::new(&build_config.app); + let app_dest = Path::new(&os_config.platform.qemu.v9p_path).join("bin"); + if let Err(e) = fs::create_dir_all(&app_dest) { log( LogLevel::Error, &format!("Failed to create bin directory: {}", e), ); std::process::exit(1); } - let app_src = Path::new(&build_config.app); if let Some(app_filename) = app_src.file_name() { - let app_dest = app_dest_bin.join(app_filename); - if let Err(err) = fs::copy(app_src, app_dest) { + if let Err(err) = fs::copy(app_src, app_dest.join(app_filename)) { log( LogLevel::Error, &format!("Binary file does not exist or path is incorrect: {}", err),