ChanServ changed the topic of #zig to: zig programming language | | be excellent to each other | channel logs:
sm2n has quit [Ping timeout: 265 seconds]
plumm has quit [Quit: Textual IRC Client:]
plumm has joined #zig
<plumm> Is there any way to get a writer to a byte buffer?
cole-h has quit [Ping timeout: 265 seconds]
codingstream has joined #zig
<g-w1> what type is your byte buffer?
<plumm> u8
<g-w1> you mean []u8 ?
<plumm> it'sI can use ArrayList(u8).writer() but
<g-w1> 🤔
<plumm> what
<g-w1> is it []u8 or ArrayList(u8)?
<plumm> I wanted to use a stack allocated u8 array as the backing buffer and have a writer over it, tand I know I can use an ArrayList
<plumm> sry for the confusion
teratorn_ has quit [Ping timeout: 240 seconds]
<fengb> You can use a fixedBufferStream around an existing byte slice
<plumm> mustve looked over that
<plumm> thanks
codingstream has quit [Quit: WeeChat 3.0.1]
codingstream has joined #zig
recalloc has quit [Quit: leaving]
sm2n has joined #zig
V is now known as based
based is now known as V
braket4 has joined #zig
braket has quit [Ping timeout: 260 seconds]
braket4 is now known as braket
codingstream has quit [Ping timeout: 265 seconds]
remby has joined #zig
voldial has joined #zig
knebulae has quit [Read error: Connection reset by peer]
earnestly has quit [Ping timeout: 246 seconds]
mokafolio has quit [Quit: Bye Bye!]
moka has joined #zig
moka is now known as mokafolio
cole-h has joined #zig
ur5us__ has quit [Ping timeout: 246 seconds]
leon-p has quit [Quit: leaving]
sord937 has joined #zig
aerona has quit [Read error: Connection reset by peer]
remby has quit [Quit: remby]
zenkuro has quit [Ping timeout: 252 seconds]
gracefu_ has joined #zig
gracefu has quit [Ping timeout: 265 seconds]
[wtf] has joined #zig
ironhelix has quit []
waleee-cl has quit [Quit: Connection closed for inactivity]
Bernstein has joined #zig
cole-h has quit [Ping timeout: 240 seconds]
pretty_dumm_guy has joined #zig
marijnfs has quit [Quit: WeeChat 2.8]
Falconerd has joined #zig
Falconerd_ has joined #zig
earnestly has joined #zig
Falconerd_ has quit [Remote host closed the connection]
Falconerd_ has joined #zig
<Falconerd> can I send an anon list of types to a function? eg: myFunc(.{ MyType, MyOtherType })
<ifreund> Falconerd: sure, if that function takes anytype
<ifreund> you could also make the parameter type `comptime types: []type` though if I'm not mistaken
<Falconerd> right, I was trying to get `comptime types: []type` working but to no avail. anytype works, though
<Falconerd> thanks - i'd rather use an explicit type, just not sure how to get it done yet
<Nypsie> You may need to declare it upfront if you want []type. But `comptime types: []const type` should definitely work. (Given you do give types)
motiejus has left #zig ["User left"]
<Falconerd> I get an 'array literal requires address-of operator to coerce to slice type '[]const type''
<Falconerd> which to me is a bit confusing
<ifreund> &[_]const type{i32, u33}
<Falconerd> ah right
<ifreund> you need the & to take a pointer to the array, which will then coerce to a slice
<ifreund> arrays are values in zig
ifreund1 has joined #zig
ur5us__ has joined #zig
ifreund has quit [Ping timeout: 252 seconds]
pretty_dumm_guy has quit [Quit: WeeChat 3.2-dev]
ifreund has joined #zig
ifreund1 has quit [Ping timeout: 240 seconds]
pretty_dumm_guy has joined #zig
ifreund has quit [Ping timeout: 265 seconds]
ifreund has joined #zig
[wtf] has quit [Ping timeout: 240 seconds]
ur5us__ has quit [Ping timeout: 250 seconds]
knebulae has joined #zig
[wtf] has joined #zig
xackus has joined #zig
tdeo has quit [Ping timeout: 245 seconds]
tdeo has joined #zig
v0idify has quit [Ping timeout: 240 seconds]
jokoon has joined #zig
v0idify has joined #zig
TheLemonMan has joined #zig
bibo38 has joined #zig
<bibo38> Hi everyone. Can I somehow define a panic handler in a shared library? Tried defining the panic fn, but it doesn't get invoked.
sord937 has quit [Ping timeout: 240 seconds]
<Nypsie> I believe you can only overwrite the panic handler in the root of the project. So if some application links with a shared library, its panic handler will not be invoked unless the application defines their own panic handler that simply invokes the library's panic handler.
<TheLemonMan> what does it invoke instead?
sord937 has joined #zig
<ifreund> bibo38: that should work afaik, did you remember to make your function pub?
<bibo38> ifreund: thanks ;D pub solved the issue...
<ifreund> :)
<TheLemonMan> pubs fix every problem
<mq32> TheLemonMan, i just wanted to say "thanks" for all your cool contribution :)
<TheLemonMan> mq32, thank you for the kind works, contributing to zig is my favourite pastime so far
<mq32> this is very visible :)
<fengb> Hey TheLemonMan, do you take donations?
Falconerd has quit [Quit: Connection closed]
waleee-cl has joined #zig
<TheLemonMan> fengb, nope, all the tax and misc paperwork is too much to handle
<fengb> Alright, I'll give you some more heartfelt gratitude instead
<fengb> Thanks <3
<TheLemonMan> hah that's much better
zenkuro has joined #zig
[wtf] has quit [Ping timeout: 260 seconds]
zenkuro has quit [Ping timeout: 240 seconds]
zenkuro has joined #zig
olabaz has joined #zig
<olabaz> Hi, I'm trying to build zig from source but I'm running into some issues:
<ifreund> olabaz: looks like you are missing libclang, what distro are you on?
<olabaz> debian
<olabaz> ifreund: I have: libclang1-12/unknown,now 1:12.0.1~++20210423083014+072c90a863aa-1~exp1~20210423063719.80 amd64 [installed,automatic]
<ifreund> does that come with development headers?
<olabaz> ifreund: oh maybe not there is also: libclang-12-dev
<olabaz> let me try installing that
<olabaz> ok some progress, now I'm just missing lld things.
<olabaz> I'm assuming it's this guy: liblld-12-dev
dimenus has joined #zig
<bibo38> llvm-toolchain-12 seems to be the allrounder package:
Raito_Bezarius has quit [Ping timeout: 250 seconds]
<olabaz> ah well it's working now. Thanks for the help
<olabaz> I see two output files zig and zig0. what is the purpose of zig0?
<bibo38> "This file is the entry point for zig0, which is *only* used to build
<bibo38> / stage2, the self-hosted compiler, into an object file" (
<bibo38> TLDR: It's the C++ bootstrap compiler
<olabaz> ok thanks
remby has joined #zig
<olabaz> now if I want to update I can just run `git pull` and then `cd build && make`?
<TheLemonMan> yes
Raito_Bezarius has joined #zig
cole-h has joined #zig
<bibo38> Panics seem to be limited in shared libs, which are loaded and called by C-Programs. Tried to get myself some stacktrace infos, but getModuleForAddress just hits an assertion and the ?*builtin.StackTrace parameter is empty. Is this a known issue (which i just don't find in the issue tracker)?
<TheLemonMan> "an assertion" which one?
<bibo38> i don't quite know. I just know that I get a panic inside a panic from the default panic handler in the debug build, while in the release build it doesn't show up. Nailed it down to the getModuleForAddress call using a custom panic function. Given that I have no stacktrace, I don't quite know how to debug this.
<TheLemonMan> use a debugger?
<TheLemonMan> are you running macos?
<bibo38> nope, running linux
<TheLemonMan> hmm, there are no assertions in that code path
<TheLemonMan> get a backtrace with gdb, that will surely help
<bibo38> TheLemonMan: here . Btw. thanks. Didn't expect gdb to give me such a nice and complete backtrace.
<TheLemonMan> ah shit
<bibo38> btw. zig version is 0.8.0-dev.2065+bc06e1982
<TheLemonMan> since you're not using the startup code there's no-one filling in the aux vector in elf_aux_maybe
<TheLemonMan> the error is an integer underflow in Process.getBaseAddress
<bibo38> ah, ok. Is there some handy function to call at library init? Or does it need to be invented?
<TheLemonMan> a quick workaround is adding -lc and linking against libc
<TheLemonMan> the root cause is the same of #4524, add a comment there and cc me
<bibo38> wonderful, thanks a lot💕. I'll add the comment.
<bibo38> side question: is it allowed to strip zig binaries with `strip`? Looks like `--strip` doesn't strip everything as the `strip` cmd gets the executable a bit smaller.
<TheLemonMan> --strip omits the debug info, `strip` is also removing many more sections that are not really needed
gracefu_ has quit [Ping timeout: 252 seconds]
gracefu_ has joined #zig
pretty_dumm_guy has quit [Ping timeout: 268 seconds]
<bibo38> TheLemonMan: You're LemonBoy on GH, right? Btw. is it also an issue, that a ReleaseSafe build doesn't throw the second panic (maybe optimized the integer underflow away?)? Or is it intended?
<TheLemonMan> bibo38, yep
<TheLemonMan> it should trigger a panic anyway, can you place a gdb breakpoint on Process.getBaseAddress ?
<bibo38> `b std.process.getBaseAddress` doesn't seem to trigger.
<bibo38> *doesn't trigger
jokoon has quit [Quit: Leaving]
<bibo38> TheLemonMan: Added both issues as a comment including sample code to reproduce the bugs.
Akuli has joined #zig
<ifreund> ugh, why doesn't zig fmt allow a single line switch
<TheLemonMan> thank you bibo38, I'll have a look at that soon
<marler8997> andrewrk, regarding proposal 8642 that it looks like you created
<marler8997> wouldn't the same logic apply to fieldParentPtr that you're applying to offsetOf?
<andrewrk> why? fieldParentPtr does not leak layout details
<marler8997> you can derive offsetOf from fieldParentPtr
<andrewrk> a compiler implementation would not be forced to choose a layout when analyzing fieldParentPtr however it would for offsetOf
<andrewrk> how so?
<marler8997> offsetOf = ptr - fieldParentPtr(...)
<andrewrk> that only works at runtime
<marler8997> right, is this only a comptime restriction then?
<andrewrk> hmm that's a good point, the proposal could be amended to say that it returns a runtime value rather than comptime
<marler8997> is that possible?
<andrewrk> what do you mean?
<marler8997> to force a value to be runtime?
<marler8997> I suppose it's a builtin so you can do whatever you need to
<marler8997> I had a similar idea to force a string to only be known at runtime, even though it was a string literal
<marler8997> but I didn't know of a way to do it in a library
<ifreund> That also makes me wonder why we have both @offsetOf() and @fieldParentPtr(), one can be implemented in terms of the other
<andrewrk> the compiler would not force the struct layout and return a runtime integer. it would emit an instruction that got lowered at the final stage of compilation
<marler8997> interesting
<marler8997> ifruend, I may have made an issue for that already
<ifreund> I may have seen that issue already :D
<marler8997> lol, yeah you're the 2nd commentor :)
<andrewrk> @fieldParentPtr is friendlier to comptime code execution. maybe with more sophisticated analysis a userland implementation could work correctly but that's definitely not true for stage12
<andrewrk> *stage1
<andrewrk> alright hang on I'm typing up 1 more issue then will organize all this stuff
<ifreund> looks like elanor beat you to it :D
leon-p has joined #zig
bibo38 has quit [Quit: Connection closed]
cole-h has quit [Ping timeout: 265 seconds]
<andrewrk> ifreund, are you planning to attend the stage2 meeting today? would be nice to chat about 8638
<ifreund> andrewrk: sure! is it in 1 hour or 2 hours from now?
<ifreund> I can never keep it straight
<andrewrk> 2 hours from now
<andrewrk> I didn't expect the default build/install directory to be so tricky, but it is
<andrewrk> it's also a really important default to get right
<ifreund> definitely
<andrewrk> I am convinced that the correct default build step is "install"
<andrewrk> beyond that I think is a puzzle
<ifreund> I agree with you that "install" is the right default, the question is just where to install
<andrewrk> whenever I come back to the issue fresh, I am taken aback that the cwd matters
<ifreund> I'm kinda liking my idea to require that to be explicit in all cases
<ifreund> it feels like it fits with the zig ethos
<andrewrk> that would not be a problem with my workflow, but I am considering the user experience of all the first-time zig users who type `zig build` for the first time (probably in someone else's project), not really knowing or caring what it does
daex_ has joined #zig
daex has quit [Ping timeout: 252 seconds]
<ifreund> fair, I've also considered making the default configurable in the build.zig
<andrewrk> I'm sure we can come up with a satisfactory solution today
<marler8997> I vote for $CWD/install
<andrewrk> what's the reasoning behind $CWD?
<marler8997> none whatsoever
<marler8997> build_root/install just as fine for me :)
<andrewrk> I think I have a sound argument for ignoring cwd
<mikdusan> zig-cache lands adjacent to build.zig file; my vote is `zig-install` right beside `zig-cache`
<marler8997> I can get behind that
<andrewrk> the zig- namespace is polite. it acknowledges that a project does not revolve around zig
<lemmi> shouldn't things rather land in some thing like bin/lib?
<lemmi> install is weird
<marler8997> on windows, .exe and .dll need to be in the same directory
<marler8997> this is just a default though, for systems that seperate bin/exe, I imagine you could specify that
<ifreund> lemmi: inside the prefix there would be bin and lib subdirectories on unix-like systems
<ifreund> apparently windows is weird though
<lemmi> ah, this is the prefix
<mikdusan> I assumed (maybe incorrectly) that on non-windows we could have `zig-install/{lib,bin}/` style and windows `zig-install/` style as defaults?
<ifreund> yeah, this is the same thing you can point at /usr to install things system-wide
<mikdusan> err first one is *nix
<lemmi> i can get behind this
<marler8997> I think that was one of the other questions, whether to have windows/posix diverge
<ifreund> we already do this, but the default prefix is the local zig-cache which is werid
<marler8997> I think it would be simpler if we just install everything to the same directory by default, and then provide an option to split up bin/lib files
<marler8997> otherwise all your scripts and documentation will have to say things like "run zig-install/foo on windows, and zig-install/bin/foo on posix"
<zenkuro> hay, is there any specific channel for discussing package manager? since I dont see many updates on github issue page
<ifreund> marler8997: I don't like that, as then you can't just point your prefix at /usr to install system-wide, you have to toggle some other option as well
<ifreund> zenkuro: the package manager is not in active development, the focus is on the stage2 compiler
<ifreund> there are some people working on unofficial package managers of course, but they mostly hang out on discord
<marler8997> Installing files like that system-wide doesn't seem like a good idea to me
<marler8997> though I know it's a common practice
<ifreund> marler8997: I don't install stuff manually system-wide, I use ~/.local as my prefix
<mikdusan> if we don't follow platform patterns then runtime search path for .so is going to be an issue. when {lib/,bin/} is used, exe can be encoded with relative runtime path
<ifreund> same idea though
<marler8997> mikdusan, sure for some platforms, that doesn't do anything for my platform (Nix)
<zenkuro> ifreud: many thanks, I will check discord then
<marler8997> --prefix=/usr --bindir=bin --libdir=lib
<ifreund> marler8997: I think you're certainly right that we need to be able to set bindir/libdir manually, we can't right now afaik
<marler8997> another idea is to support platform install zig configuration defaults?
<ifreund> sounds messy and complicated :/
<marler8997> yes, but it would be opt in
<marler8997> like, /etc/install.conf
<ifreund> most other build systems treat installation differently from just compiling (e.g. meson by default just dumps everything in the root of the build dir if install isn't specified, but uses bin/, lib/, etc when installing)
<andrewrk> I think it's a tricky problem, the different conventions per system. because it relates to how you are going to distribute your software. if you really are going to ship a .zip file for windows users, then you want to be testing on windows, with the same install dir structure
<andrewrk> e.g. your code is presumably going to look for its assets in some system-specific way in that case
<andrewrk> for zig, we actually just have code that supports a few different install layouts that includes both the windows way and the unix way, and we do ship different layouts in tarballs and zip files
ifreund has quit [Ping timeout: 252 seconds]
ifreund has joined #zig
<olabaz> is there a way to embed a file in a zig exe?
<ifreund> olabaz: @embedFile()
<marler8997> maybe we use the bin/lib structure, but on windows, we deploy .dll files to bin?
<ifreund> that's a good thought
<olabaz> ok thanks
<marler8997> zig-install/bin/{exe's/dll's} and zig-install/lib/{so's}
<ifreund> I kinda like zig-out more than zig install
<ifreund> also sounds like a funky dance move :D
<andrewrk> 🎶 tell me what you want, what you really really want 🎶
<mq32> i want my zig-cache back!
bibo38 has joined #zig
<mq32> andrewrk: the proposal for making offsetOf compile errors is interesting
<mq32> because i figured that zig is actually allowed to delete fields from `struct`
<mq32> when it's never read
<marler8997> what's the reasoning behind not allowing offsetof to be known at comptime? It's still known at comptime isn't it?
<mq32> marler8997: you can delete fields from structs then when they are not required
<andrewrk> marler8997, no, the compiler wants to wait and see if it can delete fields, re-order fields, etc
<mq32> which is super-cool
<mq32> problem is that @sizeOf has the same problem
<mq32> (deleting fields modifies the size)
<marler8997> true, how would you deal with @sizeOf?
<marler8997> also affects @alignOf
<marler8997> I suppose you could make those runtime known as well?
pretty_dumm_guy has joined #zig
<ifreund> I think they return the maximum size/align
<mq32> which is a horrible idea if we are allowed to delete fields :D
<marler8997> So @maxSizeOf is comptime known, @sizeOf is runtime known
<marler8997> interesting ideas for sure, sounds like there's still thing to think about
<mikdusan> ifreund: re: zig-out; my script to build zig is call `zbout` and to build llvm is `lbout`; `out` is so short and sweet
<andrewrk> the nice thing is that we can make some firm decisions based on sound principles and then let those firm decisions guide the rest of the more squishy questions
<mq32> andrewrk: do we have the value status "link time known"?
<mq32> C has this and it's used quite often in embedded
<karchnu> I saw 2 issues on github about the event loop design, I guess this is still very much WIP? Abstracting kqueue and epoll (let alone the windows version) sure sounds like a massive work
andrewrk has quit [Ping timeout: 240 seconds]
cole-h has joined #zig
<ifreund> yep, still very much WIP
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<g-w1> will all these new proposals needed to be added to stage1 also?
<g-w1> or can they not be if they are not used in stage2?
<g-w1> i guess the ones blocking stage2 will have to be implemented in stage1 :(
marijnfs has joined #zig
gpanders has quit [Ping timeout: 240 seconds]
gpanders has joined #zig
carldd has quit [Quit: The Lounge -]
carldd has joined #zig
andrewrk has joined #zig
sord937 has quit [Quit: sord937]
gpanders has quit [Ping timeout: 268 seconds]
gpanders has joined #zig
recalloc has joined #zig
codingstream has joined #zig
codingstream has quit [Quit: WeeChat 3.0.1]
<remby> any update on regex?
<marijnfs> what happens if you give the wrong type of frame to a anyframe->T
<andrewrk> ifreund, what's the idea behind the fs.path.resolve in resolveInstallPrefix?
<andrewrk> ah I think I understand
<andrewrk> otherwise it will be relative to cwd, and the build.zig may want to inspect that value
<andrewrk> right?
ur5us__ has joined #zig
remby has quit [Quit: remby]
dimenus has quit [Read error: Connection reset by peer]
pretty_dumm_guy has quit [Quit: WeeChat 3.2-dev]
pretty_dumm_guy has joined #zig
<ifreund> andrewrk: yeah that's right
<ifreund> what do you think about removing the ability to override for now pending futher build system changes?
<andrewrk> I support that
<andrewrk> either way, your call
<ifreund> We also don
<ifreund> We also don't have a strong use-case for the feature yet that can't be worked around, I think I'll remove it for now
klltkr has joined #zig
<andrewrk> sounds good
<g-w1> the only use case i heard was not having to use a shell script to provide --prefix every time which was not that convincing to me
<ifreund> yeah, that's not a good enough reason
<andrewrk> everyone needs to know about ctrl+r in the shell, total game changer
<g-w1> yep!
<ifreund> ctrl+r is nice, so is autosuggestions
<ifreund> if they just pop up automatically, you don't have to remember to use ctrl-r :P
<g-w1> i used zsh, but switched to bash out of not wanting to configure stuff
Akuli has quit [Quit: Leaving]
klltkr has quit [Quit: Textual IRC Client:]
remby has joined #zig
remby has quit [Quit: remby]
nvmd has joined #zig
codingstream has joined #zig
bibo38 has quit [Quit: Connection closed]
<g-w1> ooh, is stage2 test runner coming?
remby has joined #zig
remby has left #zig [#zig]
<andrewrk> you betcha
<andrewrk> outta the way! stage2 coming through!!
gazler_ has quit [Ping timeout: 252 seconds]
<andrewrk> trying to figure out how to encode comptime struct fields in ZIR
<andrewrk> can add another bit but then will waste 1 bit per field
<andrewrk> got it
<g-w1> how?
<andrewrk> mm it was a bad idea because it would be problematic later. idea was: `field_type == Ref.unreachable_value` means comptime field. the default_vaule will be provided, and coerced to the field type. Use that type to determine the field type.
<andrewrk> won't work because a field init expression is allowed to observe its own field type
<andrewrk> just gonna bump up from 2 bits to 4 bits for each field and use 1 of them, and leave 1 unused per field
gazler has joined #zig
<g-w1> ahh
ur5us_ has joined #zig
ur5us__ has quit [Remote host closed the connection]
pretty_dumm_guy has quit [Quit: WeeChat 3.2-dev]
<andrewrk> side note, I think I grew enough as a programmer this last couple years to actually write a competitive -OReleaseFast allocator 😎