Skip to content

Commit

Permalink
fix up packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Mar 3, 2024
1 parent 185e906 commit a343277
Show file tree
Hide file tree
Showing 29 changed files with 308 additions and 332 deletions.
79 changes: 2 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## What version of Zig to use

0.11.0
Zig master/nightly

## Getting Started With MicroZig

Expand All @@ -26,8 +26,6 @@ Right now, you gotta figure out how to flash the MCU yourself, but as people say

### I Want To Contribute To MicroZig

**IMPORTANT:** Developer experience is degraded right now, and not really good. Windows isn't really a supported dev target and you got to expect some friction. [There's a project for improving DX, feel free to grab tasks from there!](https://github.com/orgs/ZigEmbeddedGroup/projects/4)

Please see the [project page](https://github.com/orgs/ZigEmbeddedGroup/projects/1/views/1), it’s used as a place to brainstorm and organize work in ZEG. There will be issues marked as good first issue or drafts for larger ideas that need scoping/breaking ground on.

More words on contribution and development on MicroZig are [further down below](#developing).
Expand All @@ -47,84 +45,11 @@ This repo contains the infrastructure for getting started in an embedded Zig pro

For MicroZig internals please see the [Design Document](docs/design.adoc).

## Developing

Right now, the developer experience is not optimal due to 0.11 not really supporting what we're doing at all.

If you want to test your changes, you gotta to the following:

**Step 1:** Install required python packages, either systemwide or via a [virtual environment](https://docs.python.org/3/library/venv.html):

```sh-session
# systemwide:
[user@host] microzig-monorepo/ $ pip install -r tools/requirements.txt
[user@host] microzig-monorepo/ $

# using virtual environments:
[user@host] microzig-monorepo/ $ python3 -m venv .venv
[user@host] microzig-monorepo/ $ . .venv/bin/activate # on linux, macos
[user@host] microzig-monorepo/ $ . .venv/Scripts/activate # on windows
[user@host] microzig-monorepo/ $ pip3 install -r tools/requirements.txt
[user@host] microzig-monorepo/ $
```

**Step 2:** Create a deployment for local usage:

```sh-session
[user@host] microzig-monorepo/ $ python3 ./tools/bundle.py --debug
preparing environment...
validating packages...
loaded packages:
* microzig-build
* examples:microchip/avr
* examples:...
* microzig-core
* microchip/avr
* ...
resolving inner dependencies...
creating packages...
bundling microzig-build...
bundling microzig-core...
bundling microchip/avr...
...
[user@host] microzig-monorepo/ $
```

This command yields output in `./microzig-deploy` that is meant to be fetched via `http://localhost:8080/`.

**Step 3:** To serve the files on this port, you can start a pre-bundled web server:

```sh-session
[user@host] microzig-monorepo/ $ python3 ./tools/demo-server.py
...
```

This way, you spawn a local HTTP server that will serve `./microzig-deploy` on port 8080 on your machine, and you can then
start fetching packages from this.

Now you can use curl to fetch the packages, or you can just create a local development project.

**Step 4:** Create a local test environment

This is basically done by unpacking an example from the `./microzig-deploy/examples` folder, and starting to test changes.
As the `build.zig.zon` has to be updated after running `./tools/bundle.py` again, there's a script that helps here:
`tools/patch-build-zon.py` can be used to patch/upgrade your development project inplace based on what it finds in `./microzig-deploy`:

```sh-session
[user@host] microzig-monorepo/ $ python3 ./tools/patch-build-zon.py /tmp/dev-project/build.zig.zon
Updating hash of http://localhost:8080/packages/microzig-build.tar.gz to 12200040a36bbbb2fe09809861f565fcda9a10ec3064d70357aa40ad0a61596c16fb
Updating hash of http://localhost:8080/packages/microzig-core.tar.gz to 122013a37ce9ac295303f26057c203e722b9ceaefa5b4403fe5a18ab065f03079e7d
Updating hash of http://localhost:8080/packages/board-support/stmicro/stm32.tar.gz to 12207c278b78c5aeb08cd7889647d7d0d9a359cb28fe68105d2e43f85dabb3865981
[user@host] microzig-monorepo/ $
```

Both compiling the local example and updating the `build.zig.zon` requires running the local development server.

## Repository structure

* `build/` contains the build components of MicroZig.
* `core/` contains the shared components of MicroZig.
* `board-support/` contains all official board support package.
* `bsp/` contains all official board support package.
* `examples/` contains examples that can be used with the board support packages.
* `tools/` contains tooling to work *on* MicroZig itself, so deployment, testing, ...
* `design/` contains images and logos
Expand Down
2 changes: 1 addition & 1 deletion bsp/espressif/esp/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/espressif/esp",
.name = "bsp/espressif/esp",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{ .path = "../../../build" },
Expand Down
2 changes: 1 addition & 1 deletion bsp/gigadevice/gd32/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/gigadevice/gd32",
.name = "bsp/gigadevice/gd32",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{ .path = "../../../build" },
Expand Down
2 changes: 1 addition & 1 deletion bsp/microchip/atsam/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/microchip/atsam",
.name = "bsp/microchip/atsam",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{ .path = "../../../build" },
Expand Down
2 changes: 1 addition & 1 deletion bsp/microchip/avr/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/microchip/avr",
.name = "bsp/microchip/avr",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{ .path = "../../../build" },
Expand Down
2 changes: 1 addition & 1 deletion bsp/nordic/nrf5x/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/nordic/nrf5x",
.name = "bsp/nordic/nrf5x",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{ .path = "../../../build" },
Expand Down
2 changes: 1 addition & 1 deletion bsp/nxp/lpc/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/nxp/lpc",
.name = "bsp/nxp/lpc",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{ .path = "../../../build" },
Expand Down
2 changes: 1 addition & 1 deletion bsp/raspberrypi/rp2040/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/raspberrypi/rp2040",
.name = "bsp/raspberrypi/rp2040",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{
Expand Down
2 changes: 1 addition & 1 deletion bsp/stmicro/stm32/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "microzig/bsp/stmicro/stm32",
.name = "bsp/stmicro/stm32",
.version = "0.0.0",
.dependencies = .{
.@"microzig/build" = .{ .path = "../../../build" },
Expand Down
16 changes: 8 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const std = @import("std");
// assert(@alignOf(i16) == 2);
// ~~~~~~^~~~~~~~~~~~~~~~~~~~
const example_dep_names: []const []const u8 = &.{
"microzig/examples/nordic/nrf5x",
"microzig/examples/nxp/lpc",
"microzig/examples/microchip/atsam",
//"microzig/examples/microchip/avr",
"microzig/examples/gigadevice/gd32",
"microzig/examples/stmicro/stm32",
"microzig/examples/espressif/esp",
"microzig/examples/raspberrypi/rp2040",
"examples/nordic/nrf5x",
"examples/nxp/lpc",
"examples/microchip/atsam",
//"examples/microchip/avr",
"examples/gigadevice/gd32",
"examples/stmicro/stm32",
"examples/espressif/esp",
"examples/raspberrypi/rp2040",
};

pub fn build(b: *std.Build) void {
Expand Down
45 changes: 23 additions & 22 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@
.version = "0.0.0",
.dependencies = .{
// packages within the monorepo so that others can reach them
.@"microzig/build" = .{ .path = "build" },
.@"microzig/core" = .{ .path = "core" },
.@"microzig/tools/regz" = .{ .path = "tools/regz" },
.@"microzig/tools/uf2" = .{ .path = "tools/uf2" },
.@"microzig/bsp/nordic/nrf5x" = .{ .path = "bsp/nordic/nrf5x" },
.@"microzig/bsp/nxp/lpc" = .{ .path = "bsp/nxp/lpc" },
.@"microzig/bsp/microchip/atsam" = .{ .path = "bsp/microchip/atsam" },
.@"microzig/bsp/microchip/avr" = .{ .path = "bsp/microchip/avr" },
.@"microzig/bsp/gigadevice/gd32" = .{ .path = "bsp/gigadevice/gd32" },
.@"microzig/bsp/stmicro/stm32" = .{ .path = "bsp/stmicro/stm32" },
.@"microzig/bsp/espressif/esp" = .{ .path = "bsp/espressif/esp" },
.@"microzig/bsp/raspberrypi/rp2040" = .{ .path = "bsp/raspberrypi/rp2040" },
.@"build" = .{ .path = "build" },
.@"build/definitions" = .{ .path = "build/definitions" },
.@"core" = .{ .path = "core" },
.@"tools/regz" = .{ .path = "tools/regz" },
.@"tools/uf2" = .{ .path = "tools/uf2" },
.@"bsp/nordic/nrf5x" = .{ .path = "bsp/nordic/nrf5x" },
.@"bsp/nxp/lpc" = .{ .path = "bsp/nxp/lpc" },
.@"bsp/microchip/atsam" = .{ .path = "bsp/microchip/atsam" },
.@"bsp/microchip/avr" = .{ .path = "bsp/microchip/avr" },
.@"bsp/gigadevice/gd32" = .{ .path = "bsp/gigadevice/gd32" },
.@"bsp/stmicro/stm32" = .{ .path = "bsp/stmicro/stm32" },
.@"bsp/espressif/esp" = .{ .path = "bsp/espressif/esp" },
.@"bsp/raspberrypi/rp2040" = .{ .path = "bsp/raspberrypi/rp2040" },

// examples so that we can build them all in one go
.@"microzig/examples/nordic/nrf5x" = .{ .path = "examples/nordic/nrf5x" },
.@"microzig/examples/nxp/lpc" = .{ .path = "examples/nxp/lpc" },
.@"microzig/examples/microchip/atsam" = .{ .path = "examples/microchip/atsam" },
.@"microzig/examples/microchip/avr" = .{ .path = "examples/microchip/avr" },
.@"microzig/examples/gigadevice/gd32" = .{ .path = "examples/gigadevice/gd32" },
.@"microzig/examples/stmicro/stm32" = .{ .path = "examples/stmicro/stm32" },
.@"microzig/examples/espressif/esp" = .{ .path = "examples/espressif/esp" },
.@"microzig/examples/raspberrypi/rp2040" = .{ .path = "examples/raspberrypi/rp2040" },
.@"examples/nordic/nrf5x" = .{ .path = "examples/nordic/nrf5x" },
.@"examples/nxp/lpc" = .{ .path = "examples/nxp/lpc" },
.@"examples/microchip/atsam" = .{ .path = "examples/microchip/atsam" },
.@"examples/microchip/avr" = .{ .path = "examples/microchip/avr" },
.@"examples/gigadevice/gd32" = .{ .path = "examples/gigadevice/gd32" },
.@"examples/stmicro/stm32" = .{ .path = "examples/stmicro/stm32" },
.@"examples/espressif/esp" = .{ .path = "examples/espressif/esp" },
.@"examples/raspberrypi/rp2040" = .{ .path = "examples/raspberrypi/rp2040" },

// used for creating package tarballs
.boxzer = .{
.url = "https://github.com/mattnite/boxzer/archive/44183569cb4418f3b127711a989ded8822869a91.tar.gz",
.hash = "1220f6fc705e2d658644c96c093ed7907f2c3091252058d6bdfdc0334965dd25d6c4",
.url = "https://github.com/mattnite/boxzer/archive/b9f08b4c9b1db709af03763ace69761a6482238c.tar.gz",
.hash = "12204fdd9914a6d99abb55366b3a664395a6038d7e6308178c0664158eff9418e188",
},
},

Expand Down
Loading

0 comments on commit a343277

Please sign in to comment.