Skip to content

feat: implement just_version() function#2892

Open
nyurik wants to merge 2 commits intocasey:masterfrom
nyurik:just_version
Open

feat: implement just_version() function#2892
nyurik wants to merge 2 commits intocasey:masterfrom
nyurik:just_version

Conversation

@nyurik
Copy link
Copy Markdown
Contributor

@nyurik nyurik commented Sep 26, 2025

implement #2616

Note that this also allows #2290

_required_just_ver := if semver_matches(just_version(), '>=1.43.0') == 'true' {
  'yes'
} else {
  error('just version 1.43.0 or greater is required, found ' + just_version())
}

@nyurik nyurik force-pushed the just_version branch 3 times, most recently from 42cc35d to 01c3e34 Compare September 28, 2025 02:33
@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Oct 3, 2025

@casey hi, are there any blockers or concerns with this? Thx!

@laniakea64
Copy link
Copy Markdown
Contributor

Sorry if I'm missing something, but so far the proposed use cases for this function revolve around detecting whether the running just version has the features the justfile requires. But when a too-old just version is presented with a syntax or function that requires a later just version, it will fail with a compile error before the justfile's version check is evaluated. So as casey said in #2290 (comment) , a just function cannot fulfill those use cases.

Are there any other use cases for just_version()?

@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Oct 3, 2025

ironically, my biggest use case is NOT to do version check, but rather to reliably report the version from inside. All my just-using projects have this section. I need it to work in CI before anything else - just so that I can debug bigger issues.

# Print environment info
env-info:
    @echo "Running for '{{main_crate}}' crate {{if ci_mode == '1' {'in CI mode'} else {'in dev mode'} }} on {{os()}} / {{arch()}}"
    {{just_executable()}} --version
    rustc --version
    cargo --version
    rustup --version

What I recently discovered is that this breaks on Windows - because just_executable() returns Windows path, but if the script runs using bash, it creates all sorts of problems. So if we have {{just_version()}}, I will have more flexibility in the future.

Do note that with every function we will have the "before" and "after" -- so anyone who wants to use any new function will have to ensure that the version of the just executable will handle it. Not much we can do about it "in retrospect" other than to create some external wrappers.

Copy link
Copy Markdown
Owner

@casey casey left a comment

Choose a reason for hiding this comment

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

See comments!

set dotenv-load
set export

_required_just_ver := if semver_matches(just_version(), '>=1.43.0') == 'true' {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We should remove this, since this is a fragile way to enforce a particular just version, since the justfile may fail to compile at all with the older version.

Comment thread src/function.rs
}

fn just_version(_context: Context) -> FunctionResult {
Ok(env!("CARGO_PKG_VERSION").to_string())
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
Ok(env!("CARGO_PKG_VERSION").to_string())
Ok(env!("CARGO_PKG_VERSION").into())

Comment thread tests/functions.rs
r"
foo:
echo {{arch()}} {{os()}} {{os_family()}} {{num_cpus()}}
echo {{arch()}} {{os()}} {{os_family()}} {{num_cpus()}} {{just_version()}}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's add a single extra test for this, instead of making these tests more complicated.

Comment thread README.md
`"macos"`, `"netbsd"`, `"openbsd"`, `"solaris"`, and `"windows"`.
- `os_family()` — Operating system family; possible values are: `"unix"` and
`"windows"`.
- `just_version()`<sup>master</sup> — The version of `just` being run, e.g. `"1.42.5"`.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I would leave off the e.g.

Suggested change
- `just_version()`<sup>master</sup> — The version of `just` being run, e.g. `"1.42.5"`.
- `just_version()`<sup>master</sup> — The version of `just` being run.

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.

3 participants