odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.98k stars 621 forks source link

Building a package at the filesystem root causes... Weirdness? #4305

Open kawaii-Code opened 1 month ago

kawaii-Code commented 1 month ago

Steps to Reproduce

Windows

Make an odin file at C:\

Run cmd as administrator at C:\

odin build .

This will output a peculiar empty file C without any extensions

image

(Which is kinda hilarious)

Interestingly, odin run . works fine, as well as -file variants.

Linux

# As root
cat > /main.odin << EOF
package main

import "core:fmt"

main :: proc() {
    fmt.println("Hellope!")
}
EOF
cd / && odin build .

Here, the crash is more straightforward:

src/build_settings.cpp(1828): Assertion Failure: `build_project_name.len > 0`

Note: this also works without any odin files, just launching odin build . or odin run . at / is enough.

Context

        Odin:    dev-2024-09:791b05b
        OS:      Windows 10 Professional (version: 22H2), build 19045.4894
        CPU:     AMD Ryzen 7 5800X 8-Core Processor
        RAM:     32711 MiB
        Backend: LLVM 18.1.8

Notes

The bug obviously occurs because while building a package, odin tries to use the parent directory name as the name for the executable. At the root, there is no parent. So, here is the bug.

My issue isn't really about wanting to make a package at filesystem root, that's weird. It's more about using the parent directory name for the executable name. Why do this? We already have the package name and, unlike go, the package doesn't have to be main. I usually call the package the same as the project. Is there any reason for using parent directory name?

flysand7 commented 1 month ago

You definately came to this question from a weird place, but an attempt to build a filesystem root should be a compiler error. That aside, though:

We already have the package name and, unlike go, the package doesn't have to be main. I usually call the package the same as the project. Is there any reason for using parent directory name?

I actually agree with this somewhat, because it also causes naming conflicts on linux, because if you have a directory called src inside your project directory, and build it, it will try to make an executable with the same name, which causes a name conflict (I don't remember how it's resolved currently) between the executable and the directory. If this is a game project, the package name would be something like game, which would make more sense as a default.

gingerBill commented 1 month ago

I am not sure what to do in this case.

Firstly: why the heck are you doing what you are doing?!?!?!

Secondly: maybe we should just ban this from being a thing.

kawaii-Code commented 1 month ago

As I've mentioned in the notes, it's not that I want to do that, it's more of "why even use the parent directory"? I also relate to flysand's point about src. In my opinion, using the package name for the output file is a better default.

kawaii-Code commented 1 month ago

4321 is somewhat related