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

Zig Template: zigConsole #94

Merged
merged 5 commits into from
Nov 8, 2023
Merged

Zig Template: zigConsole #94

merged 5 commits into from
Nov 8, 2023

Conversation

kassane
Copy link
Contributor

@kassane kassane commented Aug 21, 2023

Hi @microhobby ,

website: https://ziglang.org

Template based on v0.11.0 release-notes - uses LLVM 16.0.6.

Glossary:

  • build.zig: build-system written on zig, makefile like.
  • build.zig.zon: dependencies manager, cargo.toml like.
  • zig: toolchain
  • ziglang: language

About:

Ziglang is a new language having the purpose to be an alternative to C, not as replacement only, also as complement (easy ffi - better than using C code in C++). Zig can guarantee that C code runs with clang rules and not clang++.

$> zig version
0.11.0
$> zig cc --version
clang version 16.0.6 (https://github.com/ziglang/zig-bootstrap 1dda86241204c4649f668d46b6a37feed707c7b4)
Target: x86_64-unknown-linux-musl
Thread model: posix
InstalledDir: /usr/bin

Current Status

Today, zig has llvm-backend to build C and C++ projects (clang/clang++) in which it manages porting some libC for easy cross-compilation ( CI added by me is proof of that), so it is first class support. Except for BSDs with incomplete support and MSVC because of MS license.

Zig libc: https://github.com/ziglang/zig/tree/master/lib/libc (first class support = portability)

Zig can also move between glibc versions. It makes it possible to choose the version of glibc in the target build.
https://github.com/ziglang/glibc-abi-tool

For C++ exclusively, zig has support llvm-libcxx + llvm-libcxxabi + llvm-libunwind + custom libcompiler-rt (rewritten on zig) that are statically linked in the binaries.

https://github.com/ziglang/zig/tree/master/lib/libcxx
https://github.com/ziglang/zig/tree/master/lib/libcxxabi
https://github.com/ziglang/zig/tree/master/lib/libunwind
https://github.com/ziglang/zig/tree/master/lib/compiler_rt

I'm a C++ developer currently porting some libraries which will allow me to use zig-pkg (package manager). Something equivalent to fetchContent(cmake), that is, for non-header-only libraries would need that dependencies have cmake to be built and linked to the main project. The same applies to zig-pkg which needs to push includes and libs built before linking to the main project.

Summarizing, zig c++ build our app statically running libcxx+libunwind on almost all platforms under the same condition (C++ABI unified).

Zig is planning to not depend from LLVM. How will C++ support work?

Yes, however only version 1.0 that maybe will be released in mid 2025!

Explained here: https://youtu.be/AqDdWEiSwMM?t=2435

The zig project has always wanted to become a self-hosted toolchain making LLVM support optional, while benefiting from all the targets of this tool. However, many bugs inhibit further development of the main project (zig), which has fewer compiler developers.

Andrew Kelley has plans for zig to become not only a language and toolchain focused on the language itself, but also a new backend compiler that competes with LLVM and GCC keeping compatibility.

Roadmap: old diagram (v0.9.0)

@microhobby
Copy link
Collaborator

awesome! Let's review it, thanks for the contribution

.vscode/launch.json Outdated Show resolved Hide resolved
zigConsole/.conf/deps.json Outdated Show resolved Hide resolved
@kassane kassane requested a review from microhobby August 21, 2023 15:48
@microhobby
Copy link
Collaborator

@kassane also is needed to add the template here: https://github.com/toradex/vscode-torizon-templates/blob/dev/templates.json

The VS Code extension uses these metadata, and lists the templates when creating new projects.

@kassane kassane force-pushed the zig branch 2 times, most recently from 82cbd38 to 0b24f2f Compare August 21, 2023 16:04
@kassane
Copy link
Contributor Author

kassane commented Aug 21, 2023

@microhobby microhobby modified the milestones: v2.1.2, v2.2.0 Aug 23, 2023
@microhobby microhobby changed the base branch from bookworm to dev August 23, 2023 19:26
@microhobby
Copy link
Collaborator

Hey @kassane I took the liberty of switching to dev and running a rebase. I didn't see it on the first iteration, but everything new first goes into the dev branch.

@microhobby
Copy link
Collaborator

I'm checking here, we are missing the .vscode/ files, like the settings.json, extension.json and etc... Take a look in one of the other templates, these files are needed to install the right extensions and debugger.

@kassane
Copy link
Contributor Author

kassane commented Aug 24, 2023

I'm checking here, we are missing the .vscode/ files, like the settings.json, extension.json and etc... Take a look in one of the other templates, these files are needed to install the right extensions and debugger.

Ok. (also rebased to toradex/dev)

@kassane kassane force-pushed the zig branch 3 times, most recently from cde0f9b to d053e09 Compare August 24, 2023 12:31
@kassane
Copy link
Contributor Author

kassane commented Aug 25, 2023

@microhobby ,

After this PR, started another project since there was no docker container with latest zig (no bootstraping). So, I started running some tests.

I even suggest you see here are some of my tests:

For the main purpose of this PR it is not impaired because (cited in the issue above) ziglang projects do not have any problems during build, as they do not need libc and Debian/Alpine containers works normally.

But, still looking into the problem with libunwind in the (busybox) container.

I'll do more testing with the other containers (Debian and Alpine).

@microhobby
Copy link
Collaborator

Hey @kassane I will remove the milestone for the v2.2.0 because it's scheduled for the next week. So, we will have no time to review it and handle the fixes until v2.2.0.

@kassane kassane force-pushed the zig branch 3 times, most recently from deb48a7 to 7de1230 Compare September 29, 2023 13:54
@microhobby
Copy link
Collaborator

hey @kassane thanks for the work, I was on vacation, but I'm back. I will take a look this week

zigConsole/.vscode/launch.json Outdated Show resolved Hide resolved
zigConsole/.vscode/launch.json Outdated Show resolved Hide resolved
* new container added on dockerfile sdk
templates.json Show resolved Hide resolved
zigConsole/docker-compose.yml Outdated Show resolved Hide resolved
zigConsole/.vscode/tasks.json Outdated Show resolved Hide resolved
zigConsole/.vscode/tasks.json Show resolved Hide resolved
@microhobby
Copy link
Collaborator

@kassane thanks for the great work, we are very close to the end!

@kassane
Copy link
Contributor Author

kassane commented Oct 26, 2023

Nice! Thank you for your attention and patience.
If you have any questions, just ask!!

@microhobby microhobby added this to the v2.3.0 milestone Oct 26, 2023
@microhobby
Copy link
Collaborator

@kassane this looks good, but there is another detail. We need a way to add the pretty printer to the Debug session: https://github.com/ziglang/zig/blob/master/tools/zig_gdb_pretty_printers.py

Without this the variables look weird on the VS Code inspector

@kassane
Copy link
Contributor Author

kassane commented Oct 27, 2023

@kassane this looks good, but there is another detail. We need a way to add the pretty printer to the Debug session: https://github.com/ziglang/zig/blob/master/tools/zig_gdb_pretty_printers.py

Without this the variables look weird on the VS Code inspector

Ok. Need more scripts *.py? Zig v0.11.0 or master are stage2 only.

@microhobby
Copy link
Collaborator

Ok. Need more scripts *.py? Zig v0.11.0 or master are stage2 only.

To be honest I have no idea. I tried the configuration locally and on the remote but these do not work as expected. Do you have these working on your machine?

@kassane
Copy link
Contributor Author

kassane commented Nov 3, 2023

Without this the variables look weird on the VS Code inspector

@microhobby ,

Pretty printer not work in all and on zig is experimental.

I put scripts in my configuration and didn't see much difference.
The example added, a log print, doesn't show much. However, when adding a variable with the name torizon, the inspector gives information.

cppdbg w/ gdb

preview - print

image

LLDB

preview - print

image

References

@microhobby
Copy link
Collaborator

Ok, so I think that we have the same problem from the Rust templates #96, the LLDB works in a way that shows the variables in a better presentation but also we should figure out how to use it in the remote environment.

So, I think that we can drop the ebe3cd5 and 69f5341 and it's done

@kassane
Copy link
Contributor Author

kassane commented Nov 8, 2023

So, I think that we can drop the ebe3cd5 and 69f5341 and it's done

dropped commits

@microhobby
Copy link
Collaborator

LGTM

@microhobby microhobby merged commit ca62031 into torizon:dev Nov 8, 2023
@kassane kassane deleted the zig branch November 8, 2023 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-template Adding a new template
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants