Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devcontainer fails with zig build #53

Open
dierbei opened this issue Mar 6, 2024 · 25 comments
Open

devcontainer fails with zig build #53

dierbei opened this issue Mar 6, 2024 · 25 comments
Labels
good first issue Good for newcomers

Comments

@dierbei
Copy link
Contributor

dierbei commented Mar 6, 2024

I am a zig newbie and would like to try to learn.

I'm having problems compiling mewz, I run zig build with the following error. Can you help me with this? Thanks for the help.

root ➜ /workspaces/mewz (main) $ zig build
++ git rev-parse --show-toplevel
++ git rev-parse --show-toplevel
+ REPO_ROOT=/workspaces/mewz
+ cd /workspaces/mewz
+ REPO_ROOT=/workspaces/mewz
+ cd /workspaces/mewz
+ ls build/newlib/libc.a
+ mkdir -p build/lwip
ls: cannot access 'build/newlib/libc.a': No such file or directory
+ mkdir -p build/newlib
+ cd build/lwip
+ cmake ../../lwip-wrapper
+ cd build/newlib
+ ../../submodules/newlib/newlib/configure --target=x86_64-elf --disable-multilib --prefix=/usr/local/newlib-x86_64-elf
./scripts/build-newlib.sh: line 12: ../../submodules/newlib/newlib/configure: No such file or directory
run ./scripts/build-newlib.sh: error: the following command exited with error code 127:
./scripts/build-newlib.sh 
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at CMakeLists.txt:15 (include):
  include could not find requested file:

    /workspaces/mewz/lwip-wrapper/../submodules/lwip/src/Filelists.cmake


CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.25)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
See also "/workspaces/mewz/build/lwip/CMakeFiles/CMakeOutput.log".
run ./scripts/build-lwip.sh: error: the following command exited with error code 1:
./scripts/build-lwip.sh 
Build Summary: 1/6 steps succeeded; 2 failed (disable with --summary none)
install transitive failure
└─ install mewz.elf transitive failure
   └─ zig build-exe mewz.elf Debug x86_64-freestanding transitive failure
      ├─ run ./scripts/build-newlib.sh failure
      └─ run ./scripts/build-lwip.sh failure
error: the following build command failed with exit code 1:
/workspaces/mewz/zig-cache/o/7c36e40cbb2402eb80e289dd70bd7100/build /usr/bin/zig/zig /workspaces/mewz /workspaces/mewz/zig-cache /root/.cache/zig --seed 0xd3f16844
@saza-ku
Copy link
Contributor

saza-ku commented Mar 6, 2024

It looks lacking the codes of Newlib. This is registered as a submodule.

How about doing git submodule update --init?

@dierbei
Copy link
Contributor Author

dierbei commented Mar 7, 2024

@saza-ku It worked, thanks.

@dierbei
Copy link
Contributor Author

dierbei commented Mar 7, 2024

