nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.41k stars 1.47k forks source link

os module uses wrong path separator in nimvm when cross-compiling #23877

Open nocturn9x opened 1 month ago

nocturn9x commented 1 month ago

Description

The VM used for compile time evaluation does not appear to be using hostOS to pick which path style to use in functions like joinPath() (possibly targetOS is being used?). This is a problem I encountered while trying to cross compile my project for Windows while being on Linux: part of the code tries to statically read the contents of two JSON files into two consts and fails because the path is incorrect

import os

func buildPath: string {.compileTime.} =
    result = joinPath(currentSourcePath().parentDir(), "resources")

const x = buildPath()
echo x

Nim Version

Nim Compiler Version 2.0.4 [Linux: amd64] Compiled at 2024-03-28 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b47747d31844c6bd9af4322efe55e24fefea544c active boot switches: -d:release

Current Output

\home\nocturn9x\heimdall\resources

Expected Output

/home/nocturn9x/heimdall/resources

Possible Solution

The nim compile time evaluator should use hostOS for picking the path separator to use

Additional Information

No response

demotomohiro commented 1 month ago

Related issues: https://github.com/nim-lang/Nim/issues/21534 https://github.com/nim-lang/Nim/issues/19558

A path created at compile time can be used at both compile time and run time. I have created new path library to workaround this issue: https://github.com/demotomohiro/pathX

juancarlospaco commented 1 month ago

Add a mention to the lib in the docs? 🤔