-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIDEAS.mk
More file actions
273 lines (236 loc) · 12.3 KB
/
Copy pathIDEAS.mk
File metadata and controls
273 lines (236 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#
# Copyright (C) 2025 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(realpath $(dir $(MAKEFILE_PATH)))
EXTRACT_INFO_CMAKE := ${MAKEFILE_DIR}/extract_info.cmake
AGENTS_MAKEFILE := $(MAKEFILE_DIR)/AGENTS.mk
PROVIDER ?= hosted_vllm
MODEL ?= Qwen/Qwen3.5-397B-A17B
HOST ?= localhost
PORT ?= 8000
BASE_URL ?= http://${HOST}:${PORT}/v1
TRANSLATION_DIR ?= translation.$(shell git --git-dir=${MAKEFILE_DIR}/.git rev-parse HEAD)
ifeq (${PROVIDER},hosted_vllm)
override TRANSLATE_ARGS += model.base_url=${BASE_URL}
endif
RUSTFLAGS ?= -Awarnings## Ignore Rust compiler warnings
CARGO_NET_OFFLINE ?= true## Cargo offline mode
CFLAGS ?= -w## Ignore C compiler warnings
LARGE_PROJECT ?= 0## Disable translation-time tests and enable context compression
export EXTRACT_INFO_CMAKE CFLAGS LARGE_PROJECT
VCS ?= git
GIT_AUTHOR_NAME ?= ideas
GIT_AUTHOR_EMAIL ?= ideas@localhost
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
ifeq ($(LARGE_PROJECT),1)
TRANSLATION_TEST ?= smoke
else
TRANSLATION_TEST ?= test_assert
endif
EVALUATION_TEST ?= test_cases
TEST_FILES := $(wildcard test_vectors/*.json)
ifeq ($(LARGE_PROJECT),1)
TARGETS_LIB ?=
TARGETS_BIN ?= $(shell [ -d build-ninja ] && find build-ninja -maxdepth 1 -name '*.sources' ! -name '*.so.sources' -exec basename {} .sources \; )
else
TARGETS_LIB ?= $(shell [ -d build-ninja ] && find build-ninja -maxdepth 1 -name 'lib*.so.sources' -exec basename {} .so.sources \; | sed -e "s/^lib//gi")
TARGETS_BIN ?= $(shell [ -d build-ninja ] && find build-ninja -maxdepth 1 -name '*.sources' ! -name 'lib*.so.sources' -exec basename {} .sources \; )
endif
TARGETS ?= $(TARGETS_BIN) $(TARGETS_LIB)
ifeq (${TARGETS},)
ifeq ($(filter cmake clean,$(MAKECMDGOALS)),)
$(error No TARGETS found! You need to run cmake!)
endif
endif
# cmake
.PHONY: cmake
cmake: build-ninja/cmake.log
build-ninja/cmake.log: test_case/CMakeLists.txt ${EXTRACT_INFO_CMAKE}
uv run python -m ideas.cmake source_dir=test_case build_dir=build-ninja
@touch $@
build-ninja/CMakeCache.txt: build-ninja/cmake.log
build-ninja/compile_commands.json: build-ninja/cmake.log
build-ninja/build.log: build-ninja/cmake.log
# init
.PHONY: init
init: $(patsubst %,${TRANSLATION_DIR}/%/init,${TARGETS}) ;
${TRANSLATION_DIR}/%/init: ${TRANSLATION_DIR}/%/build.rs
touch ${TRANSLATION_DIR}/$*/Cargo.toml
touch ${TRANSLATION_DIR}/$*/build.rs
# initialize workspace
.PRECIOUS: ${TRANSLATION_DIR}/Cargo.toml
${TRANSLATION_DIR}/Cargo.toml:
@mkdir -p ${TRANSLATION_DIR}
uv run python -m ideas.init.workspace cargo_toml=$@ vcs=${VCS}
# initialize translated crate for each C target
# consolidate each C target
# generate build scripts
.PRECIOUS: ${TRANSLATION_DIR}/%/Cargo.toml
.PRECIOUS: ${TRANSLATION_DIR}/%/src/lib.c
.PRECIOUS: ${TRANSLATION_DIR}/%/src/main.c
.PRECIOUS: ${TRANSLATION_DIR}/%/build.rs
${TRANSLATION_DIR}/%/Cargo.toml \
${TRANSLATION_DIR}/%/src/lib.c \
${TRANSLATION_DIR}/%/build.rs: | ${TRANSLATION_DIR}/Cargo.toml build-ninja/compile_commands.json build-ninja/lib%.so.sources
uv run python -m ideas.init.crate crate_type=lib \
vcs=${VCS} \
hydra.output_subdir=.init.crate \
hydra.run.dir=${TRANSLATION_DIR}/$*
uv run python -m ideas.init.consolidate filename=build-ninja/compile_commands.json \
vcs=${VCS} \
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
source_priority=build-ninja/lib$*.so.sources \
hydra.output_subdir=.init.consolidate \
hydra.run.dir=${TRANSLATION_DIR}/$*
uv run python -m ideas.init.build vcs=${VCS} \
hydra.output_subdir=.init.build \
hydra.job.name=init.build \
hydra.run.dir=${TRANSLATION_DIR}/$*
${TRANSLATION_DIR}/%/Cargo.toml \
${TRANSLATION_DIR}/%/src/main.c \
${TRANSLATION_DIR}/%/build.rs: | ${TRANSLATION_DIR}/Cargo.toml build-ninja/compile_commands.json build-ninja/%.sources
uv run python -m ideas.init.crate crate_type=bin \
vcs=${VCS} \
hydra.output_subdir=.init.crate \
hydra.run.dir=${TRANSLATION_DIR}/$*
uv run python -m ideas.init.consolidate filename=build-ninja/compile_commands.json \
vcs=${VCS} \
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
source_priority=build-ninja/$*.sources \
hydra.output_subdir=.init.consolidate \
hydra.run.dir=${TRANSLATION_DIR}/$*
uv run python -m ideas.init.build vcs=${VCS} \
hydra.output_subdir=.init.build \
hydra.job.name=init.build \
hydra.run.dir=${TRANSLATION_DIR}/$*
# translate
.PHONY: translate
translate: $(patsubst %,${TRANSLATION_DIR}/%/translate,${TARGETS}) ;
${TRANSLATION_DIR}/%/translate: ${TRANSLATION_DIR}/%/src/lib.rs | build-ninja/lib%.so.sources ;
${TRANSLATION_DIR}/%/translate: ${TRANSLATION_DIR}/%/src/main.rs | build-ninja/%.sources ;
ifeq ($(LARGE_PROJECT),1)
.PRECIOUS: ${TRANSLATION_DIR}/%/src/lib.rs
${TRANSLATION_DIR}/%/src/lib.rs: | ${TRANSLATION_DIR}/%/Cargo.toml ${TRANSLATION_DIR}/%/tests/${TRANSLATION_TEST}.rs build-ninja/compile_commands.json
-uv run python -m ideas.translate model.name=${PROVIDER}/${MODEL} \
filename=build-ninja/compile_commands.json \
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
source_priority=build-ninja/lib$*.so.sources \
tests=${TRANSLATION_TEST} \
vcs=${VCS} \
hydra.output_subdir=.translate \
hydra.job.name=translate \
hydra.run.dir=${TRANSLATION_DIR}/$* ${TRANSLATE_ARGS}
@touch $@
.PRECIOUS: ${TRANSLATION_DIR}/%/src/main.rs
${TRANSLATION_DIR}/%/src/main.rs: | ${TRANSLATION_DIR}/%/Cargo.toml ${TRANSLATION_DIR}/%/tests/${TRANSLATION_TEST}.rs build-ninja/compile_commands.json
-uv run python -m ideas.translate model.name=${PROVIDER}/${MODEL} \
filename=build-ninja/compile_commands.json \
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
source_priority=build-ninja/$*.sources \
tests=${TRANSLATION_TEST} \
vcs=${VCS} \
hydra.output_subdir=.translate \
hydra.job.name=translate \
hydra.run.dir=${TRANSLATION_DIR}/$* ${TRANSLATE_ARGS}
@touch $@
else
.PRECIOUS: ${TRANSLATION_DIR}/%/src/lib.rs
${TRANSLATION_DIR}/%/src/lib.rs: ${TRANSLATION_DIR}/%/src/lib.c | ${TRANSLATION_DIR}/%/Cargo.toml ${TRANSLATION_DIR}/%/tests/${TRANSLATION_TEST}.rs
-uv run python -m ideas.translate model.name=${PROVIDER}/${MODEL} \
filename=${TRANSLATION_DIR}/$*/src/lib.c \
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
tests=${TRANSLATION_TEST} \
vcs=${VCS} \
hydra.output_subdir=.translate \
hydra.job.name=translate \
hydra.run.dir=${TRANSLATION_DIR}/$* ${TRANSLATE_ARGS}
@touch $@
.PRECIOUS: ${TRANSLATION_DIR}/%/src/main.rs
${TRANSLATION_DIR}/%/src/main.rs: ${TRANSLATION_DIR}/%/src/main.c | ${TRANSLATION_DIR}/%/Cargo.toml ${TRANSLATION_DIR}/%/tests/${TRANSLATION_TEST}.rs
-uv run python -m ideas.translate model.name=${PROVIDER}/${MODEL} \
filename=${TRANSLATION_DIR}/$*/src/main.c \
cargo_toml=${TRANSLATION_DIR}/$*/Cargo.toml \
tests=${TRANSLATION_TEST} \
vcs=${VCS} \
hydra.output_subdir=.translate \
hydra.job.name=translate \
hydra.run.dir=${TRANSLATION_DIR}/$* ${TRANSLATE_ARGS}
@touch $@
endif
# build
.PHONY: build
build: ${TRANSLATION_DIR}/build.log ;
.PRECIOUS: ${TRANSLATION_DIR}/build.log
${TRANSLATION_DIR}/build.log: $(patsubst %,${TRANSLATION_DIR}/%/build.log,${TARGETS}) ;
cat $^ > $@
.PRECIOUS: ${TRANSLATION_DIR}/%/build.log
${TRANSLATION_DIR}/%/build.log: ${TRANSLATION_DIR}/%/src/lib.rs
-export RUSTFLAGS=${RUSTFLAGS} && cargo build --quiet --manifest-path ${TRANSLATION_DIR}/$*/Cargo.toml 2> ${TRANSLATION_DIR}/$*/build.log
@cat ${TRANSLATION_DIR}/$*/build.log
${TRANSLATION_DIR}/%/build.log: ${TRANSLATION_DIR}/%/src/main.rs
-export RUSTFLAGS=${RUSTFLAGS} && cargo build --quiet --manifest-path ${TRANSLATION_DIR}/$*/Cargo.toml 2> ${TRANSLATION_DIR}/$*/build.log
@cat ${TRANSLATION_DIR}/$*/build.log
# test
.PHONY: test
test: ${TRANSLATION_DIR}/cargo_${EVALUATION_TEST}.log ;
.PRECIOUS: ${TRANSLATION_DIR}/cargo_${EVALUATION_TEST}.log
${TRANSLATION_DIR}/cargo_${EVALUATION_TEST}.log: ${TRANSLATION_DIR}/build.log $(patsubst %,${TRANSLATION_DIR}/%/cargo_${EVALUATION_TEST}.log,${TARGETS})
cat $(filter-out $<,$^) > $@
.PRECIOUS: ${TRANSLATION_DIR}/%/cargo_${EVALUATION_TEST}.log
${TRANSLATION_DIR}/%/cargo_${EVALUATION_TEST}.log: ${TRANSLATION_DIR}/%/build.log ${TRANSLATION_DIR}/%/tests/${EVALUATION_TEST}.rs | ${TRANSLATION_DIR}/%/Cargo.toml
uv run python -m ideas.evaluate manifest=${TRANSLATION_DIR}/$*/Cargo.toml \
test_cases=${EVALUATION_TEST} \
output_file=$@
# convert cando tests
.PRECIOUS: ${TRANSLATION_DIR}/%/tests/test_cases.rs
${TRANSLATION_DIR}/%/tests/test_cases.rs: | ${TEST_FILES} ${TRANSLATION_DIR}/%/Cargo.toml runner/Cargo.toml build-ninja/lib%.so.sources
uv run python -m ideas.convert_tests runner_manifest=runner/Cargo.toml \
vcs=${VCS} \
template=${MAKEFILE_DIR}/tools/rust_tests/lib_testing.rs \
output=tests/test_cases.rs \
'test_vectors=[$(shell echo "$(TEST_FILES)" | tr ' ' ',')]' \
hydra.output_subdir=.convert_tests \
hydra.run.dir=${TRANSLATION_DIR}/$*
${TRANSLATION_DIR}/%/tests/test_cases.rs: | ${TEST_FILES} ${TRANSLATION_DIR}/%/Cargo.toml build-ninja/%.sources
uv run python -m ideas.convert_tests vcs=${VCS} \
output=tests/test_cases.rs \
'test_vectors=[$(shell echo "$(TEST_FILES)" | tr ' ' ',')]' \
hydra.output_subdir=.convert_tests \
hydra.run.dir=${TRANSLATION_DIR}/$*
# can't rely on test vectors without explicit targets
.PRECIOUS: test_vectors/%.json
test_vectors/%.json:
$(error $@ not found)
.PRECIOUS: test_vectors/%/%.json
test_vectors/%/%.json:
$(error $@ not found)
# testgen for each C target
.PRECIOUS: test_crates/%/tests/test_assert.rs
test_crates/%/tests/test_assert.rs: | build-ninja/lib%.so.sources
-@$(MAKE) -j1 -f $(AGENTS_MAKEFILE) $@
test_crates/%/tests/test_assert.rs: | build-ninja/%.sources
-@$(MAKE) -j1 -f $(AGENTS_MAKEFILE) $@
.PRECIOUS: ${TRANSLATION_DIR}/%/tests/test_assert.rs
${TRANSLATION_DIR}/%/tests/test_assert.rs: test_crates/%/tests/test_assert.rs
mkdir -p $(dir $@)
cp $< $@
# test wrappers instead of bindings
.PRECIOUS: ${TRANSLATION_DIR}/%/tests/test_assert_wrapper.rs
${TRANSLATION_DIR}/%/tests/test_assert_wrapper.rs: test_crates/%/tests/test_assert.rs
cat $< | sed 's/$*::binding::/$*::wrapper::/g' > $@
# smoke test
.PRECIOUS: ${TRANSLATION_DIR}/%/tests/smoke.rs
${TRANSLATION_DIR}/%/tests/smoke.rs:
mkdir -p $(dir $@)
echo "#[test]" >> $@
echo "fn smoke() {" >> $@
echo " assert_eq!(1, 1);" >> $@
echo "}" >> $@
# clean
.PHONY: clean
clean:
rm -rf build-ninja
find . -name Cargo.toml -exec cargo clean --quiet --manifest-path {} \;