icexin / eggos

A Go unikernel running on x86 bare metal
http://eggos.icexin.com
MIT License
2.21k stars 112 forks source link

cmd/egg: build failure when specifying build path #71

Closed prologic closed 2 years ago

prologic commented 2 years ago

I tried egg build on something very simple:

(⎈ |local:default)
prologic@Jamess-iMac
Fri Aug 06 10:16:51
~/tmp/hello-eggos
 130
$ egg build .
2021/08/06 10:16:53 eggos not found in go.mod
2021/08/06 10:16:53 go get github.com/icexin/eggos
go get: added github.com/icexin/eggos v0.4.0
malformed import path "-tags": leading dash
package eggos is not in GOROOT (/usr/local/Cellar/go/1.16/libexec/src/eggos)
2021/08/06 10:18:02 exit status 1
(⎈ |local:default)
prologic@Jamess-iMac
Fri Aug 06 10:18:02
~/tmp/hello-eggos
 1
$ ls -lah
total 2.1M
drwxr-xr-x   6 prologic staff  192 Aug  6 10:18 .
drwxr-xr-x 151 prologic staff 4.8K Aug  6 10:16 ..
-rw-r--r--   1 prologic staff   80 Aug  6 10:18 go.mod
-rw-r--r--   1 prologic staff  98K Aug  6 10:18 go.sum
-rwxr-xr-x   1 prologic staff 2.0M Aug  6 10:16 hello-eggos
-rw-r--r--   1 prologic staff   73 Aug  6 10:16 main.go
(⎈ |local:default)
prologic@Jamess-iMac
Fri Aug 06 10:18:47
~/tmp/hello-eggos
 0
$ cat main.go
package main

import "fmt"

func main() {
    fmt.Println("Hello eggos!")
}
(⎈ |local:default)
prologic@Jamess-iMac
Fri Aug 06 10:18:50
~/tmp/hello-eggos
 0
$ cat go.mod
module hello-eggos

go 1.16

require github.com/icexin/eggos v0.4.0 // indirect

It might be the last 3 lines here:

malformed import path "-tags": leading dash
package eggos is not in GOROOT (/usr/local/Cellar/go/1.16/libexec/src/eggos)
2021/08/06 10:18:02 exit status 1

Bug?

icexin commented 2 years ago

Thanks for the report @prologic

Remove the current path . in the command line, and run egg build directly in the project directory. egg have bugs when specifying the build path. I will try to fix it.

prologic commented 2 years ago

That worked! Quick too!

prologic commented 2 years ago

Next question 🤣

How do I use egg run?:

(⎈ |local:default)
prologic@Jamess-iMac
Fri Aug 06 12:16:29
~/tmp/hello-eggos
 130
$ ls
go.mod  go.sum  hello-eggos  main.go
(⎈ |local:default)
prologic@Jamess-iMac
Fri Aug 06 12:16:31
~/tmp/hello-eggos
 0
$ egg run ./hello-eggos
2021/08/06 12:16:35 missing kernel file
icexin commented 2 years ago

The -k flag specifies the kernel file. In your example, you can use egg run -k hello-eggos

prologic commented 2 years ago

Ahh I see! So it's actually a "kernel" that's output. Got it!

prologic commented 2 years ago

Why not just make it the argument to egg run? e.g: egg run hello-eggos ?

icexin commented 2 years ago

Why not just make it the argument to egg run? e.g: egg run hello-eggos ?

Good suggestion!

prologic commented 2 years ago
Screen Shot 2021-08-06 at 12 39 12

it works! 🎉

We might need ways to control qemu options too like running in headless mode, etc...

icexin commented 2 years ago

You can specify qemu parameters after --, such as -- -nographic to make qemu not display the window.

The complete command is as follows

egg run -k hello-eggos -- -nographic

prologic commented 2 years ago

I hacked egg run a bit to do this:

Screen Shot 2021-08-06 at 12 57 42

Basically simplify the usage and take qemu options from QEMU_OPTS environment variable so egg run options can be egg specific only and not get confuging.

Interesting in a PR for this?

icexin commented 2 years ago

Interesting in a PR for this?

@prologic welcome!

prologic commented 2 years ago

We can also borrow some ideas from here: https://github.com/nanovms/ops/tree/master/qemu or reuse some of it's sub-packages.

prologic commented 2 years ago

Here is my branch so far https://git.mills.io/prologic/eggos/compare/main...simplify_run_test_qemu_opts

Feel free to comment there or here, I don't publish code to Github anymore 😭

