iawia002 requested elliottt for a review on PR #8871.
iawia002 requested wasmtime-core-reviewers for a review on PR #8871.
iawia002 opened PR #8871 from iawia002:normalize-path to bytecodealliance:main:
I encountered a file path issue while using the
wasmtime::component::bindgen!macro, I used a relative file path (e.g.,../wit) in thepathparameter, and then I received an error message:failed to read path for WIT [/Users/code/test-component/examples/../wit]The file path in the error message was quite confusing, in reality, the path that was not found should be
/Users/code/test-component/wit. The relative file path in the error message made it hard for me to immediately understand which directorywasmtime::component::bindgen!was using to look for WIT files. Therefore, this patch normalizes thepathbefore resolving WIT files.Error message before:
failed to read path for WIT [/Users/code/test-component/examples/../wit]after:
failed to read path for WIT [/Users/code/test-component/wit]The
wit_bindgen::generate!macro has the same issue. If this patch is reasonable, I will make the same changes towit_bindgen::generate!afterward.
alexcrichton commented on PR #8871:
Thanks for the PR! Personally though I find path manipulation very tricky/subtle. For example in the presence of symlinks I'm not sure that this implementation is correct. In lieu of that perhaps
std::fs::canonicalizecould be used instead? If that returnsOkthen the resulting path can be used and if it returnsErrthen the original path can be used as-is to probably return an error somewhere else.
iawia002 commented on PR #8871:
Thanks for the review, I agree that path manipulation is tricky,
std::fs::canonicalizeis more of a compromise solution. It can handle some scenarios (such as when the path itself exists but thewitfile does not). However, if the path itself does not exist, the error message will still be the same as it is now. But I believe this is acceptable because we would rather not incorrectly normalize the path in some corner cases.
iawia002 updated PR #8871.
alexcrichton submitted PR review:
Oh that's a good point yeah, I had forgotten about that. Seems like a reasonable compromise though!
alexcrichton merged PR #8871.
Last updated: Dec 13 2025 at 19:03 UTC