# hello_world
This is a simple Hello World program.
## How to run on Mewz
The following steps can be executed within the Dev Container.
First, build the program into Wasm.
```sh
cd examples/hello_world
# In the Dev Container, you should run `rustup target add wasm32-wasi in advance.
cargo build --target wasm32-wasi
```
Then, convert it into a native object file with Wasker.
```sh
wasker target/wasm32-wasi/debug/hello_world.wasm
```
Now you can run it on Mewz.
```sh
cd ../..
zig build -Dapp-obj=examples/hello_world/wasm.o run
```

Are the steps for using mewz like the following?

  1. use rust to build wasm

  2. use wasker conversion

  3. use mewz to run it

This looks like the wasm runtime, but a little different.

@saza-ku
Copy link
Contributor

saza-ku commented Mar 7, 2024

Yeah that's right.

The last command builds a kernel image of Mewz, then runs it on a QEMU virtual machine.

I think the entire process may not be so different from other wasm runtimes.

@dierbei
Copy link
Contributor Author

dierbei commented Mar 11, 2024

mewz is a bit hard for me, it will take me some time to learn it.

zig language is the same.

@dierbei
Copy link
Contributor Author

dierbei commented Mar 13, 2024

@saza-ku I'm having a problem developing with devcontainer and can't do code hints, code jumps.

For example, if I click on a function name, I can't jump to it. Have you encountered such a problem?

@saza-ku
Copy link
Contributor

saza-ku commented Mar 13, 2024

Have you installed https://marketplace.visualstudio.com/items?itemName=ziglang.vscode-zig ?

And it might be necessary to confirm the paths of zig and zls (https://github.com/zigtools/zls) are properly set.

(Also we need to set customizations.vscode.extensions in devcontainer.json... 😅 )

@dierbei
Copy link
Contributor Author

dierbei commented Mar 13, 2024

https://github.com/zigtools/zls

Thanks, I didn't have ZLS installed before.

Just restart VScode after installing it.

Adding some zig plugins could be better.

@saza-ku
Copy link
Contributor

saza-ku commented Mar 13, 2024

mewz is a bit hard for me, it will take me some time to learn it.

We should add more documents about the usages and the architecture.

@dierbei Please share what you learn and didn't understand if you don't mind! This information would help us to update the docs 😃

@dierbei
Copy link
Contributor Author

dierbei commented Mar 13, 2024

mewz is a bit hard for me, it will take me some time to learn it.

We should add more documents about the usages and the architecture.

@dierbei Please share what you learn and didn't understand if you don't mind! This information would help us to update the docs 😃

No problem. I'm happy to do it.

@dierbei
Copy link
Contributor Author

dierbei commented Mar 13, 2024

@saza-ku The code for the project is difficult for me and I have no knowledge of it. Don't know how to start.

Can you give me some ideas? Thanks

@saza-ku
Copy link
Contributor

saza-ku commented Mar 13, 2024

Are you trying to read and understand the codes, or add some feature?

@dierbei
Copy link
Contributor Author

dierbei commented Mar 13, 2024

Are you trying to read and understand the codes, or add some feature?

After my initial perusal of the code, I was completely unable to understand why the code was written the way it was.

This state of affairs left me feeling a bit confused, as if I had just started learning programming and I had absolutely no clue as to how to add some functionality to the mewz.

In the midst of this confusion, I felt like a novice programmer, and I felt completely directionless as to what I should do next.

next I will learn how to debug zig.

@saza-ku
Copy link
Contributor

saza-ku commented Mar 13, 2024

I see. I would tell you some hints to understand the codes.

  • We wrote these codes referring to xv6, especially about the boot process. This might be helpful: https://pdos.csail.mit.edu/6.828/2018/xv6/book-rev11.pdf
  • These codes would be divided into two parts: boot process codes and runtime codes.
    • The former is executed in boot process. First boot function in boot.S is executed and it jumps into bspEarlyInit in main.zig. At the last of bspEarlyInit, it calls wasker_main, which is the entry point of the Wasm application. The boot process might be incomprehensible if you don't have experience of writing a kernel, so I would recommend skipping it for now.
    • The latter is called from Wasm applications. Wasm applications call Mewz's codes via WASI. WASI functions are implemented in wasi.zig. So I would recommend beginning to read functions in wasi.zig. Functions annotated with export in wasi.zig are called from Wasm.

Wasm applications call Mewz's codes via WASI.

There are a few exceptions: memory_grow and memory_base. memory_grow grows the linear memory, so it's called when the Wasm executes the memory.grow instruction. memory_base (it would be difficult to understand, so you could ingnore it) returns the base address of the linear memory.

@dierbei
Copy link
Contributor Author

dierbei commented Mar 14, 2024

@saza-ku Okay, thanks.

I'll start with the wasi and I'll see if the zig can be debugged.

I haven't tried it before, and I've just been following zig recently.

@saza-ku
Copy link
Contributor

saza-ku commented Mar 14, 2024

To debug it, you can use GDB. This repository contains .gdbinit.

@dierbei
Copy link
Contributor Author

dierbei commented Mar 14, 2024

@saza-ku Indeed, the code is particularly primitive and not very well understood.

It looks like kernel code, which I've never touched before.

I was hoping to get involved, but realized there is still a lot to learn.

@saza-ku
Copy link
Contributor

saza-ku commented Mar 14, 2024

If you would like to touch the codes, how about starting with adding integration tests?

The integration tests are written in wasi.zig(L632) (also we should separate them from wasi.zig by creating another file🤒)
You can run the tests by zig build -Dtest=true run. After doing curl localhost:1234 in another teminal, you could see [LOG FATAL]: Integration test passed and the process will exit.

It could help you understand the codes through directly interacting with WASI API provided by Mewz.

@dierbei
Copy link
Contributor Author

dierbei commented Mar 15, 2024

If you would like to touch the codes, how about starting with adding integration tests?

The integration tests are written in wasi.zig(L632) (also we should separate them from wasi.zig by creating another file🤒)
You can run the tests by zig build -Dtest=true run. After doing curl localhost:1234 in another teminal, you could see [LOG FATAL]: Integration test passed and the process will exit.

It could help you understand the codes through directly interacting with WASI API provided by Mewz.

Thanks for the advice, you helped me a lot.

@saza-ku
Copy link
Contributor

saza-ku commented Mar 20, 2024

We can now pass the integration tests by only doing zig build -Dtest=true run, without doing curl localhost:1234. (#56)

We now have only tests of testClientSocket and testServerSocket.(https://github.com/mewz-project/mewz/blob/main/src/wasi.zig#L646)
We need to add a test of reading file from the filesystem. If you are interested in adding it, we welcome your PR!

@dierbei
Copy link
Contributor Author

dierbei commented Mar 20, 2024

We can now pass the integration tests by only doing zig build -Dtest=true run, without doing curl localhost:1234. (#56)

We now have only tests of testClientSocket and testServerSocket.(https://github.com/mewz-project/mewz/blob/main/src/wasi.zig#L646) We need to add a test of reading file from the filesystem. If you are interested in adding it, we welcome your PR!

Wow, that's great, maybe I'll be able to try that.

@dierbei
Copy link
Contributor Author

dierbei commented Apr 4, 2024

@saza-ku I just read your share on youtobe, haha! https://www.youtube.com/watch?v=-bCTkwvMzw8

@saza-ku
Copy link
Contributor

saza-ku commented Apr 27, 2024

How about doing git submodule update --init?

To close this issue, we might need to ensure the command is executed automatically.
We could use onCreateCommand (https://containers.dev/implementors/json_reference/#lifecycle-scripts).

@saza-ku saza-ku added the good first issue Good for newcomers label Apr 27, 2024
@dierbei
Copy link
Contributor Author

dierbei commented Apr 28, 2024

@sa Do you mean: run git submodule update --init by the way when starting devcontainer?

I got this error before because I didn't run git submodule update --init in the README. If I follow the README, I don't get this problem.

@saza-ku
Copy link
Contributor

saza-ku commented Apr 28, 2024

Yeah, but it's tedeous, isn't it? 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants