hello world in C
This commit is contained in:
parent
17b173bba6
commit
00c3cbf4d7
|
@ -229,7 +229,7 @@ func (p *Process) open(fnamesP int32, flags int32) int32 {
|
||||||
case "stdout":
|
case "stdout":
|
||||||
fi = stdFD{
|
fi = stdFD{
|
||||||
ReadWriteCloser: loggerFile{
|
ReadWriteCloser: loggerFile{
|
||||||
Logger: log.New(os.Stdout, p.name, log.LstdFlags),
|
Logger: log.New(os.Stdout, p.name+" ", log.LstdFlags),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ func testWasmFile(t *testing.T, fname string) *Process {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
p.name = fname
|
||||||
|
|
||||||
ret, err := p.Main()
|
ret, err := p.Main()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -111,3 +112,7 @@ func TestStruct(t *testing.T) {
|
||||||
t.Fatalf("wanted foo.baz to be 255, got: %d", foo.Baz)
|
t.Fatalf("wanted foo.baz to be 255, got: %d", foo.Baz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCHelloWorld(t *testing.T) {
|
||||||
|
testWasmFile(t, "./testdata/helloworld.wasm")
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ include_rules
|
||||||
|
|
||||||
CFLAGS += --target=wasm32-unknown-unknown-wasm
|
CFLAGS += --target=wasm32-unknown-unknown-wasm
|
||||||
CFLAGS += --sysroot=~/code/wasmception/sysroot/
|
CFLAGS += --sysroot=~/code/wasmception/sysroot/
|
||||||
CFLAGS += -O0 -nostartfiles -Wl,--no-entry -nostdlib
|
CFLAGS += -O0 -nostartfiles -nostdlib -fvisibility=hidden
|
||||||
|
CFLAGS += -Wl,--no-entry,--allow-undefined-file=land.syms
|
||||||
|
|
||||||
: foreach *.wast |> wat2wasm -o %o %f |> %B.wasm
|
: foreach *.wast |> wat2wasm -o %o %f |> %B.wasm
|
||||||
: foreach *.c |> ~/code/wasmception/dist/bin/clang $(CFLAGS) %f -o %o |> %B.wasm
|
: foreach *.c |> ~/code/wasmception/dist/bin/clang $(CFLAGS) %f -o %o |> %B.wasm
|
||||||
|
|
|
@ -4,18 +4,11 @@ extern int close(int);
|
||||||
|
|
||||||
__attribute__ ((visibility ("default")))
|
__attribute__ ((visibility ("default")))
|
||||||
int main() {
|
int main() {
|
||||||
const char *name = "hello";
|
const char *name = "stdout";
|
||||||
char *msg = "Hello, world!";
|
char *msg = "Hello, world!";
|
||||||
int fd = open(name, 0x42);
|
int fd = open(name, 0x42);
|
||||||
int num = write(fd, msg, 13);
|
write(fd, msg, 13);
|
||||||
if (num == 0) {
|
close(fd);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
num = close(fd);
|
|
||||||
if (num == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
open
|
||||||
|
read
|
||||||
|
write
|
||||||
|
close
|
||||||
|
unlink
|
||||||
|
isatty
|
Loading…
Reference in New Issue