PLSysSec / PLSysSec/cargo-scan

Roadmap for `cfg` attributes

Open
#50 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement roadmap-v1
Dominant language
Rust
Stars
47
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Current infrastructure for skipping cfg attributes is hacky, see this code in scanner.rs:

    // Quickfix to decide when to skip a CFG attribute
    // TODO: we need to use rust-analyzer or similar to more robustly parse attributes
    pub fn skip_cfg(&self, args: &str) -> bool {
        args.starts_with("target_os = \"linux\"") || args.starts_with("not (feature =")
    }

    // Return true if the attributes imply the code should be skipped
    pub fn skip_attr(&self, attr: &'a syn::Attribute) -> bool {
        let path = attr.path();
        // if path.is_ident("cfg_args") || path.is_ident("cfg") {
        if path.is_ident("cfg") {
            let syn::Meta::List(l) = &attr.meta else { return false };
            let args = &l.tokens;
            if self.skip_cfg(args.to_string().as_str()) {
                info!("Skipping cfg attribute: {}", args);
                return true;
            } else {
                debug!("Scanning cfg attribute: {}", args);
                return false;
            }
        }
        false
    }

    // Return true if the attributes imply the code should be skipped
    pub fn skip_attrs(&self, attrs: &'a [syn::Attribute]) -> bool {
        attrs.iter().any(|x| self.skip_attr(x))
    }

Probably eventually we want to add code to the rust-analyzer wrapper to get information about attributes that are currently enabled for the current build. Relates to the story for build-time effects #13 as well.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with scanner.rs and read skip_cfg, skip_attr, and skip_attrs to understand the current special cases. Then inspect the rust-analyzer wrapper and related story #13 for the intended build-time integration. Done means replacing the current hack with a robust way to identify attributes enabled for the current build, but the issue does not define the implementation scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.