ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #zig
laaron has quit [Remote host closed the connection]
laaron has joined #zig
a_chou has joined #zig
a_chou has quit [Remote host closed the connection]
a_chou has joined #zig
<Snektron> anyone online using mac?
<Snektron> I ran into an issue where File.stat is causing an integer overflow because of the limited precision of timespec on arm, yet i noticed darwin's timespec values are defined in c_long - 32 bit
<Snektron> so i think the problem should occur there too
<torque> iirc apple hfs+ timestamps are measured in seconds
<Snektron> shouldn't matter, tv_sec is multiplied by ns_per_s which causes an overflow if tv_sec > 2
<torque> ah
<Snektron> In any case, the fix i applied should also fix it for darwin
mq32 has quit [Ping timeout: 272 seconds]
<Tetralux> Can someone else confirm this
<Tetralux> Make an ArrayList,
<Tetralux> ArrayList(?usize)
<Tetralux> Add an entry to it that is non-null.
<Tetralux> Does this panic: var idx = list.popOrNull() orelse @panic("");
<Tetralux> (Basically, I have a suspicion that orelse unwraps twice.
kristoff_it has quit [Ping timeout: 245 seconds]
mq32 has joined #zig
a_chou has quit [Remote host closed the connection]
a_chou has joined #zig
laaron has quit [Remote host closed the connection]
laaron has joined #zig
darithorn has quit [Read error: Connection reset by peer]
a_chou has quit [Quit: a_chou]
a_chou has joined #zig
a_chou has quit [Ping timeout: 250 seconds]
a_chou has joined #zig
a_chou has quit [Quit: a_chou]
cgag has joined #zig
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #zig
LargeEpsilon has joined #zig
abbiya has joined #zig
LargeEpsilon has quit [Read error: Connection reset by peer]
LargeEpsilon has joined #zig
avoidr has quit [Quit: leaving]
alexander92 has joined #zig
<alexander92> hm guys, how to install zig easily: both downloading a binary and building from source seem to require installed llvm
<alexander92> which i seem to have(llvm-8)
<alexander92> but not sure how to hint it to zig
<bgiannan> alexander92, under linux i just had to download the binary, i don't have llvm
laaron has quit [Remote host closed the connection]
laaron has joined #zig
<alexander92> strange: i do ti
<alexander92> it
<alexander92> and i try to zig build examples/cat/main.zig
<alexander92> (an example from the repo): and i get an error in searching for llvm
<gonz_> alexander92: While I don't think it's the important part of what's going wrong, `zig build` should be used with a `build.zig` file and if you want a binary to be created from a single source file, you use `zig build-exe`.
<alexander92> ah thanks
<bgiannan> alexander92, are you sure your zig commands points to the downloaded binary and not some other one?
alexander92 has quit [Ping timeout: 272 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #zig
cgag has quit [Ping timeout: 248 seconds]
kristoff_it has joined #zig
walac has quit [Ping timeout: 252 seconds]
walac has joined #zig
laaron has quit [Remote host closed the connection]
laaron has joined #zig
marijnfs has joined #zig
occivink has joined #zig
<Snektron> alexander92: try ldd zig to see what llvm libraries you are missing
samtebbs has joined #zig
<bgiannan> does that notation actually works? `var more_points = [_]Point{makePoint(3)} ** 10;`
<bgiannan> i'm doing the same thing and zig is complaining it only got 1 item
<samtebbs> That should work as long as `makePoint(3)` is comptime known
<samtebbs> What's the error?
<bgiannan> ah it must be it my makePoint equivalent has an allocator as parameter
<bgiannan> how do i initialize my array then?
<samtebbs> What do you want each item to be?
<bgiannan> struct with one member needing to be allocated
<samtebbs> Do you have the source handy?
<samtebbs> If it absolutely requires an allocator then I'm not sure if you can do it at comptime
<bgiannan> i did not want to use an ArrayList because i know at comptime the size of the array
dewf has joined #zig
<bgiannan> actually it works
<bgiannan> my syntax was off
<bgiannan> still is
<bgiannan> it's 2d array:
<bgiannan> var grid: [][]const Self.Cell = [_][height]Self.Cell{
<bgiannan> [_]Self.Cell{Self.defaultCell(allocator)} ** height
<bgiannan> } ** width;
<bgiannan> error: expected type '[][]const src.level.Cell', found '[80][48]src.level.Cell'
<bgiannan> but if i do [width][height]Self.Cell.... i get `found [1][48]src.level.Cell`
<samtebbs> Set the type to `[width][height]const Self.Cell`
<bgiannan> got it
<samtebbs> The const may need changing too but try that first
<bgiannan> how can i convert that 2d array to a 2d slice?
<samtebbs> `grid[0..]`
<bgiannan> expected type '[][]const src.level.Cell', found '[][48]src.level.Cell'
<bgiannan> the second dimension needs also 0.. notation i guess
<samtebbs> Oh of course the 2d-ness means you can't do `[0..]`...
<samtebbs> Someone with more experience of slices will have to help
<bgiannan> ok i managed to do it
<bgiannan> the first dimension is an array, the second a slice
<bgiannan> then i just have the first dimension to convert to a slice
alexander92 has joined #zig
<mq32> brainfart: is anyone here open for real multi-dimensional arrays (with support for multi-dim slices)?
<bgiannan> after what i had to write just to initialize a 2d slice, yes
<mq32> so something like "var chessField : [8,8]?Piece;"
laaron has quit [Remote host closed the connection]
<mq32> "var topLeft : [,]?Piece = chessField[0..4,0..4]";
laaron has joined #zig
<Snektron> bgiannan: grid[0..][0..]
<bgiannan> Snektron, that doesn't work
<Snektron> it doesn't?
<mq32> Snektron, that does select the first row
<Snektron> oh wait, i see what you mean
<mq32> ah no, it's a syntax error
<Snektron> well its pretty logically that you cant do that actually
<Snektron> you'll first need to create an array of slices and then take a slice to that
<Snektron> alternatively you could store everything in a single array and manually calculate. Thats what i usually do
rivten has joined #zig
<Snektron> You could pretty easily create a KD array and KD slice
<mq32> Snektron, afaik that's the only possible way to do in most languages
rivten has quit [Remote host closed the connection]
rivten has joined #zig
<rivten> hey everyone ! i've got a very quick question : does any know how I can build a DLL on windows in 32-bit ? not 64. Basically, the only arch I can find in builtin is x86_64 which, I think, is 64-bit DLL...
<mq32> afaik the win-i386 target is broken
<rivten> yeah I tried i386 but got LLVM complaining at me :(
<rivten> Well, too bad for me :p I guess I'll try to find the issue on github and follow it. Thanks for the quick response though ;)
<mq32> hm
<mq32> seems to work though
<mq32> hm
<mq32> nope
<rivten> on my side I get a "error: unknow token in expression" from LLVM (and this points to a ])
<mq32> yeah it looks like it doesn't understand hex notation
<Snektron> could always use something like that
<mq32> yeah
<mq32> but it would break if you leave the safe space of "everything is my own code"
<mq32> also 2D slices must be more complex than your example (would require arbitrary subslicing for ranges)
<Snektron> thats true
<bgiannan> huh but i could just store everything in one dimension
<Snektron> You'll need to store the backing array's dimensions
<mq32> bgiannan: for 2D slices you need to store slice width/height, a start pointer and the actual array stride
<mq32> would be really cool if we had 2D slices, would make a lot of stuff much easier (like image processing)
<Snektron> All functionality to implement it in userspace is there
<Snektron> You're just missing [] syntax really
<Snektron> i guess a range type could be useful for this. It could behave similarly to a slice where its just a struct { lower: usize, upper: ?usize };
<rivten> mq32 : what made you say "nope" afterwards ? :p because indeed from godbolt this seems to work
abbiya_ has joined #zig
laaron has quit [Remote host closed the connection]
abbiya has quit [Ping timeout: 268 seconds]
abbiya_ is now known as abbiya
laaron has joined #zig
abbiya_ has joined #zig
abbiya has quit [Ping timeout: 272 seconds]
abbiya_ is now known as abbiya
<mq32> rivten, godbolt only compiles an object file, but does not link
<mq32> and it seems like the upstream version of zig (from the download page) still fails to compile
ntgg has joined #zig
<mq32> Snektron, yeah i know that i can do this in user space without problems
<mq32> also my point is not that i'm missing [], but standardization
<mq32> (and the need to copy-paste for every nth-dimension i need because we can't do this with comptime)=
knebulae has quit [Quit: Leaving]
SimonNa has quit [Ping timeout: 272 seconds]
SimonNa has joined #zig
knebulae has joined #zig
SimonN has joined #zig
SimonNa has quit [Ping timeout: 244 seconds]
<Snektron> you can do the last part too, albeit with some workarounds
<mq32> ah yeah
<mq32> i can go another abstraction layer
<Snektron> you can take a comptime []usize for the dimensions
<mq32> and use array parameters
<Snektron> it would be nicer if there was some kind of way to make varargs of a specific type
<mq32> comptime L : comptime_int, dimensions : [L]usize
<bgiannan> if i have this slice `[]const *MyStruct` shouldn't i be able to modify members of MyStruct ?
LargeEpsilon has quit [Quit: Leaving]
AlexisC has joined #zig
AlexisC has quit [Quit: WeeChat 2.4]
wooter has joined #zig
<samtebbs> bgiannan: Nope, it's const
<bgiannan> does non-const slices exist?
dewf has quit [Ping timeout: 245 seconds]
abbiya has quit [Quit: abbiya]
<mq32> samtebbs: why is the data pointed to const? in my reading, this is a "A slice of const pointers to non-const MyStruct"
<bgiannan> ^ mpq32, my thought exactly
<samtebbs> mq32, bgiannan: Yep you're correct, I misplaced the asterisk
<bgiannan> so i have a `[]const *Self.Cell` and when i try to modify one of the cell like so: `for (self.grid) |*cell| { cell.*.light = light; }`, zig gives me this error: `cannot assign to constant`
<samtebbs> In this case cell must be the const. Could you paste the full error?
ntgg has quit [Ping timeout: 268 seconds]
<Tetralux> bgiannan: Non-const slices do exist btw :p
<Tetralux> They're what you normally use.
<bgiannan> samtebbs, https://0x0.st/z4ju.zig
<bgiannan> Tetralux, how do you initialize a non-const slice?
<Tetralux> They're what you normally use.
<Tetralux> whoops wrong chat
<Tetralux> bgiannan: var x = [_]u8{...}; var s = x[0..];
<Tetralux> Or allocate it.
<bgiannan> huh i did that
<bgiannan> and zig said i was giving a const slice
<Tetralux> I suspect it has something to do with how you did.
<bgiannan> i guess
<bgiannan> `([_]*Self.Cell{&Self.defaultCell(allocator)} ** (width * height))[0..]`
<fengb> You need to assign the array somewhere
<fengb> Otherwise you’re slicing a literal, which zig interprets as a const
<samtebbs> bgiannan: Looking at the docs it does seem possible to assign to the iterator variable, so `light` must be constant within the struct.
<bgiannan> fengb, pulling out the array enables me to have a non-const slice, thx!
<bgiannan> samtebbs, no the light field is not constant
<bgiannan> it's optional however
<Tetralux> I believe the idea is that when you see 'var', it means "this creates storage on the stack for the thing I am assigning to it"
<Tetralux> It may be copied in, or may be directly written in.
<Tetralux> But either way, it's stored in the var.
<Tetralux> Meaning that if you don't have it, the you cannot mutate it.
<Tetralux> .. since it'll be comptime evalutated if it can, and put in the static segment.
<Tetralux> I believe that's how that works.
GiovaniAbel has joined #zig
alexander92 has quit [Ping timeout: 258 seconds]
<Snektron> Does nakedcc automatically generate a return instruction?
ntgg has joined #zig
laaron- has joined #zig
<samtebbs> Snektron: It does, set the return type to "noreturn" to not generate one
laaron has quit [Remote host closed the connection]
<Tetralux> I still don't understand how a function cannot return.
<Tetralux> It seems so alien xD
<Tetralux> "The kernel does something" is about all I've got.
<samtebbs> It's good for a kernel's entry symbol since you don't want to be going back to the bootloader
<Tetralux> I guess you just fall off the end of the function and keep going... except I wonder how the entry point for a program works.
<Tetralux> The kernel put a runtime longjmp after the function or something?
<Snektron> samtebbs: no i want it to return, just not sure
<Snektron> i think that should be correct
alexander92 has joined #zig
<gonz_> alexander92: Did you manage to get it compiling?
<gonz_> bgiannan sent this right before you disappeared: 09:42:36 <bgiannan> alexander92, are you sure your zig commands points to the downloaded binary and not some other one?
FireFox317 has joined #zig
<FireFox317> So cool to see 'clashos' working on a physical raspberry pi 3b!
<alexander92> hey, thank you gonz_ i did
<alexander92> i wrote a simple program in zig
<alexander92> i might play more with it later after work
rivten has quit [Remote host closed the connection]
FireFox317_ has joined #zig
FireFox317 has quit [Ping timeout: 245 seconds]
<samtebbs> Tetralux: where would you jump to though? :)
<gonz_> alexander92: Great. :)
<Snektron> Tetralux: remember that a kernel has a notion of processes. When a program ends the process simply ends
<Snektron> the program ends by calling an exit syscall usually, at which point i'd guess the process is just removed from the list of active ones
<Snektron> if the exit syscall isnt called it will just continue trying to execute the memory after the _start function which will probably soon result in a fault
<ntgg> why does this segfault? https://bpaste.net/show/cYLD
wooter has quit [Quit: Leaving]
<ntgg> I'm building on the latest master
<ntgg> the traceback says the return is where it happens
tyler569 has quit [Ping timeout: 258 seconds]
<FireFox317_> ntgg: You have to 'try' allocStruct because it can fail
<FireFox317_> However a segfault is always a bug in the compiler
rappet has quit [Quit: -]
rappet has joined #zig
<ntgg> the try allocStruct isn't the issue
<andrewrk> a segfault in the compiler is always a bug in the compiler. a segfault in zig code at runtime is not necessarily a bug in the compiler because zig is not memory safe
<ntgg> It's not a segfault while compiling
<samtebbs> segfault while testing?
<ntgg> yeah
rappet has quit [Ping timeout: 252 seconds]
rappet has joined #zig
laaron- has quit [Remote host closed the connection]
<Tetralux> samtebbs: I mean yeah - but the kernel needs a way to know when the program ends. Like, you could have the program jump to some code that marks itself as finished, but that might be a security issue.
tyler569 has joined #zig
<andrewrk> mq32, what's this about the source tarball from the download page not working?
<samtebbs> Tetralux: Oh I'm talking about the kernel's entry point, rather than a program's
laaron has joined #zig
<samtebbs> Snektron is right in saying that a program will call a syscall when it's finished
<samtebbs> What type would I give to a parameter if I want to pass it the result of an import?
<samtebbs> If I have `const foo = @import("foo.zig"); fn use_foo(bar: ?) {}`, I would like to call use_foo with foo.
<kristoff_it> samtebbs: `var`? :D
<mq32> andrewrk, just the known problem with i386-windwos
<andrewrk> ah ok
<mq32> Tetralux, Linux kills programs by making a syscall (interrupt + number in register)
<mq32> if that syscall is "exit(exitCode)" the program will be terminated
<mq32> so there is a jump into a code not known to the program itself (the interrupt handler)
<mq32> just imagine this like a task switch with no switching back
<ntgg> If I move the Union{ .Struct = s } to outside of the function it works correctly
ntgg has quit [Quit: Lost terminal]
<Snektron> why is the target passed to zig with -target and not --target?
<Snektron> but strip is --strip
<andrewrk> Snektron, copying existing flags for other programs, rather than trying to be consistent about - or --
ntgg has joined #zig
<Snektron> it seems more inconsistent to me now
<Snektron> oh wait i read that wrong
<andrewrk> the CLI flags are pretty unstable at this point. don't worry, closer to 1.0 we can do a pass and organize everything
<Snektron> I need a global read from the auxv. for the arm stuff. Where should i initialize that?
<andrewrk> Snektron, is this something that belongs in std/special/start.zig?
<Snektron> the method to retrieve the thread pointer depends on HWCAP from the auxv
<Snektron> So i guess?
<Snektron> I can also just put hwcap in linux.zig and initialize it alongside elf_aux_maybe
<andrewrk> what std lib function is this for?
<andrewrk> getCurrentId?
<Snektron> No, its actually a funciton to retrieve the current thread pointer
<Snektron> like the opposite of what setThreadPointer does
<andrewrk> this is new code? not trying to get existing code to work with arm?
<Snektron> on arm its a pseudoinstruction which llvm emits as a call to __aeabi_read_tp and expects libc to provide that. Theres an option in llvm to emit it directly like on other platforms, but that depends on some subfeature setting or whatever its called
<andrewrk> what std lib function is this for?
<Snektron> Im just trying to improve arm32 support, like i said. If there is a thread local in a zig program, the compiler crashes because there is an undefined reference to __aeabi_read_tp
<andrewrk> ok I see
<andrewrk> so you're trying to implement __aeabi_read_tp
<Snektron> yes
<Snektron> that function can be implemented in two ways: using a coprocessor instruction
<Snektron> or with a kernel helper function, on older kernels i guess
<Snektron> well, or it can be retrieved by a syscall
<Snektron> The linux kernel decides how it can be retrieved by reading the HWCAP auxv. If it contains HWCAP_TLS, it provides the thread pointer via the coprocessor instruction. If it doesn't, its a helper function
<andrewrk> ok I get the idea now. I think the first thing I would try would be to put this functionality in std/special/start.zig
<andrewrk> if that file is used, it's because the program is not being linked with libc
<andrewrk> sorry, it's always included. but you can look at link_libc
<andrewrk> and then you can conditionally export the __aeabi_read_tp function
<andrewrk> the auxv is sort of a runtime value, so actually maybe __aeabi_read_tp would be in std/special/c.zig for this target
<andrewrk> yeah, I think __aeabi_read_tp belongs in std/special/c.zig (or a file imported by it) and then std/os/linux/tls.zig can be improved with arm32 support. the initTLS function reads the aux vector
<Snektron> Can i also put it in std/os/linux/arm-eabi.zig and export it from std/special/c.zig?
<andrewrk> that would work, yes, but why not put it under the std/special/c/ directory?
<Snektron> figured it could go nicely with the other architecture-dependent stuff
<Snektron> either will work fine i guess
<andrewrk> yeah that does make sense, go for it
<andrewrk> sorry, I'm reasoning through this at the same time as you :)
<andrewrk> ntgg, thanks for filing the issue
<Snektron> by the way, i seem to get a compile error when doing builtin.arch == .arm
<andrewrk> builtin.Arch is a tagged union
<andrewrk> arm has the Arm32 sub-arch enum to choose from
<andrewrk> oh, you just want to compare tags though. that makes sense.
<Snektron> yes
<Snektron> Its already being tracked, cool
waleee-cl has joined #zig
halosghost has joined #zig
Tetralux49 has joined #zig
nairou has joined #zig
ntgg has quit [Ping timeout: 248 seconds]
Tetralux49 has quit [Ping timeout: 260 seconds]
<nrdmn> Looks like there's a java framework called quarkus that has a bytecode generator that writes files with names ending in .zig
<nrdmn> if someone pushes this bytecode to github, it falsely detects this as zig and labels the repo as a zig repo
<samtebbs> kristoff_it: I tried that but got `error: parameter of type 'type' requires comptime`. The code I'm passing the struct to can't be comptime
avoidr has joined #zig
<Snektron> So the alternative non-register-tls thing requires calling a kernel helper function, yet im not sure how to do that exactly and i don't have a kernel i can test that on either
<Snektron> Should i just put @panic("TODO") there?
<kristoff_it> samtebbs: I think it's fine. it's asking you to mark the parameter as comptime, not the whole function. change it to `fn foo(comptime bar: var)`. The function will still be callable at runtime, it's just the parameter that needs comptime
<samtebbs> kristoff_it: Oh nevermind it just wanted the parameter to be comptime :D
<Snektron> oh also, the method i tried crashes the compiler
<samtebbs> kristoff_it: thanks
<kristoff_it> samtebbs: yep :)
<kristoff_it> samtebbs: also I just noticed that the compiler gave you a good hint: bar is of type `type`, so you can use that instead of `var`
marmotini_ has joined #zig
<samtebbs> kristoff_it: Very true! What's the difference?
<fengb> var can be anything. type needs to be a type
<kristoff_it> samtebbs: types are stuff like a specific struct definition, `i64`, `[3]u8` etc, usually we call those "types". While `var` arguments can be all the things I just mentioned plus instances of any of these things, like `"hello"` or 5, or `[3]u8{'l', 'o', 'l'}`
alexander92 has quit [Ping timeout: 268 seconds]
<kristoff_it> `var` is one order of magnitude more generic than `type`, in some sense.
ntgg has joined #zig
porky11 has joined #zig
wootehfoot has joined #zig
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #zig
kristoff_it has quit [Ping timeout: 248 seconds]
vegai has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
cgag has joined #zig
<mikdusan> andrewrk: i need a pair of eyes to review if I'm doing correct IrBasicBlock setup for IR slice bounds checking. I added a detailed comment against the WIP: https://github.com/mikdusan/zig/commit/e85120f42b7cdf00c3cab11e7e9a5f3362c3b133#r34885874
<mikdusan> ie: `ir_set_cursor_at_end_and_append_block()` and `ir_set_cursor_at_end()`
<andrewrk> mikdusan, I'll have a look
<mikdusan> hints or guesses welcome.
<andrewrk> still looking at the code, but note that the order of ir_create_basic_block is not important, but the order of ir_set_cursor_at_end_and_append_block is important
<andrewrk> so for example in an if statement, it's required that the then block and else block are before the endif block
<andrewrk> there's some extra hoops you have to jump through after result locations now too, you can see it in ir_gen_if_bool_expr
<andrewrk> the peer parent thing is required
<andrewrk> as well as the ir_build_end_expr with the result locations set up
<andrewrk> even if everything is void
<andrewrk> maybe you can omit that stuff if everything is guaranteed void
<andrewrk> mikdusan, I don't see ir_set_cursor_at_end_and_append_block for pass_block, is the pass_block getting appended to the basic block list anywhere?
<mikdusan> i just do this: `ir_set_cursor_at_end(&ira->new_irb, pass_block);`
<andrewrk> the use cases for ir_set_cursor_at_end are rare and advanced
<andrewrk> why not ir_set_cursor_at_end_and_append_block there?
<mikdusan> using the _and_append caused the block to duplicate in IR output
<andrewrk> where else is it getting appended?
<andrewrk> you also need to pass is_comptime. it's not allowed to be null for pass1 instructions
<andrewrk> in ir_build_cond_br
<mikdusan> added another comment showing what happens when using _and_append
<andrewrk> you'll have to debug it and figure out why that's happening. the fix is not ir_set_cursor_at_end
<andrewrk> this is not a contributor friendly issue
<mikdusan> ok thanks for the hints.
<andrewrk> I mean, not to discourage you, but this is difficult
<mikdusan> yeah i get it. i'm bypassing all the AST->IR logic and goodness and writing direct IR. expecting it wasn't going to be easy :)
<andrewrk> I'm not even 100% sure that moving the safety check code to ir pass 2 will solve the problem, I'd want to think that through a bit more before trying to implement it
<andrewrk> one complication is @setRuntimeSafety
<andrewrk> it's a bit convenient for example that that function participates in comptime, and then in the llvm ir pass, only then do we read the value
<andrewrk> I don't even foresee doing this in stage1. I was thinking it would make sense to have data flow analysis first
<andrewrk> yeah tbh even if you had a working implementation of this, if it complicates stage1 it might not even be worth it
<andrewrk> isn't that issue tagged with milestone 1.1.0?
<mikdusan> yes
<mikdusan> well there's #1839 and #2649
<andrewrk> ah right
ky0ko has quit [Disconnected by services]
ky1ko is now known as ky0ko
ky0ko_ has joined #zig
ky0ko_ has quit [Remote host closed the connection]
Ichorio has joined #zig
alexander92 has joined #zig
ntgg has quit [Ping timeout: 272 seconds]
wootehfoot has joined #zig
gunnara has joined #zig
<gunnara> hi! If I'd like to target xbox, how would I do that? I read the tier system docs and I believe this would be Tier 3 or 4?
<andrewrk> hi gunnara, what architecture is xbox?
<andrewrk> x86_64?
<gunnara> yes
<mq32> xbox one is x86_64, but the older ones are … Power PC i think
<andrewrk> zig should do just fine. just the parts of the std lib that depend on operating system stuff won't be available
<gunnara> right, I'm not the expert, glad to get help
<gunnara> andrewrk, thanks! How do I determine what depend on "opearting system stuff"?
<andrewrk> you'll get a compile error if it won't work
<andrewrk> but anything that's not OS-specific such as std.ArrayList will work fine
<gunnara> awesome!
<andrewrk> I'm guessing there's an xbox SDK that provides a libc. you'll probably rely heavily on this
<andrewrk> you're the first person trying to do this with zig, so you're gonna have to be a pioneer, but feel free to ask for as much help as you want here, of course :)
<gunnara> andrewrk cool, I'm really happy about the "you'll get compile error it it won't work". That gives me confidence (and some headaches too of course) :)
<andrewrk> zig is pretty good about not introducing OS dependencies where they aren't necessary
FireFox317 has joined #zig
<FireFox317> gunnara: Do you have a way to run code on the xbox?
FireFox317_ has quit [Remote host closed the connection]
<bgiannan> no matter how i try to instanciate my slice, i get a `unable to evaluate constant expression` i think because of the fact that the size is not comptime known
<bgiannan> i tried with an array then sliced and with allocator.alloc
nitram91 has joined #zig
<nitram91> Hello, has anybody tried to do something similar to writing a dynamic linker in zig ? I can't figure out my build.rs (but I can build the project manually)
nitram91 has quit [Remote host closed the connection]
nitram91 has joined #zig
<nitram91> Can anyone give me a bit of help with build.rs ?
<andrewrk> nitram91, you're in #zig
<nitram91> oh sorry, I meant build.zig, I'm tired sorry
FireFox317 has quit [Remote host closed the connection]
<nitram91> I've given up on trying to use rust for my project, but zig seems great because it doesn't depend on libc
<andrewrk> I'm sure people would be willing to help, if you ask a question with details such as what you tried to do, and what you expected or wanted to happen, and a link to the output you actually got
<nitram91> ok, I'll try to write something up
nairou has quit [Remote host closed the connection]
<bgiannan> andrewrk, any idea why something like `allocator.alloc(*MyType, width * height);` would get me a `unable to evaluate constant expression` in alignedAlloc ?
<andrewrk> can I see the output?
<bgiannan> andrewrk, https://0x0.st/z42v.zig
<bgiannan> i tried a slice before and had the same error but on the slice initialization itself, so something must be off on my part for sure i just don't see what
<andrewrk> bgiannan, you're using Level.init(...) as a default value for a struct field
<andrewrk> which means it's getting run at compile time
<andrewrk> you can't allocate heap memory at compile time. related: https://github.com/ziglang/zig/issues/1291
<andrewrk> I suggest not using the default struct field value feature
<bgiannan> ah thank you that makes sense
<bgiannan> be on this all day your saving me
<bgiannan> you're*
<andrewrk> the "called from here" trace points back to level: Level, that's how I know
<bgiannan> right i just didn't have the notion that default struct field values where evaluated at compile time
<andrewrk> yeah there are no constructors
<bgiannan> ah nice now i'm getting a seg fault from `zig build`
marmotini_ has quit [Remote host closed the connection]
<nitram91> Hello, I'm trying to write a dynamic linker in zig (I've done it in C and I want to give zig a try).So I'm trying to compile two files: - main.zig, in which I just have a hello world for now. - _start.s, in which I jump to my main function which is located in main.zigWhen I compile and link manually, everything works out. I basically just do: zi
<nitram91> g build-obj --assembly src/_start.s --disable-pic src/main.zig ld -no-pie -o ld.so main.oBut I can't get my build.zig to do the same thing .Also the -no-pie option is very important, I don't want relocations in my executable.Does anyone have tips on how to achieve this ? I've spent a good few hours reading the source code of std/builder.zigand the
<nitram91> only thing that looked like it could help me was addObject and addAssembly but the compiler is now complaining about unreachable code.Also sorry if this is not how IRC works, it's my first time, I'd gladly learn.
<nitram91> ow, formating broke, it's unreadable
<andrewrk> nitram91, what do you need _start.s for?
<nitram91> it has my _start function, since I'm writing a dynamic linker I need to control precisely how my program start
<andrewrk> ah ok. Well that will work fine. You can also export _start from zig, like this: https://github.com/ziglang/zig/blob/94bbb46ca602be0ea0df97c207a98734ac459a0f/std/special/start.zig#L31
kristoff_it has joined #zig
<shachaf> Hmm, does that entry point set the stack base pointer to 0?
<andrewrk> nitram91, this works for me: https://clbin.com/rhyPu
<andrewrk> shachaf, no, why?
<Snektron> andrewrk: did you see what i wrote earlier about how i can't verify if the kernel helper function will work or not?
<andrewrk> no I did not see that
<shachaf> The amd64 ABI says you should set rbp to 0 in the outermost stack frame.
<andrewrk> I'm guessing the linux kernel does that before invoking _start. otherwise I agree it should be added
<nitram91> shachaf yes, but when I compile manually, everything works, I'm just trying to setup build.zig
<nitram91> andrewrk I'm going to try and I'll let you know
kristoff_it has quit [Ping timeout: 246 seconds]
<shachaf> Hmm, maybe it does. The ABI says that it's unspecified and user code should set it to 0.
<Snektron> andrewrk: The device i imply to run Zig programs on supports the hardware based tls register stuff. That means i can't really test the alternative method with the kernel function, plus im not sure if im calling it correctly (and the method i used generates a compiler assertion failure). Should i add it and hope it works, or just detect if the alternative method should be used, panic, and leaving some pointers for future
<Snektron> reference?
marijnfs_ has joined #zig
<andrewrk> nitram91, ah, I'm sorry, you're trying to output ld.so. I'd have to play around with this a little bit. The code I gave you will produce an executable binary
<cgag> this mean anything to anyone? lld: error: undefined symbol: __gxx_personality_v0
<andrewrk> cgag, I think that's a c++ dependency
<andrewrk> you may need to link libc++ or something like that
<andrewrk> or don't depend on c++
<andrewrk> Snektron, I think panicking and leaving it for a future implementation is good, if you can't test it
<Snektron> In that case, i'm pretty confident that most stuff works now.
<andrewrk> nitram91, there is currently no way to guarantee -no-pie on the linker line, but that's a good use case
<andrewrk> nitram91, would you mind opening an issue explaining what you're trying to accomplish? then we can make long term plans, and give you a workaround to unblock you
<nitram91> andrewrk the name of the output isn't too important. I'm running into an issue with your build.zig, the install method apparently doesn't exist.
<andrewrk> nitram91, I'd suggest using a master branch build at this point. 0.4.0 is many commits behind
<andrewrk> next release is sept 30
<nitram91> ok, ill do that
<nitram91> and yes my issue is mainly not being able to pass -no-pie to the linker. Also when I link manually my executable works with lld but it's broken with GNU ld (bfd ld)
<Snektron> btw, is comptime []u8 support for asm an idea? could allow for a more streamlined implementation of syscall(), considering the weird syscall method of 32 bit linux
gunnara has quit [Ping timeout: 258 seconds]
<andrewrk> Snektron, I'm pretty sure inline assembly is just a comptime string
<Snektron> asm("" + ""); yields a parse error
<andrewrk> nitram91, I believe if you do build-exe and then give it a .so extension it will be no-pie
<andrewrk> Snektron, the operator is ++
<Snektron> typo on irc
<andrewrk> oh yeah, ok looking at the grammar it's a string literal
<andrewrk> I would invite you to open a proposal to change that to an expression
<Snektron> sure, i'll write that up later
<nitram91> can I set the entry point to something other than main ? (I just want execution to start at my _start function)
shritesh has joined #zig
marijnfs_ has quit [Read error: Connection reset by peer]
<Tetralux> nitram91: I believe you can just define a `export nakedcc fn _start() noreturn {}` as it'll use that as the entry point.
<Tetralux> I've never used it, but I think that's how that works.
<nitram91> it does work, but I didn't define a main function and the compiler seems to be complaining about that
marijnfs_ has joined #zig
FireFox317 has joined #zig
<FireFox317> nitram91: Currently that only works when using build-obj, i think there is an open issue for allowing _start to be defined using build-exe
<nitram91> FireFox317 indeed, that's the only way to get it to work. But since reading the definition of the_start function in the zig source code I realised I don't need my own start.
<nitram91> But thank you very much, the feature could still be useful.
<nitram91> and thank you andrewrk for answering my questions, the link to the zig source code actually helped me a lot. I'm just starting out with zig but I really like the "minimalism" of zig.
nitram91 has quit [Remote host closed the connection]
marijnfs_ has quit [Ping timeout: 264 seconds]
marijnfs_ has joined #zig
<Snektron> I think the _start problem can be fixed relatively simply by doing if (@hasDecl(root, "_start")) { @export("_start", root._start, .Strong); } else { @export("_start"), _start, .Strong} in start.zig
porky11 has quit [Remote host closed the connection]
<shritesh> Is there a way to export a default struct from a file? I remember something related when @import("root") was introduced but I can't find the issue right now.
ntgg has joined #zig
casaca has quit [Ping timeout: 248 seconds]
casaca has joined #zig
halosghost has quit [Quit: WeeChat 2.5]
waleee-cl has quit [Quit: Connection closed for inactivity]
kristoff_it has joined #zig
alexander92 has quit [Ping timeout: 248 seconds]
<Tetralux> shritesh: A 'default' strucT?
ltriant has joined #zig
ntgg has quit [Ping timeout: 258 seconds]
<cgag> andrewrk: maybe a dumb question, how do I link against libc++? I see libc++.so in /usr/lib64, and have -isystem /usr/lib64, but --library c++ complains "unable to find library -lc++"
<cgag> works for c, GL, glfw, etc
wootehfoot has quit [Read error: Connection reset by peer]
<cgag> oh, didn't have libcxx-devel
<cgag> drawing lines with the skia via nornagon's skia-zig demo, it's a miracle. Building and linking all this incredibly difficult.
FireFox317 has quit [Ping timeout: 272 seconds]
GiovaniAbel has quit [Ping timeout: 246 seconds]
Ichorio has quit [Ping timeout: 264 seconds]
ntgg has joined #zig
marijnfs_ has quit [Quit: WeeChat 2.4]
ntgg has quit [Ping timeout: 245 seconds]