icexin commented 2 years ago

Here is my branch so far https://git.mills.io/prologic/eggos/compare/main...simplify_run_test_qemu_opts

Thanks!

Feel free to comment there or here, I don't publish code to Github anymore 😭

Sorry to hear that.

We can also borrow some ideas from here: https://github.com/nanovms/ops/tree/master/qemu or reuse some of it's sub-packages.

Good! At present, the purpose of egg run is to verify the correctness of the kernel as a playground, so its feature is relatively simple, and it does not wrap the parameters of qemu too much.

What do you think? @prologic

prologic commented 2 years ago

Feel free to comment there or here, I don't publish code to Github anymore 😭

Sorry to hear that.

Yeah it's a long story, but you can read about it here (if you're curious).

We can also borrow some ideas from here: https://github.com/nanovms/ops/tree/master/qemu or reuse some of it's sub-packages.

Good! At present, the purpose of egg run is to verify the correctness of the kernel as a playground, so its feature is relatively simple, and it does not wrap the parameters of qemu too much.

What do you think? @prologic

Yeah this is why I think removing the options from egg run and egg run and putting them behind QEMU_OPTS env var makes more sense IHMO. It also simplifies how egg run and egg test actually work too.

It might (with more work) be possible to make egg run and egg test take no arguments and implicitly to some checks, run build if necessary and just automagically workout what the built kernel is.

icexin commented 2 years ago

It might (with more work) be possible to make egg run and egg test take no arguments and implicitly to some checks, run build if necessary and just automagically workout what the built kernel is.

egg test is actually run like this, it will automatically compile the unit test file, and then run it in qemu.

prologic commented 2 years ago

Shall I make egg run have the same behaviour if no argument is provided?

icexin commented 2 years ago

Maybe it is more convenient for egg run to not specify parameters, but egg run can run ISO file in addition to ELF file. I prefer to explicitly compile kernel with egg build and then run the kernel with egg run.

Maybe we can let the user explicitly specify the parameters to make egg run automatically compile the kernel before running?

prologic commented 2 years ago

See https://git.mills.io/prologic/eggos/commit/b303845646c72c4695ac1217af20cbb830e7d3b1

prologic commented 2 years ago

This works both ways now 😀

In other words egg build and egg run are behaving more like go build and go run.

You can still explicitly build and run with my branch.

icexin commented 2 years ago

In fact, it is more complicated to deal with projects without a go.mod file. egg will automatically add an import_eggos.go file to the project to import eggos when building the project, and at the same time add a dependency on eggos in the go.mod file. Therefore egg build must be in a project where go.mod exists to compile correctly.

Therefore, egg run or egg build must build a complete go module project in the temporary directory when processing a single go file to run normally.

prologic commented 2 years ago

So I can remove the fallback on the project directory name?

prologic commented 2 years ago

Done => https://git.mills.io/prologic/eggos/commit/3ea221543718089a70a02a217d79c64c1f356084

icexin commented 2 years ago

Because egg test has already compiled the package and has output file, runKernel should only run the kernel file, and the part of compiling the kernel can be put into a function separately.

In addition, the code in runTest should look like this

runKernel([]string{outfile})
prologic commented 2 years ago

Good point I'll amend that.

prologic commented 2 years ago

Fixed in https://git.mills.io/prologic/eggos/commit/6946e4482d52acc016006b14e05568e791fee7fe

icexin commented 2 years ago

@prologic thanks for your contribution. Do you mind if I merge the code into a PR and submit it to GitHub?

prologic commented 2 years ago

Absolutely not! I just don't want to host any of my own code (or forks) on Github anymore, but I will still be a happy participant of open source 😀 -- Sorry for the slightly extra work though. Btw my Gitea instance accepts Github OAuth in case that's convenience fo ryou.

Also I just tries a simple "Hello World" web server and it works!

$ egg run -p 8000:8000
...
Screen Shot 2021-08-06 at 17 08 49 Screen Shot 2021-08-06 at 17 08 59

🎉

prologic commented 2 years ago

Next thing I'm going to improve is passing signals (SIGINT and SIGTERM) from the host where egg run is being run to the guest os (egg application).

prologic commented 2 years ago

This is pretty amazing shit you've built here btw 😂 I'm loving this! Leet it up! This may very well turn out to be a really really good way of building super secure applications 👌

prologic commented 2 years ago

It reminds me of nonovms's ops project just better 🤣

prologic commented 2 years ago

=> https://twtxt.net/twt/6qxspia