CodeSampleX

サンプル

pkg-config 0.3.34: get_variable

検証済みサンプル — cargo pkg-config 0.3.34: get_variable. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: pkg_config::get_variable(package, variable)…

sha256:78da2d6443ad89f0e443c3891152ad599879778f2c422d83a4e2de1eff566b83

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux x64 cargo

検証実行環境

環境 コントラクト ステージ 実行日
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-10-18

ケース

HOW
ゴール
verify get_variable in pkg:cargo/pkg-config@0.3.34
パッケージ
シンボル
  • get_variable
作成日
2026-10-18T21:14:26Z

コントラクト

  1. pkg_config::get_variable(package, variable) invokes the configured PKG_CONFIG executable with --variable=<variable> and returns the trimmed stdout as Ok(String)
  2. pkg_config::get_variable passes PKG_CONFIG_PATH to the pkg-config process so package .pc files in that directory are queried
  3. pkg_config::get_variable returns Ok("".to_string()) when the queried variable output is empty
  4. pkg_config::get_variable returns Err(pkg_config::Error::Failure { .. }) when the pkg-config process exits with a non-zero status for an unknown package

ファイル

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • mock-pkg-config.sh
  • pc/demo.pc
  • spec.json
  • src/main.rs

ソースアーティファクトをダウンロード (tar.gz)

ソース

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "pkg-config"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"

[[package]]
name = "sample-pkg-config"
version = "0.1.0"
dependencies = [
 "pkg-config",
]
Cargo.toml
[package]
name = "sample-pkg-config"
version = "0.1.0"
edition = "2021"

[dependencies]
pkg-config = "=0.3.34"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify get_variable in pkg:cargo/pkg-config@0.3.34
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/pkg-config@0.3.34
Demonstrate these symbols/APIs:
  - get_variable

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:a2896f67044e66ce8ef33484b00fcf59183ff877851ce22d89adcb8022e7a07e","contract":["pkg_config::get_variable(package, variable) invokes the configured PKG_CONFIG executable with --variable=\u003cvariable\u003e and returns the trimmed stdout as Ok(String)","pkg_config::get_variable passes PKG_CONFIG_PATH to the pkg-config process so package .pc files in that directory are queried","pkg_config::get_variable returns Ok(\"\".to_string()) when the queried variable output is empty","pkg_config::get_variable returns Err(pkg_config::Error::Failure { .. }) when the pkg-config process exits with a non-zero status for an unknown package"],"goal":"verify get_variable in pkg:cargo/pkg-config@0.3.34","kind":"HOW","packages":["pkg:cargo/pkg-config@0.3.34"],"schemaVersion":1,"symbols":["get_variable"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/pkg-config@0.3.34"],"schemaVersion":1,"subject":"pkg:cargo/pkg-config@0.3.34","symbols":["get_variable"],"verifierAdapter":"cargo@1"}
mock-pkg-config.sh
#!/bin/sh
var=""
pkg=""
for arg in "$@"; do
    case "$arg" in
        --variable=*)
            var="${arg#--variable=}"
            ;;
        --*)
            ;;
        *)
            pkg="$arg"
            ;;
    esac
done

pc_file="${PKG_CONFIG_PATH:-.}/${pkg}.pc"
if [ ! -f "$pc_file" ]; then
    echo "Package $pkg was not found in the pkg-config search path." >&2
    exit 1
fi

if [ -n "$var" ]; then
    val=$(sed -n "s/^${var}=//p" "$pc_file" | head -n 1)
    printf "%s\n" "$val"
    exit 0
fi

exit 0
pc/demo.pc
prefix=demo_root
libdir=demo_root_lib
includedir=demo_root_include
custom_feature=enabled

Name: demo
Description: Demo package for pkg-config get_variable verification
Version: 1.2.3
Libs: -ldemo
Cflags: -DDEMO=1
spec.json
{
  "schemaVersion": 1,
  "goal": "verify get_variable in pkg:cargo/pkg-config@0.3.34",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/pkg-config@0.3.34"
  ],
  "symbols": [
    "get_variable"
  ]
}
src/main.rs
use std::env;
use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;

fn main() {
    let pc_dir = Path::new("pc")
        .canonicalize()
        .expect("pc directory must exist");
    env::set_var("PKG_CONFIG_PATH", &pc_dir);

    let mock_bin = Path::new("mock-pkg-config.sh")
        .canonicalize()
        .expect("mock-pkg-config.sh must exist");
    let mut perms = fs::metadata(&mock_bin)
        .expect("metadata must succeed")
        .permissions();
    perms.set_mode(0o755);
    fs::set_permissions(&mock_bin, perms).expect("set_permissions must succeed");
    env::set_var("PKG_CONFIG", &mock_bin);

    let prefix = pkg_config::get_variable("demo", "prefix").expect("should retrieve prefix");
    assert_eq!(prefix, "demo_root");

    let libdir = pkg_config::get_variable("demo", "libdir").expect("should retrieve libdir");
    assert_eq!(libdir, "demo_root_lib");

    let custom =
        pkg_config::get_variable("demo", "custom_feature").expect("should retrieve custom_feature");
    assert_eq!(custom, "enabled");

    let missing_var = pkg_config::get_variable("demo", "nonexistent_var")
        .expect("missing var returns empty string");
    assert_eq!(missing_var, "");

    let missing_pkg = pkg_config::get_variable("nonexistent_pkg", "prefix");
    assert!(matches!(missing_pkg, Err(pkg_config::Error::Failure { .. })));

    #[allow(deprecated)]
    let cfg_var = pkg_config::Config::get_variable("demo", "includedir")
        .expect("Config::get_variable should retrieve includedir");
    assert_eq!(cfg_var, "demo_root_include");
}

オリジンシーダー

匿名