Skip to content

Commit

Permalink
Update toml files under apps/ and how to use them
Browse files Browse the repository at this point in the history
  • Loading branch information
BeichenY1 committed Dec 26, 2023
1 parent 8ac67a0 commit c358925
Show file tree
Hide file tree
Showing 30 changed files with 1,388 additions and 30 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/target
/Nomu_Engine
*.hash
compile_commands.json
compile_commands.json
ruxos_bld
sqlite-amalgamation-3410100
file.sqlite
dump.rdb
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ For a project you want to build, you just need to figure out the source file pat

## Installation

The tool currently only supports local installation.
```console
git clone https://github.com/Ybeichen/ruxgo.git && cd ruxgo
cargo build
cargo install --path .
To build the `ruxgo` executable from source, you will first need to install Rust and Cargo. Follow the instructions on the [Rust installation page](https://www.rust-lang.org/tools/install). Ruxgo currently requires at least Rust version 1.70.

Once you have installed Rust, the following command can be used to build and install Ruxgo:

```sh
cargo install --git https://github.com/Ybeichen/ruxgo.git ruxgo
```

This will automatically download `ruxgo`, build it, and install it in Cargo's global binary directory (`~/.cargo/bin/` by default).

To uninstall, run the command `cargo uninstall ruxgo`.

## Features & TODOs

* [x] Multithreaded
Expand Down Expand Up @@ -75,21 +80,21 @@ You can also configure the log level with the environment variable `"RUXGO_LOG_L
## Ruxgo-apps
Currently, there are two ways to build an app in the **/apps** directory: locally and on ruxos.
The `apps/` directory places all the toml files that have been tested. Currently, there are two ways to build an app: locally and on ruxos
- If building locally, you'll need to download the apps source code and then use ruxgo to build and run it.
- If you want to build on ruxos, you need to copy `config_linux.toml` into ruxos **apps/c/<name>** , then download the apps source code and build it with ruxgo.
- If you want to build on ruxos, you need to copy `config_linux.toml` from `ruxgo/apps/<name>/ruxos` into `ruxos/apps/c/<name>`, then download the apps source code and use ruxgo to build and run it.
**Note:** Refer to the README.md in each app directory for details. The following applications are already supported:
* [x] [redis](apps/redis)
* [x] [sqlite3](apps/sqlite3)
* [x] [iperf](apps/iperf)
* [x] helloworld
* [x] memtest
* [x] redis
* [x] sqlite3
* [x] httpclient
* [x] httpserver
* [x] iperf
* [x] nginx
* [ ] python3
Expand Down Expand Up @@ -158,21 +163,21 @@ compiler = "gcc"
[[targets]]
name = "libsqlite3"
src = "./sqlite-amalgamation-3410100"
src_excluded = ["sqlite-amalgamation-3410100/shell.c"]
src_excluded = ["shell.c"]
include_dir = "./sqlite-amalgamation-3410100"
type = "static"
cflags = "-w -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_FLOATING_POINT -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEBUG"
archive = "ar"
ldflags = "rcs"
[[targets]]
name = "main"
name = "local_sqlite3"
src = "./"
src_excluded = ["sqlite-amalgamation-3410100"]
include_dir = "./"
type = "exe"
cflags = ""
ldflags = "rust-lld -flavor gnu"
ldflags = ""
deps = ["libsqlite3"]
```
Expand All @@ -196,25 +201,25 @@ log = "error"
[os.platform.qemu]
blk = "y"
graphic = "n"
disk_img = "disk.img"
[[targets]]
name = "libsqlite3"
src = "./sqlite-amalgamation-3410100"
src_excluded = ["sqlite-amalgamation-3410100/shell.c"]
src_excluded = ["shell.c"]
include_dir = "./sqlite-amalgamation-3410100"
type = "static"
cflags = "-w -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_FLOATING_POINT -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEBUG"
archive = "ar"
ldflags = "rcs"
[[targets]]
name = "main"
name = "ruxos_sqlite3"
src = "./"
src_excluded = ["sqlite-amalgamation-3410100"]
include_dir = "./"
type = "exe"
cflags = ""
ldflags = "rust-lld -flavor gnu"
linker = "rust-lld -flavor gnu"
ldflags = ""
deps = ["libsqlite3"]
```
26 changes: 26 additions & 0 deletions apps/filetest/ruxos/config_linux.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[build]
compiler = "gcc"

[os]
name = "ruxos"
services = ["alloc","paging","fs","blkfs"]
ulib = "ruxlibc"

[os.platform]
name = "x86_64-qemu-q35"
smp = "4"
mode = "release"
log = "warn"

[os.platform.qemu]
graphic = "n"
blk = "y"

[[targets]]
name = "filetest"
src = "./"
include_dir = "./"
type = "exe"
cflags = ""
linker = "rust-lld -flavor gnu"
ldflags = ""
10 changes: 10 additions & 0 deletions apps/helloworld/local/config_linux.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build]
compiler = "gcc"

