Skip to content

Commit 2f10509

Browse files
Release 2026.3 (#512) (#32)
# 🎉 Major Updates - Significantly improved C AST and Cmake parsing to handle more corner cases - Added a Dockerfile for reproducible, isolated execution of C-to-Rust translation, in anticipation of AI agents - Used [`cargo features`](https://doc.rust-lang.org/cargo/reference/features.html) to enable conditional compilation of wrappers in translation crate - Reworked `ideas.init` to be modular (with two sub-modules), in anticipation of AI agents # 🎈 Minor Updates - Significant clean-up and deprecation of several modules: `ideas.cover`, `ideas.logging` --------- Co-authored-by: Cory Cornelius <cory.cornelius@intel.com>
1 parent db992cf commit 2f10509

37 files changed

Lines changed: 1774 additions & 4207 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ MANIFEST
3535
# Environments
3636
.env
3737
.venv
38+
docker/.venv
3839
env/
3940
venv/
4041
ENV/

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
default_language_version:
22
python: python3.11
33

4-
exclude: 'examples|lib|test/fixtures/.*\.json'
4+
exclude: ^(examples/|lib/|tools/|test/fixtures/)
55

66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks

IDEAS.mk

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export EXTRACT_INFO_CMAKE CFLAGS
2626
GIT = git -C ${TRANSLATION_DIR}
2727

2828
TEST_FILES := $(realpath $(wildcard test_vectors/*.json))
29-
TARGETS ?= $(shell find build-ninja -maxdepth 1 -type f -executable -exec basename {} \; | cut -d. -f1 | sed -e "s/^lib//gi")
29+
TARGETS ?= $(shell [ -d build-ninja ] && find build-ninja -maxdepth 1 -type f -executable -exec basename {} \; | cut -d. -f1 | sed -e "s/^lib//gi")
3030
ifeq (${TARGETS},)
3131
ifeq ($(filter cmake clean,$(MAKECMDGOALS)),)
3232
$(error No TARGETS found! You need to run cmake!)
@@ -39,8 +39,7 @@ endif
3939
cmake: build-ninja/cmake.log
4040

4141
build-ninja/cmake.log: test_case/CMakeLists.txt ${EXTRACT_INFO_CMAKE}
42-
uv run python -m ideas.cmake source_dir=test_case \
43-
build_dir=build-ninja
42+
uv run python -m ideas.cmake source_dir=test_case build_dir=build-ninja
4443
@touch $@
4544

4645
build-ninja/CMakeCache.txt: build-ninja/cmake.log
@@ -53,50 +52,58 @@ init: $(patsubst %,${TRANSLATION_DIR}/%/init,${TARGETS}) ;
5352
${TRANSLATION_DIR}/%/init: ${TRANSLATION_DIR}/%/src/lib.c | build-ninja/lib%.so.type ;
5453
${TRANSLATION_DIR}/%/init: ${TRANSLATION_DIR}/%/src/main.c | build-ninja/%.type ;
5554

56-
# FIXME: It would be really nice if we could just check out a branch here if the repo already exists and start from there
57-
.PRECIOUS: ${TRANSLATION_DIR}/.git/config
58-
${TRANSLATION_DIR}/.git/config:
55+
# initialize workspace
56+
.PRECIOUS: ${TRANSLATION_DIR}/Cargo.toml
57+
${TRANSLATION_DIR}/Cargo.toml:
5958
@mkdir -p ${TRANSLATION_DIR}
6059
${GIT} init --quiet --initial-branch=main
6160
echo "Cargo.lock\ntarget/\n*.log\n*.jsonl" > ${TRANSLATION_DIR}/.gitignore
6261
${GIT} add .gitignore
6362
${GIT} commit --quiet --all --message "Initial commit"
64-
65-
.PRECIOUS: ${TRANSLATION_DIR}/Cargo.toml
66-
${TRANSLATION_DIR}/Cargo.toml: | ${TRANSLATION_DIR}/.git/config
6763
echo -n "[workspace]\nresolver = \"3\"" > $@
6864
${GIT} add Cargo.toml
6965
${GIT} commit --quiet --all --message "Created cargo workspace"
7066

67+
# initialize translated crate for each C target
68+
.PRECIOUS: ${TRANSLATION_DIR}/%/Cargo.toml
69+
${TRANSLATION_DIR}/%/Cargo.toml: | ${TRANSLATION_DIR}/Cargo.toml build-ninja/lib%.so.type
70+
uv run python -m ideas.init.crate crate_type=lib vcs=git \
71+
hydra.output_subdir=.init \
72+
hydra.run.dir=${TRANSLATION_DIR}/$*
73+
74+
.PRECIOUS: ${TRANSLATION_DIR}/%/Cargo.toml
75+
${TRANSLATION_DIR}/%/Cargo.toml: | ${TRANSLATION_DIR}/Cargo.toml build-ninja/%.type
76+
uv run python -m ideas.init.crate crate_type=bin vcs=git \
77+
hydra.output_subdir=.init \
78+
hydra.run.dir=${TRANSLATION_DIR}/$*
79+
80+
# consolidate each C target
7181
.PRECIOUS: ${TRANSLATION_DIR}/%/src/lib.c
72-
${TRANSLATION_DIR}/%/Cargo.toml ${TRANSLATION_DIR}/%/src/lib.c &: | ${TRANSLATION_DIR}/Cargo.toml build-ninja/lib%.so.type
73-
uv run python -m ideas.init filename=build-ninja/compile_commands.json \
74-
crate_type=lib \
82+
${TRANSLATION_DIR}/%/src/lib.c: | ${TRANSLATION_DIR}/%/Cargo.toml build-ninja/lib%.so.type
83+
uv run python -m ideas.init.consolidate filename=build-ninja/compile_commands.json \
84+
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
7585
export_symbols=build-ninja/lib$*.so.symbols \
7686
source_priority=build-ninja/lib$*.so.sources \
77-
vcs=git \
78-
hydra.output_subdir=.init \
87+
hydra.output_subdir=.init.consolidate \
7988
hydra.run.dir=${TRANSLATION_DIR}/$*
8089

8190
.PRECIOUS: ${TRANSLATION_DIR}/%/src/main.c
82-
${TRANSLATION_DIR}/%/Cargo.toml ${TRANSLATION_DIR}/%/src/main.c &: | ${TRANSLATION_DIR}/Cargo.toml build-ninja/%.type
83-
uv run python -m ideas.init filename=build-ninja/compile_commands.json \
84-
crate_type=bin \
91+
${TRANSLATION_DIR}/%/src/main.c: | ${TRANSLATION_DIR}/%/Cargo.toml build-ninja/%.type
92+
uv run python -m ideas.init.consolidate filename=build-ninja/compile_commands.json \
93+
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
8594
export_symbols=build-ninja/$*.symbols \
8695
source_priority=build-ninja/$*.sources \
87-
vcs=git \
88-
hydra.output_subdir=.init \
96+
hydra.output_subdir=.init.consolidate \
8997
hydra.run.dir=${TRANSLATION_DIR}/$*
9098

91-
9299
# translate
93100
.PHONY: translate
94101
translate: $(patsubst %,${TRANSLATION_DIR}/%/translate,${TARGETS}) ;
95102
${TRANSLATION_DIR}/%/translate: ${TRANSLATION_DIR}/%/src/lib.rs | build-ninja/lib%.so.type ;
96103
${TRANSLATION_DIR}/%/translate: ${TRANSLATION_DIR}/%/src/main.rs | build-ninja/%.type ;
97104

98105
.PRECIOUS: ${TRANSLATION_DIR}/%/src/lib.rs
99-
${TRANSLATION_DIR}/%/src/lib.rs: ${TRANSLATION_DIR}/%/src/lib.c ${TRANSLATION_DIR}/%/tests/test_cases.rs | build-ninja/compile_commands.json build-ninja/lib%.so.symbols build-ninja/lib%.so.sources
106+
${TRANSLATION_DIR}/%/src/lib.rs: ${TRANSLATION_DIR}/%/src/lib.c | build-ninja/compile_commands.json build-ninja/lib%.so.symbols build-ninja/lib%.so.sources
100107
-uv run python -m ideas.translate model.name=${PROVIDER}/${MODEL} \
101108
filename=${TRANSLATION_DIR}/$*/src/lib.c \
102109
vcs=git \
@@ -105,7 +112,7 @@ ${TRANSLATION_DIR}/%/src/lib.rs: ${TRANSLATION_DIR}/%/src/lib.c ${TRANSLATION_DI
105112
hydra.run.dir=${TRANSLATION_DIR}/$* ${TRANSLATE_ARGS}
106113

107114
.PRECIOUS: ${TRANSLATION_DIR}/%/src/main.rs
108-
${TRANSLATION_DIR}/%/src/main.rs: ${TRANSLATION_DIR}/%/src/main.c ${TRANSLATION_DIR}/%/tests/test_cases.rs | build-ninja/compile_commands.json build-ninja/%.symbols build-ninja/%.sources
115+
${TRANSLATION_DIR}/%/src/main.rs: ${TRANSLATION_DIR}/%/src/main.c | build-ninja/compile_commands.json build-ninja/%.symbols build-ninja/%.sources
109116
-uv run python -m ideas.translate model.name=${PROVIDER}/${MODEL} \
110117
filename=${TRANSLATION_DIR}/$*/src/main.c \
111118
vcs=git \
@@ -162,12 +169,17 @@ ${TRANSLATION_DIR}/%/cargo_test.log: ${TRANSLATION_DIR}/%/build.log ${TRANSLATIO
162169
fi \
163170

164171
.PRECIOUS: ${TRANSLATION_DIR}/%/tests/test_cases.rs
172+
${TRANSLATION_DIR}/%/tests/test_cases.rs: | ${TEST_FILES} ${TRANSLATION_DIR}/%/Cargo.toml runner/Cargo.toml build-ninja/lib%.so.type
173+
-uv run python -m ideas.convert_tests runner_manifest=$(realpath runner/Cargo.toml) \
174+
crate_manifest=$(realpath ${TRANSLATION_DIR}/$*/Cargo.toml) \
175+
template=${MAKEFILE_DIR}/tools/rust_tests/lib_testing.rs \
176+
output=${TRANSLATION_DIR}/$*/tests/test_cases.rs \
177+
'test_vectors=[$(shell echo "$(TEST_FILES)" | tr ' ' ',')]'
178+
165179
${TRANSLATION_DIR}/%/tests/test_cases.rs: | ${TEST_FILES} ${TRANSLATION_DIR}/%/Cargo.toml build-ninja/%.type
166-
@mkdir -p $(@D)
167-
-uv run python -m ideas.convert_tests --crate_manifest $(realpath ${TRANSLATION_DIR}/$*/Cargo.toml) \
168-
${TEST_FILES} | rustfmt > $@
169-
${GIT} add $*/Cargo.toml $*/tests/test_cases.rs
170-
${GIT} commit --quiet --message "Converted \`$*\` test vectors"
180+
-uv run python -m ideas.convert_tests crate_manifest=$(realpath ${TRANSLATION_DIR}/$*/Cargo.toml) \
181+
output=${TRANSLATION_DIR}/$*/tests/test_cases.rs \
182+
'test_vectors=[$(shell echo "$(TEST_FILES)" | tr ' ' ',')]'
171183

172184
.PRECIOUS: test_vectors/%.json
173185
test_vectors/%.json:

Makefile

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ VLLM_VERSION ?= 0.13.0
1919
VLLM_ARGS ?= --tensor-parallel-size 8 --enable-expert-parallel --max-num-seqs 32 --max-model-len 128k## Args to pass to vllm serve
2020
TRANSLATION_DIR ?= translation.$(shell git rev-parse HEAD)## Directory to put IDEAS translation
2121
TRANSLATE_ARGS ?= ## Args to pass to IDEAS translation
22-
TESTGEN_DIR ?= testgen.$(shell git rev-parse HEAD)## Directory to put IDEAS test generation
23-
TESTGEN_ARGS ?= ## Args to pass to IDEAS test generation
2422
RUSTFLAGS ?= -Awarnings## Flags to build Rust translation
2523
VERBOSE ?= 0## Whether to output failed/partial projects in summaries
2624

27-
AFL_TAG = aflplusplus/aflplusplus:stable
28-
2925
# Pass these variables to IDEAS.mk
30-
export MODEL BASE_URL TRANSLATION_DIR TESTGEN_DIR RUSTFLAGS
26+
export MODEL BASE_URL TRANSLATION_DIR RUSTFLAGS
3127

3228
EXAMPLES ?= $(sort $(patsubst %/test_case,%,$(shell find ${EXAMPLES_DIR} -maxdepth 3 -name test_case -type d)))## List of examples to run on
3329
ifeq ($(EXAMPLES),)
@@ -37,8 +33,43 @@ endif
3733

3834
all: help ;
3935

36+
.PHONY: docker/build
37+
docker/build:## Build translation Docker image
38+
docker/build: docker/docker_build.log
39+
40+
.PRECIOUS: docker/docker_build.log
41+
docker/docker_build.log: docker/ideas.Dockerfile
42+
rm -rf docker/.venv
43+
cd docker && \
44+
docker build --build-arg USER_UID=$(shell id -u) \
45+
--build-arg USER_GID=$(shell id -g) \
46+
-f ideas.Dockerfile -t ideas-$(shell id -u) . && \
47+
docker images --quiet ideas:latest 2>&1 | tee $(notdir $@)
48+
49+
.PHONY: docker
50+
docker:## Mount translation Docker image
51+
docker: docker/docker_build.log
52+
mkdir -p docker/.venv
53+
test -f $(HOME)/.bashrc || touch $(HOME)/.bashrc
54+
docker run -it --rm -v ".:/home/user/IDEAS" \
55+
-v "./docker/.venv:/home/user/IDEAS/.venv" \
56+
-v "$(HOME)/.bashrc:/home/user/.bashrc:ro" \
57+
ideas-$(shell id -u) bash
58+
59+
60+
.PHONY: docker/build_measurements
61+
docker/build_measurements:## Build measurement Docker images
62+
docker/build_measurements: ${PIPELINE_DIR}/evaluate_unsafe_usage/unsafety.Dockerfile \
63+
${PIPELINE_DIR}/idiomaticity/idiomaticity_measurements.Dockerfile
64+
docker build -t ${PIPELINE_TAG}/unsafety \
65+
-f ${PIPELINE_DIR}/evaluate_unsafe_usage/unsafety.Dockerfile \
66+
${PIPELINE_DIR}/evaluate_unsafe_usage/
67+
docker build -t ${PIPELINE_TAG}/idiomaticity \
68+
-f ${PIPELINE_DIR}/idiomaticity/idiomaticity_measurements.Dockerfile \
69+
${PIPELINE_DIR}/idiomaticity/
70+
4071
.PHONY: install
41-
install: install-uv install-rust install-deno ## Install uv, Rust, and Deno
72+
install: install-uv install-rust ## Install uv and Rust
4273

4374
.PHONY: install-uv
4475
install-uv:## Install uv@0.9.22
@@ -48,26 +79,18 @@ install-uv:## Install uv@0.9.22
4879
install-rust:## Install Rust@1.88.0
4980
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.88.0
5081

51-
.PHONY: install-deno
52-
install-deno:## Install Deno, which is required by dspy.PythonInterpreter()
53-
curl -fsSL https://deno.land/install.sh | sh
54-
5582
.PHONY: install-clang
5683
install-clang:## Install Clang-21, must be sudo
5784
wget https://apt.llvm.org/llvm.sh
5885
chmod +x llvm.sh
5986
-./llvm.sh 21 all
6087
rm ./llvm.sh
6188

62-
.PHONY: test
63-
test:## Run pytest
64-
uv run pytest
65-
6689
.PHONY: serve
6790
serve:## Start vLLM server
6891
uv run --no-project --python 3.11 --with vllm==${VLLM_VERSION} vllm serve ${MODEL} --revision ${REVISION} --host ${HOST} --port ${PORT} --dtype auto ${VLLM_ARGS}
6992

70-
kill:## Kill all vLLM serves
93+
kill:## Kill all vLLM servers
7194
pkill -f "^uv run --no-project --python 3.11 --with vllm==${VLLM_VERSION} vllm serve" -u ${USER}
7295

7396
.PHONY: FORCE
@@ -119,14 +142,6 @@ examples/%/wrapper: FORCE
119142
-@$(MAKE) -j1 -f $(IDEAS_MAKEFILE) -C $(@D) wrapper
120143

121144

122-
.PHONY: examples/add_test_vectors
123-
examples/add_test_vectors:## Build all translated examples
124-
examples/add_test_vectors: $(addsuffix /add_test_vectors,${EXAMPLES})
125-
examples/%/add_test_vectors:## Build specific translated example
126-
examples/%/add_test_vectors: FORCE
127-
-@$(MAKE) -j1 -f $(IDEAS_MAKEFILE) -C $(@D) cmake
128-
-@$(MAKE) -j1 -f $(IDEAS_MAKEFILE) -C $(@D) add_test_vectors
129-
130145
.PHONY: examples/build
131146
examples/build:## Build all translated examples
132147
examples/build: $(addsuffix /build,${EXAMPLES})
@@ -186,19 +201,12 @@ examples/%/clean:## Clean specific example
186201
examples/%/clean: FORCE
187202
-@$(MAKE) -j1 -f $(IDEAS_MAKEFILE) -C $(@D) clean
188203

189-
# update tests
190-
.PHONY: examples/update_tests
191-
examples/update_tests:## Update test cases to use TRANSLATION_DIR test cases for all examples
192-
examples/update_tests: $(addsuffix /update_tests,${EXAMPLES})
193-
examples/%/update_tests:## Update specific test cases to use TRANSLATION_DIR test cases
194-
examples/%/update_tests: FORCE
195-
-@$(MAKE) -j1 -f $(IDEAS_MAKEFILE) -C $(@D) cmake
196-
-@$(MAKE) -j1 -f $(IDEAS_MAKEFILE) -C $(@D) update_tests
197-
198-
# clean
204+
# Global clean
199205
clean:
200-
rm -rf examples
201-
git checkout HEAD examples
206+
rm -rf docker/.venv
207+
rm -rf docker/docker_build.log
208+
rm -rf ${PIPELINE_DIR} examples
209+
git checkout HEAD ${PIPELINE_DIR} examples
202210

203211
# help
204212
RESET := \033[0;0m
@@ -219,5 +227,5 @@ help:
219227
| awk 'BEGIN { FS=" [:?!+]?= |##" } ; \
220228
{ printf " ${YELLOW_COL}%-30s${RESET}%s ${GREY_COL}(default: %s)${RESET}\n", $$1, $$3, $$2}'
221229
@echo ""
222-
@echo "Examples:"
223-
@echo " make examples/test TRANSLATION_DIR=test_case ${GREY_COL}# Build and run tests on C examples ${RESET}"
230+
@echo "Example:"
231+
@echo " make examples/test TRANSLATION_DIR=test_case ${GREY_COL}# Translate, build, and run tests on C examples ${RESET}"

0 commit comments

Comments
 (0)