facebook / starlark-rust

A Rust implementation of the Starlark language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clarification: "glob" / "native functions"

sschnug opened this issue · comments

While playing around with "enhanced JSON"-like use-cases (as the documentation would call it), i stumbled upon the following interpreter-error:

Err(error: Variable `glob` not found
 --> errors.star:3:10
  |
3 |   srcs = glob("*.md"),
  |          ^^^^
  |
)

with something like:

pandoc_templating_indentation(
  name = "bla",
  srcs = glob("*.md"),
  template = "blub.markdown",
  indentation = 1
)

and:

#[starlark_module]
fn starlark_pandoc_templating_indentation(builder: &mut GlobalsBuilder) {    
    fn pandoc_templating_indentation (name: &str, srcs: Vec<&str>, template: &str, indentation: i32) -> anyhow::Result<NoneType> {
        info!("  -> registered: pandoc_templating_indentation");
        ...

Now i wonder: Is glob not part of this interpreter? I guess, in bazel terminology it would be a native function.

On one hand,

while on the other,

So:

  • Is glob there and i did miss something?
  • Is glob not there and it's out of scope?
  • Is glob not there and it will eventually be provided?

Thanks for reading.

  • Sascha

Thanks for the message. glob is not part of the Starlark standard, but it is part of Bazel/Buck. That means it usually gets provided via a native function, and what it does/how it operates is left to the native function implementing it. The globs you see in the test cases are mostly just parser tests, and originally came from the Bazel repo, so aren't functional.

We never intend to provide glob as part of Starlark, but given the Rust directory/glob libraries, you can write your own version, tailored to your needs, very easily - if that's something that makes sense in your particular Starlark domain.