[[targets]]
name = "helloworld"
src = "./"
include_dir = "./"
type = "exe"
cflags = ""
ldflags = ""
16 changes: 16 additions & 0 deletions apps/helloworld/local/helloworld.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright (c) [2023] [Syswonder Community]
* [Ruxos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#include <stdio.h>

int main()
{
printf("Hello, %c app!\n", 'C');
return 0;
}
File renamed without changes.
10 changes: 10 additions & 0 deletions apps/httpclient/local/config_linux.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build]
compiler = "gcc"

[[targets]]
name = "httpclient"
src = "./"
include_dir = "./"
type = "exe"
cflags = ""
ldflags = ""
86 changes: 86 additions & 0 deletions apps/httpclient/local/httpclient.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* Copyright (c) [2023] [Syswonder Community]
* [Ruxos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/uio.h>

const char request[] = "\
GET / HTTP/1.1\r\n\
Host: ident.me\r\n\
Accept: */*\r\n\
\r\n";

char request1[] = "\
GET / HTTP/1.1\r\n";

char request2[] = "Host: ident.me\r\n\
Accept: */*\r\n\
\r\n";

int main()
{
puts("Hello, Ruxos C HTTP client!");
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == -1) {
perror("socket() error");
return -1;
}
struct addrinfo *res;

if (getaddrinfo("ident.me", NULL, NULL, &res) != 0) {
perror("getaddrinfo() error");
return -1;
}
char str[INET_ADDRSTRLEN];
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(res->ai_addr))->sin_addr), str,
INET_ADDRSTRLEN) == NULL) {
perror("inet_ntop() error");
return -1;
}
printf("IP: %s\n", str);
((struct sockaddr_in *)(res->ai_addr))->sin_port = htons(80);
if (connect(sock, res->ai_addr, sizeof(*(res->ai_addr))) != 0) {
perror("connect() error");
return -1;
}
char rebuf[2000] = {};
if (send(sock, request, strlen(request), 0) == -1) {
perror("send() error");
return -1;
}
ssize_t l = recv(sock, rebuf, 2000, 0);
if (l == -1) {
perror("recv() error");
return -1;
}
rebuf[l] = '\0';
printf("%s\n", rebuf);
// test sendmsg
struct iovec iovs[2] = {
{ .iov_base = request1, .iov_len = strlen(request1)},
{ .iov_base = request2, .iov_len = strlen(request2)}
};
struct msghdr mg = {
.msg_iov = iovs,
.msg_iovlen = 2
};
int num = sendmsg(sock, &mg, 0);
if (num == -1) {
perror("sendmsg() error");
return -1;
}
freeaddrinfo(res);

return 0;
}
File renamed without changes.
10 changes: 10 additions & 0 deletions apps/httpserver/local/config_linux.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build]
compiler = "gcc"

[[targets]]
name = "httpserver"
src = "./"
include_dir = "./"
type = "exe"
cflags = "-Wno-format"
ldflags = ""
99 changes: 99 additions & 0 deletions apps/httpserver/local/httpserver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* Copyright (c) [2023] [Syswonder Community]
* [Ruxos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/


#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>

const char header[] = "\
HTTP/1.1 200 OK\r\n\
Content-Type: text/html\r\n\
Content-Length: %u\r\n\
Connection: close\r\n\
\r\n\
";

const char content[] = "<html>\n\
<head>\n\
<title>Hello, Ruxos</title>\n\
</head>\n\
<body>\n\
<center>\n\
<h1>Hello, <a href=\"https://github.com/syswonder/ruxos\">Ruxos</a></h1>\n\
</center>\n\
<hr>\n\
<center>\n\
<i>Powered by <a href=\"https://github.com/syswonder/ruxos/tree/main/apps/net/httpserver\">Ruxos example HTTP server</a> v0.1.0</i>\n\
</center>\n\
</body>\n\
</html>\n\
";

int main()
{
puts("Hello, Ruxos C HTTP server!");
struct sockaddr_in local, remote;
int addr_len = sizeof(remote);
local.sin_family = AF_INET;
if (inet_pton(AF_INET, "0.0.0.0", &(local.sin_addr)) != 1) {
perror("inet_pton() error");
return -1;
}
local.sin_port = htons(5555);
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == -1) {
perror("socket() error");
return -1;
}
if (bind(sock, (struct sockaddr *)&local, sizeof(local)) != 0) {
perror("bind() error");
return -1;
}
if (listen(sock, 0) != 0) {
perror("listen() error");
return -1;
}
puts("listen on: http://0.0.0.0:5555/");
char buf[1024] = {};
int client;
char response[1024] = {};
snprintf(response, 1024, header, strlen(content));
strcat(response, content);
for (;;) {
client = accept(sock, (struct sockaddr *)&remote, (socklen_t *)&addr_len);
if (client == -1) {
perror("accept() error");
return -1;
}
printf("new client %d\n", client);
if (recv(client, buf, 1024, 0) == -1) {
perror("recv() error");
return -1;
}
ssize_t l = send(client, response, strlen(response), 0);
if (l == -1) {
perror("send() error");
return -1;
}
if (close(client) == -1) {
perror("close() error");
return -1;
}
printf("client %d close: %ld bytes sent\n", client, l);
}
if (close(sock) == -1) {
perror("close() error");
return -1;
}
return 0;
}
File renamed without changes.
Loading

0 comments on commit c358925

Please sign in to comment.