Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn on 'strict undefined behavior'
Browse files Browse the repository at this point in the history
For now, this depends on a branch of minijinja, until
<mitsuhiko/minijinja#627> lands
fasterthanlime committed Nov 1, 2024
1 parent 33316c5 commit 607e0e3
Showing 9 changed files with 30 additions and 12 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -43,7 +43,8 @@ semver = "1.0.23"
newline-converter = "0.3.0"
dialoguer = "0.11.0"
sha2 = "0.10.6"
minijinja = { version = "2.4.0", features = ["debug", "loader", "builtins", "json", "custom_syntax"] }
# until <https://github.com/mitsuhiko/minijinja/pull/627> lands
minijinja = { version = "2.4.0", features = ["debug", "loader", "builtins", "json", "custom_syntax"], git = "https://github.com/mitsuhiko/minijinja", rev = "c9fe2eb" }
include_dir = "0.7.4"
itertools = "0.13.0"
cargo-wix = "0.3.8"
1 change: 1 addition & 0 deletions cargo-dist/src/backend/templates.rs
Original file line number Diff line number Diff line change
@@ -131,6 +131,7 @@ impl Templates {
}
for env in envs.values_mut() {
env.set_debug(true);
env.set_undefined_behavior(minijinja::UndefinedBehavior::Strict);

fn jinja_error(details: String) -> std::result::Result<String, minijinja::Error> {
Err(minijinja::Error::new(
18 changes: 16 additions & 2 deletions cargo-dist/src/errors.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
use axoproject::errors::AxoprojectError;
use camino::Utf8PathBuf;
use cargo_dist_schema::TargetTriple;
use miette::Diagnostic;
use miette::{Diagnostic, SourceOffset, SourceSpan};
use thiserror::Error;

/// An alias for the common Result type for this crate
@@ -587,7 +587,21 @@ pub struct AxoassetYamlError {
impl From<minijinja::Error> for DistError {
fn from(details: minijinja::Error) -> Self {
let source: String = details.template_source().unwrap_or_default().to_owned();
let span = details.range().map(|r| r.into());
let span = details.range().map(|r| r.into()).or_else(|| {
details.line().map(|line| {
// some minijinja errors only have a line, not a range, so let's just highlight the whole line
let start = SourceOffset::from_location(&source, line, 0);
let end = SourceOffset::from_location(&source, line + 1, 0);
let len = (end.offset() - start.offset()).wrapping_sub(1);
SourceSpan::from((start, len))
})
});

if std::env::var("CARGO_DIST_FORCE_BACKTRACE").as_deref() == Ok("1") {
let bt = std::backtrace::Backtrace::force_capture();
eprintln!("Cooking up a miette error, backtrace:\n{bt}");
}

DistError::Jinja {
source,
span,
2 changes: 1 addition & 1 deletion cargo-dist/templates/ci/github/release.yml.j2
Original file line number Diff line number Diff line change
@@ -300,7 +300,7 @@ jobs:
# Actually do builds and make zips and whatnot
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
echo "dist ran successfully"
{{%- if github_attestations %}}
{{%- if github_attestations is defined and github_attestations %}}
- name: Attest
uses: actions/attest-build-provenance@v1
with:
10 changes: 5 additions & 5 deletions cargo-dist/templates/installer/homebrew.rb.j2
Original file line number Diff line number Diff line change
@@ -36,17 +36,17 @@ class {{ formula_class }} < Formula
end
{%- endif %}
{#- #}
{%- if arm64_linux.id or x86_64_linux.id %}
{%- if arm64_linux.id is defined or x86_64_linux.id is defined %}
if OS.linux?
{%- if arm64_linux.id %}
{%- if arm64_linux.id is defined %}
if Hardware::CPU.arm?
url "{{ inner.base_url }}/{{ arm64_linux.id }}"
{%- if arm64_linux %}
sha256 "{{ arm64_linux_sha256 }}"
{%- endif %}
end
{%- endif %}
{%- if x86_64_linux.id %}
{%- if x86_64_linux.id is defined %}
if Hardware::CPU.intel?
url "{{ inner.base_url }}/{{ x86_64_linux.id }}"
{%- if x86_64_linux_sha256 %}
@@ -110,9 +110,9 @@ class {{ formula_class }} < Formula
{%- endif %}
end
{%- endif %}
{%- if arm64_linux.executables or arm64_linux.cdylibs %}
{%- if arm64_linux.executables is defined or arm64_linux.cdylibs is defined %}
if OS.linux? && Hardware::CPU.arm?
{%- if arm64_linux.executables %}
{%- if arm64_linux.executables is defined %}
bin.install {% for binary in arm64_linux.executables %}"{{ binary }}"{{ ", " if not loop.last else "" }}{% endfor %}
{%- endif %}
{%- if arm64_linux.cdylibs and "cdylib" in install_libraries %}
2 changes: 1 addition & 1 deletion cargo-dist/templates/installer/installer.sh.j2
Original file line number Diff line number Diff line change
@@ -339,7 +339,7 @@ select_archive_for_arch() {
"{{ target }}")
{%- for option in platform_support.platforms[target] %}
_archive="{{platform_support.archives[option.archive_idx].id}}"
{%- if option.runtime_conditions.min_glibc_version %}
{%- if option.runtime_conditions.min_glibc_version is defined %}
if ! check_glibc "{{option.runtime_conditions.min_glibc_version.major}}" "{{option.runtime_conditions.min_glibc_version.series}}"; then
_archive=""
fi
2 changes: 2 additions & 0 deletions cargo-dist/templates/installer/npm/run.js.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env node

const { run } = require("./binary");
{%- if bin is defined %}
run({{ bin }});
{%- endif %}
1 change: 1 addition & 0 deletions cargo-dist/tests/gallery/repo.rs
Original file line number Diff line number Diff line change
@@ -142,6 +142,7 @@ where
/// Run a test on this repo
pub fn run_test(&self, test: impl FnOnce(TestContext<Tools>) -> Result<()>) -> Result<()> {
std::env::set_var("CARGO_DIST_MOCK_NETWORKING", "1");
std::env::set_var("CARGO_DIST_FORCE_BACKTRACE", "1");
let maybe_tools = self.tools.lock();
let maybe_repo = self.ctx.lock();
// Intentionally unwrapping here to poison the mutexes if we can't fetch

0 comments on commit 607e0e3

Please sign in to comment.