diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index cefacdb..100a20b 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -46,7 +46,7 @@ jobs: - name: Build native module working-directory: ./python run: | - cp Cargo.${{ matrix.feature }}.toml Cargo.toml + python prepare.py ${{ matrix.feature }} cargo build --release - name: Install Python build tools (macOS) diff --git a/python/.gitignore b/python/.gitignore index 7aaa10e..4dc02c3 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -1,5 +1,6 @@ /Cargo.lock /Cargo.toml +/src/lib.rs /target/ __pycache__/ diff --git a/python/prepare.py b/python/prepare.py new file mode 100644 index 0000000..4c8e985 --- /dev/null +++ b/python/prepare.py @@ -0,0 +1,14 @@ +import shutil +import sys + +feature = sys.argv[1] + +module_name = "minify_html_core" if feature == "core" else "minify_html" +cargo_file = "Cargo.core.toml" if feature == "core" else "Cargo.js.toml" + +with open("src/lib.template.rs", "r") as template: + actual = template.read().replace("REPLACE_WITH_MODULE_NAME", module_name) + with open("src/lib.rs", "w") as librs: + librs.write(actual) + +shutil.copyfile(cargo_file, "Cargo.toml") diff --git a/python/src/lib.rs b/python/src/lib.template.rs similarity index 91% rename from python/src/lib.rs rename to python/src/lib.template.rs index ed935a0..c7a2ca8 100644 --- a/python/src/lib.rs +++ b/python/src/lib.template.rs @@ -17,7 +17,7 @@ fn minify(code: String, minify_js: bool, minify_css: bool) -> PyResult { } #[pymodule] -fn minify_html(_py: Python, m: &PyModule) -> PyResult<()> { +fn REPLACE_WITH_MODULE_NAME(_py: Python, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(minify))?; Ok(())