frmdstryr has quit [Remote host closed the connection]
vegecode has joined #zig
<vegecode>
Hello everyone, question on a good way to do something I do in C a lot.
<vegecode>
I often build tables and index into them using enums. I use designated initializers to place the correct item at the correct index.
<vegecode>
With this method it is very easy to do code inspections and makes the table resilient to future code changes as the position of an item in the array will automatically be corrected.
<vegecode>
Is it possible to do something like this in Zig? I looked through the documentation at the array sections but didn't see anything like designated initializers.
<vegecode>
Of course you can use functions to initialize an array.
<vegecode>
This may be an XY type of question, to be sure.
<vegecode>
The real thing I'm trying to replace is something that uses the preprocessor...
<andrewrk>
you can do this with `const the_table = block: { ...; break :block value; };`
<vegecode>
Ahh, I actually have to go unfortunately and can't stick around to hear any responses. I will check the logs though! Thanks in advance anyone for the help, and thank you Andrew and LemonBoy in particular for being so responsive to my other issues I have filed! LemonBoy is the man (boy?)!
<vegecode>
I'm not understanding what I'm looking at there, particularly the implied part behind the ellipses. Maybe this will be enough of a hint for me to figure it out though. Thanks!
vegecode has left #zig [#zig]
ifreund has quit [Ping timeout: 250 seconds]
adamkowalski has joined #zig
<traviss>
vegecode i believe zig best practices would say that this is misusing enums. however it is very common and powerful in c for the reasons you stated. here are some related ideas. maybe this gets you close to what you want. https://clbin.com/96VDZ
<Bekwnn>
haven't really done much besides look around a bit at other people's code as far as zig metaprogramming goes. Was wondering if anyone can think of a good way to make this automatically populate from the one colorsRGB8 version: https://i.imgur.com/pmC0FHS.png
<Bekwnn>
ie if I add an 'Orange' color to RGB8, it would automatically show up without me needing to edit RGBA, RGBA8, or RGB
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 250 seconds]
<traviss>
Bekwnn, maybe store all those colors under `const AllColors = @import("Colors.zig").AllColors` in an struct as consts.
<traviss>
Then you can `inline for (std.meta.declarations(AllColors) |color, i| {...}` and create the new colors.
<traviss>
but this way you'd lost the ability to declare the individual identifiers and need to create an array to store them
<fengb>
Can you upload the text into a pastebin?
adamkowalski has joined #zig
<Bekwnn>
https://github.com/Bekwnn/Eden/tree/master/src/math top 5 files, with RGB8 being the source one for the majority of colors (but I may want to add something like "Transparent" to the RGBA8 one or other semi-transparent constants, idk
<Bekwnn>
that would be more of a nice-to-have I guess
<fengb>
I’d personally just define one set somewhere and probably have methods to transform them
<fengb>
Feels like comptime is overkill
adamkowalski has quit [Quit: Lost terminal]
<fengb>
LLVM would in-line any operations on constants anyway if you’re worried about performance
waleee-cl has quit [Quit: Connection closed for inactivity]
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #zig
_whitelogger has joined #zig
adamkowalski has joined #zig
<adamkowalski>
is there any documentation about the debug allcoator
_whitelogger has joined #zig
ur5us has quit [Ping timeout: 246 seconds]
_Vi has joined #zig
adamkowalski has quit [Ping timeout: 250 seconds]
Bekwnn has quit [Ping timeout: 240 seconds]
_Vi has quit [Ping timeout: 246 seconds]
dddddd has quit [Remote host closed the connection]
<squeek502>
andrewrk, you might want to re-test zig cc with luajit, i noticed in your stream VOD that for the successful compilation you forgot to specify CC=$CC (you just ran make by itself, which used gcc and ignored $CC); not sure if itd fail with zig cc, but worth re-testing to make sure
<ifreund>
redj: all I had to do was `CMAKE ..`, did you try that?
<redj>
ifreund: I did, and then it complained about CLANG_INCLUDE_DIRS and LLD_INCLUDE_DIRS not being set... set those successfully... and then it complained about CLANG_LIBRARIES and LLD_LIBRARIES
dddddd has joined #zig
<redj>
ah, I used -DCMAKE_INSTALL_PREFIX=$HOME/local -DCMAKE_PREFIX_PATH=$HOME/local for compiling llvm 10... using the same for compiling zig allows it to find the include/libs...
<redj>
now, it seems I'm missing lld... it said on the wiki to compile llvm and clang but no mention of lld
<andrewrk>
squeek502, thanks for the heads up! I did end up trying it again later and fixing a couple more problems
<andrewrk>
master branch now requires llvm 10
FireFox317 has quit [Ping timeout: 250 seconds]
<andrewrk>
TheLemonMan, do you think rebasing #4795 on master (with llvm 10) will solve the windows test failure?
<andrewrk>
it looks like that f128 issue that is now fixed
<mq32>
andrewrk: you said something about a blog post? is it released yet?
<andrewrk>
mq32, give it a couple hours for the CI to make available a master branch build based on llvm 10
<mq32>
okay! i'm just curious
<andrewrk>
yeah I'm going to try to coincide the blog post so that it gets in the tech news right next to the llvm 10 announcement :)
<ifreund>
> released 18 minutes ago < pretty on top of things lol
<andrewrk>
yeah well now I get to close like 8 bugs \o/
<mq32>
andrewrk: smart!
<ifreund>
hah, that's the first time i've won the race to flag the arch package as out of date
<andrewrk>
now I'm just waiting for the CI to make an llvm10-based master branch build on the download page, and for llvm 10 release announcement to make its way into tech news sites, then I'll publish the blog post
<andrewrk>
it could potentially be an exciting day today for the zig community
<ifreund>
can't wait to read the blog post, I think i'm not quite in the loop as to what llvm 10 means for zig
<andrewrk>
not much, really. just a few bug fixes. I'm capitalizing on llvm/clang's popularity to get some spotlight on the zig project
<ifreund>
smart move, zig definitely deserves more attention
<andrewrk>
maybe they fixed it though. Sylvestre responded to my llvm-dev mail pointing out the problem
<TheLemonMan>
I hope they fix that before the point release
<andrewrk>
it's fixable without a release - it's only a problem with the apt package
<TheLemonMan>
oh well, it's still waiting to be fixed
<andrewrk>
I've essentially given up on depending on llvm as a package for development purposes. spent the entire weekend compiling llvm for every target
<andrewrk>
if you want something done right you gotta do it yourself
* mikdusan
has been building local llvm for zig forever
<TheLemonMan>
that's quite disrespectful, package mantainers do a lot of (hard) work
<andrewrk>
you're right
<andrewrk>
that was disrespectful and I apologise
<TheLemonMan>
well fuck everything, my whole internet connection is slow as fuck today
<TheLemonMan>
punching the router may fix that
<andrewrk>
llvm release day is an unfortunate day for slow internet connections
<andrewrk>
damn we beat the release announcement email
jcharbon has quit [Quit: Connection closed for inactivity]
FireFox317 has joined #zig
<FireFox317>
so andrewrk, it will be clear why you added the __clear_cache compiler-rt when you publish your blog?
<andrewrk>
FireFox317, probably not, since adding that actually allowed me to delete a section from the blog post :)
<andrewrk>
__clear_cache is part of compiler-rt. it would have been added before zig 1.0 anyway
<andrewrk>
__clear_cache was the only addition needed to compiler-rt to successfully cross compile LuaJIT for aarch64-linux-gnu
<companion_cube>
reading your tweets, andrewrk: in deflate, maybe there's len + nlen just for redundancy reasons?
<FireFox317>
andrewrk, hahah ahh nice :)
<BaroqueLarouche>
Checking that the block is ok for a non-compressed block
<companion_cube>
this LiteralLengthTable could be comptime generated, couldn't it? :
<companion_cube>
:p
<companion_cube>
waiiit no
<BaroqueLarouche>
it is
<BaroqueLarouche>
there's no rule for that table
<BaroqueLarouche>
there's no rule for that table
<BaroqueLarouche>
but for the fixed huffman coding I do generate the table in comptime
<companion_cube>
yeah at first I thought it was a table of primes, my bad
<andrewrk>
companion_cube, yeah, old school compression stuff often had these. I think it was a mistake to put integrity checks in-bound. that's a job for an out-of-bound system. but people didn't understand this back then, I guess
<BaroqueLarouche>
btw the RFC for DEFLATE is so useless, that article about Zip file was so helpful
adamkowalski has joined #zig
<andrewrk>
the one by Hans Wennborg right? that's the release manager for llvm btw
<BaroqueLarouche>
Yup
<andrewrk>
yeah that article is fantastic. it took me a week to read it
<scientes>
but in terms of pre-zstd there is also 7zip/lzma/xz
<BaroqueLarouche>
Waiting to have the encoder to submit it in the std lib
<fengb>
👍
<BaroqueLarouche>
I hope JPEG will be fun to implement
<scientes>
what do we gain by implementing these things in zig?
<TheLemonMan>
good timing, do you also have an inflate implementation?
<scientes>
it seems to me it would just increase maintinance
<fengb>
andrewrk: is it possible to import variables in wasm? I couldn't figure out how to get lld to ignore extern variables
<scientes>
over just using the C
<BaroqueLarouche>
TheLemonMan: only inflate for now
<TheLemonMan>
scientes, dogfooding
<scientes>
something that would be cooler would be to implement these things with a RPC over shared memory
<scientes>
so as to protect for security problems
<TheLemonMan>
BaroqueLarouche, cool, I was about to port Zlib's puff.c to Zig
<companion_cube>
scientes: or in a sandbox, like wasm ;)
<scientes>
more like seccomp mode 1
<scientes>
wasm is just slow-box
<scientes>
not a sandbox but a slow-as-sand-box
<companion_cube>
I didn't know seccomp, it looks like capabilities?
<scientes>
companion_cube, it limits system calls
<scientes>
so you set it up, and then you turn off system calls except for futex()
<andrewrk>
fengb, I'd be happy to take a look at this with you if you can help me understand the situation
adamkowalski has quit [Ping timeout: 256 seconds]
<andrewrk>
scientes, I'm pretty sure we'll want inflate at least in the std lib because of package manager. the current plan is that the package manager's base set of "download plugins" will depend only on std lib
<scientes>
well yeah I get inflate
<scientes>
but more difficult stuff like libjpeg, I just don't see why
<andrewrk>
yeah, a lot of stuff from std lib will get deleted before 1.0, the only purpose is dogfooding as TheLemonMan said
<scientes>
ah ok
<andrewrk>
"deleted" meaning, anyone is free of course to take over maintenance and make it a third party package
<BaroqueLarouche>
yeah image support doesn't belong in std
<scientes>
BaroqueLarouche, well i'm talking about the algorithmic complexity
<TheLemonMan>
a-we-some, LLVM10 doesn't fix the other vector-related problems in #4737
<fengb>
andrewrk: ^ trying to import a global value
<andrewrk>
let me fiddle with it
<fengb>
Also I just realized we can't import memory like this. Probably need to expose lld's `--import-memory`
adamkowalski has quit [Ping timeout: 240 seconds]
<andrewrk>
for what it's worth, wasm is generally still experimental, meaning if you submit pull requests and tell me that it's an improvement, I'll believe you and merge it without vetting it too much
<fengb>
I think we need a few more users to test these things out :P
mmx870 has quit [*.net *.split]
SimonN has quit [*.net *.split]
SimonN has joined #zig
mmx870 has joined #zig
<companion_cube>
scientes: but seccomp is linux only though, isn't it?
<companion_cube>
the stdlib should at least have json and deflate, yeah, otherwise how do you do the package manager? :D
<andrewrk>
PSA: if you want your zig project listed in the "Active Open-Source Projects Using Zig" section of the 0.6.0 release notes, make sure https://github.com/ziglang/zig/wiki/Community-Projects is updated to include your project by the end of next week
marijnfs1 has joined #zig
<ifreund>
hmm, I hope I'll have something worth listing by then
<mq32>
really looking forward on the thing with libc++, then i can remove more dependencies in my pet language
<shakesoda>
there's a good chance I'll have my tinyfx wrapper public by then
<mq32>
nice!
<shakesoda>
for all, i dunno, one (including myself) people interested in gl4+zig lol
<TheLemonMan>
many vector-related errors are linked to Zig generating weird-ass layouts (eg. v4xi5)
<mq32>
shakesoda: tinyfx is an OpenGL 4 loader?
<shakesoda>
no, it's a declarative style mid-level rendering library, so you can focus on the graphics techniques you are implementing instead of the dark arts needed to make opengl do the work for you
<mq32>
ah
<shakesoda>
similar idea to bgfx and very similar api, but much smaller in scope
<mq32>
then i'm a dark magician
<mq32>
really dark magic
<mq32>
i have a nice terrain demo with a lot of grass
<shakesoda>
I won't claim it is thoroughly battle tested, but my games have been using it for a while and it really makes wrangling the GPU a lot easier
<mq32>
and a friend asked me: "how do you store the vertex data" :D
<shakesoda>
mq32: did you answer "I don't"?
<mq32>
yep ^^
<shakesoda>
that's the spirit
<mq32>
why _store_ vertex data when you can _generate_ vertex data
<mq32>
the thing runs blazingly fast on my iGPU
<TheLemonMan>
"I download if from the cloud every frame"
<TheLemonMan>
that's the right answer
<shakesoda>
we're going to get along well, it seems
<mq32>
can you link the source, shakesoda? would still take a look
<fengb>
If I add wazm, I might be motivated to make it do something
<shakesoda>
the grass scattering was completely on the cpu in lua(jit), rendered with love, heh
<fengb>
Or be a big disappointment to the community :P
<shakesoda>
for how amazingly dumb it was, it worked really well
<mq32>
shakesoda: yeah, i was trying to do a full-shader-approach
<mq32>
the cool thing is: the grass is always scattered around the camera
<mq32>
fixed-position though
<shakesoda>
mq32: i just wanted to mock my stupid idea for grass in the least appropriate tool possible
<mq32>
heh :D
<mq32>
how do you render it?
layneson has quit [Ping timeout: 260 seconds]
<shakesoda>
a billion draw calls, give or take
<mq32>
ah
<mq32>
the scene you see above is 4
<shakesoda>
later I moved it to all instancing
<mq32>
or actually, 3 draw calls
<shakesoda>
so it went from something like 10000 draw calls of the clumps to one
<mq32>
:)
<shakesoda>
it's on my near term weekend plans to do a new impl of grass that's actually decent by generating the draws/instance data in compute
<mq32>
i watched a talk on nvidia mesh shaders these days
<mq32>
this is the awesome new tech i want to have on my iGPU :D
<shakesoda>
after that screenshot all the way back in 2017 i didn't actually need grass for a long time
<mq32>
i have to learn how to use compute actually :D
<shakesoda>
yes, do!
<shakesoda>
compute is *wonderful*
<mq32>
so, properly use compute for rendering, not for computing :D
<shakesoda>
I use it for all kinds of things, but my favorites are the realtime spherical harmonics updates from the cubemap probes and the skeletal animation
<shakesoda>
the latter because doing it in compute means i was able to remove all knowledge that it's even happening from the rest of the pipeline
<mq32>
that sounds nice
<shakesoda>
big simplification, deduplicated the work when things happened in several passes, and just plain faster and easier to understand
<mq32>
i have an engine protoype lying around that is modelled after Gamestudio A8/Acknex A8
<shakesoda>
it cost some memory, but not in practice a meaningful amount
<mq32>
provides a lot of modern APIs through a simple C API
<mq32>
and i learned a lot about how to actually code an engine :D
<mq32>
afk
adamkowalski has joined #zig
<shakesoda>
oh, if you're getting into compute, definitely look into doing tiled lighting with it (i.e. tiled/clustered forward or deferred rendering - whichever is appropriate for you)
<shakesoda>
tiled forward rendering is a *lot* more practical than deferred anything on igpus
<ifreund>
andrewrk: by the way, it looks like I do need c pointers here https://paste.rs/OMg
<andrewrk>
it would be sweet if this made it onto hacker news and reddit
<andrewrk>
now I just have to figure out wtf is going on with drone CI before I get caught for saying it works with musl and the download tarball isn't caught up to master
<jwh>
heh, in the process of trying to ditch drone
<andrewrk>
it's not drone's fault, I was able to reproduce the problem
<andrewrk>
nice, it's on lobste.rs
* companion_cube
pleads guilty
<fengb>
andrewrk: where do you learn to write well?
<andrewrk>
aww thanks for the compliment
adamkowalski has joined #zig
mikdusan has quit [Quit: WeeChat 2.6]
<companion_cube>
no one put it on HN yet?
marijnfs1 has quit [Read error: Connection reset by peer]
<jaredmm>
If I have a cimport file that needs to reference a compiler_rt builtin...how would I do that?
<mq32>
andrewrk: > print(3 + 4)
<mq32>
i feel honoured :D
<andrewrk>
hahah yes thanks for that
<andrewrk>
damn I forgot to give shout outs to people who helped me when I was streaming
<squeek502>
return 3 + 4 would have also worked btw
<jaredmm>
Generate an extern function and that's all?
<andrewrk>
good to know
mahmudov has joined #zig
<andrewrk>
alright, it's hit critical mass. enjoy the media day, everyone :)
<companion_cube>
is 0.6 for today then?
<andrewrk>
no that's april 13
<andrewrk>
I'm not sure I understand your question
<companion_cube>
heh I thought you were trying to have 0.6 coincide with llvm 10, sorry
<andrewrk>
we need a couple weeks to fix bugs and work out the kinks
<andrewrk>
it would be a little risky to release immediately
<via>
man, you're at the top of hn, congrats
<andrewrk>
thanks to zig contributors! this work is just a little layer, revealing to the world what we've been slowly building up over time
<Cadey>
andrewrk: shitty idea: could you use `zig cc` as a drop-in replacement for the system compiler on something like Gentoo or NixOS?
<ifreund>
can llvm compile the linux kernel yet?
<ifreund>
well i'm pretty sure it has, but idk if it's as painless as doing it with gcc
<andrewrk>
Cadey, yes
<andrewrk>
I mean there are some follow-up issues to solve first, but the idea is fundamentally sound
<andrewrk>
the nixos clang package requires nix-specific patches, however zig cc does not need such patches on nixos
<daurnimator>
ooo, I open HN this morning and I see zig :)
<andrewrk>
media day today! enjoy
<fengb>
Good morning!
<daurnimator>
also I see we updated to llvm 10..... I need to figure out how to actually get that working :(
mikdusan has joined #zig
<daurnimator>
I've never managed to compile my own LLVM and get it working with zig
<FireFox317>
daurnimator, for me that has been a really easy task
<FireFox317>
on arch linux btw
<fengb>
How do you know if someone is running Arch? 🙃
<daurnimator>
FireFox317: cool; got instructions?
<shakesoda>
fengb: easy, they will tell you
<shakesoda>
fengb: easy, they will tell you
<FireFox317>
daurnimator, well basically cloning `llvm-project` checking out release/10.x then building llvm, clang and lld by going into the dirs, making a build dir, from the dir run `cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/dev/zig/local -DCMAKE_PREFIX_PATH=$HOME/dev/zig/local -DCMAKE_BUILD_TYPE=Release` and `make install -j(nproc)`. To build llvm you also need `-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="AVR" -DLLVM_ENABLE_LIBXML2=OFF`. When all that is
<FireFox317>
build (takes some time), you can build zig using `cmake .. -DCMAKE_PREFIX_PATH=$HOME/dev/zig/local`
<mikdusan>
adjust vars for your preferred locations: __PROJECT, __LLVM_INSTALL_ROOT, __LLVM_PRODUCT
<FireFox317>
mikdusan, ha thanks, thats why easier than my explanation xd
adamkowalski has quit [Quit: Lost terminal]
marijnfs_ has quit [Quit: Lost terminal]
FireFox317 has quit [Ping timeout: 240 seconds]
<pmwhite>
I may be wrong, but I had the impression eventual independence from LLVM was desirable, but it looks like with all the `zig cc` stuff, that's not true. How do any eventual plans with zasm fit in? Maybe that's just another option that could be used (if zasm ends up being faster, for example).
<Snektron>
hm
<mq32>
pmwhite, to my understanding, zig cc is required for bootstrapping the compiler
<mq32>
but the long-term plan is to get rid of LLVM as a compiler infrastructure and make the code generation self-hosted as well
<fengb>
LLVM will not be a part of the language spec but it’ll probably remain a part of the reference implementation
<Snektron>
`zig asm` to replace nasm when
<andrewrk>
pmwhite, my plan is for llvm+clang+lld an optional set of dependencies (either all 3 or none), which will provide things such as `zig translate-c`, `zig cc`, `@cImport`, etc. It will also be possible to build the self-hosted zig compiler without these dependencies, and it will be compliant with the zig specification, but it will have fewer backends available and the toolchain will be missing some commands
<andrewrk>
the toolchain is not part of the zig language specification. for example you don't have to implement `zig cc` to implement the zig language according to spec. it's just a nice feature that this particular zig compiler exposes
<fengb>
What's with people in general confusing language syntax with semantics? :/
<Snektron>
Trying to use zig cc to compile my os for fun
<mq32>
fengb: But "var i : i32 = 0;" is just not "int32_t i = 0;" !
<Snektron>
interesting, as clang itself was not able to
<andrewrk>
damn, I cannot reproduce the "bad alloc" from the drone ci failure outside docker
<companion_cube>
I think zig will have serious street cred as a "C replacement" the day there's also a gcc based implementation :s
<mq32>
companion_cube: which version do you mean?
<mq32>
arm-none-eabi-zig?
<mq32>
x86_64-linux-gnu-zig
<mq32>
?
<mq32>
*grin*
<companion_cube>
the second one
<companion_cube>
well, the *-*-gnu-zig family I guess
<Snektron>
hm, i just found an issue in clang
<Snektron>
Apparently inline assembly doesn't track whether its intel syntax or not