Skip to content

cli: add ability to set project root - #392

Open
KyrylR wants to merge 1 commit into
masterfrom
feature/fix-crate-root-resolution
Open

cli: add ability to set project root#392
KyrylR wants to merge 1 commit into
masterfrom
feature/fix-crate-root-resolution

Conversation

@KyrylR

@KyrylR KyrylR commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

When files are not on the project_root/simf or project_root/simf or any other source dir but deeper, like project_root/simf/math/module/*add*.simf and in *.simf we specify the crate keyword it would resolve as a project_root project_root/simf/math/module but it should resolve as project_root/simf for the correct LSP analysis

This PR introduces a way to provide a specific project root to help address the issue

@KyrylR
KyrylR requested a review from LesterEvSe August 24, 2026 10:59
@KyrylR KyrylR self-assigned this Aug 24, 2026
@KyrylR
KyrylR requested a review from delta1 as a code owner August 24, 2026 10:59

@stringhandler stringhandler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConceptACK, but I think you should allow the main entry path to exist outside of the project root.

Comment thread src/main.rs Outdated
.arg(
Arg::new("project_root")
.long("project-root")
.value_name("PATH")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.value_name("PATH")
.value_name("PROJECT_ROOT")

Comment thread src/main.rs
.ok_or("Failed to determine project root directory from entry file")?,
};

if !main_path.starts_with(&canon_root) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails anyway, what is the purpose of allowing you to specify it? This feels like the behaviour is the same before this PR

@KyrylR

KyrylR commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

I think you should allow the main entry path to exist outside of the project root.

In which case we should allow it?

I do not really understand what do you mean

@stringhandler

Copy link
Copy Markdown
Contributor

Maybe I am misunderstanding what you want to achieve with this PR. Could you add some example file layouts before and after the PR?

@KyrylR

KyrylR commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

This fixes a bug related to the crate keyword, @LesterEvSe probably can explain it better

@LesterEvSe

Copy link
Copy Markdown
Collaborator

Currently we have this structure in simplicityhl-std/simf #3eafe6b.

The problem is that we can't create a tests directory (or anything similar), because the crate keyword resolves relative to the file that is being compiled, not relative to the project root.

Example:

simf/
  lib/
    asserts.simf
  tests/
    asserts_test.simf

We want use crate::lib::asserts::{...} to work inside asserts_test.simf, but right now this is impossible: crate::lib::asserts resolves to simf/tests/lib/asserts instead of simf/lib/asserts. This PR adds an explicit project root so we can have a better project layout than the current one.

On the starts_with check, I'd keep it. If the entry file lives outside the declared root, crate::-relative resolution stops being well-defined: no crate:: path can refer to the entry itself, and any module in the tree that tries to import from it will silently miss.

@apoelstra

Copy link
Copy Markdown
Contributor

If this fails anyway, what is the purpose of allowing you to specify it? This feels like the behaviour is the same before this PR

Before this PR, crate:: always refers to the directory where main is defined. (What this PR calls the main_path.)

After this PR, you can specify a --project-root which tells the compiler where crate:: should point to. And then the main_path continues to be "wherever main is defined", and is only used to check that the main function is defined somewhere within the project root.

Eventually, presumably, we will have a cargo-like tool (maybe smplx) around the rustc-like simc compiler. This tool will locate its top-level manifest file, Smplx.toml or whatever, and set --project-root to the directory where that file lives. And all source files should live in the tree under that.

If you remove this check, it will let people do confusing constructions that may limit our ability in the future to define Cargo-like projects. I'd prefer to keep it.

@stringhandler

Copy link
Copy Markdown
Contributor

Ok. My main concern was that this was adding a check that was already done, but I see it allows you to specify a root further up the path than was previously allowed.

@KyrylR
KyrylR force-pushed the feature/fix-crate-root-resolution branch from 2fc51f7 to d21f237 Compare August 24, 2026 13:58

@LesterEvSe LesterEvSe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d21f237; tested locally with just check and just check_fuzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants