Skip to content

Fixes #28507: Add ADR for Handling IO encoding in Rust modules - #6985

Merged
amousset merged 7 commits into
Normation:branches/rudder/9.0from
m4rtinh4rt:bug_28507/add_adr_for_handling_io_encoding_in_rust_modules
Apr 22, 2026
Merged

Fixes #28507: Add ADR for Handling IO encoding in Rust modules#6985
amousset merged 7 commits into
Normation:branches/rudder/9.0from
m4rtinh4rt:bug_28507/add_adr_for_handling_io_encoding_in_rust_modules

Conversation

@m4rtinh4rt

Copy link
Copy Markdown
Contributor

@m4rtinh4rt

Copy link
Copy Markdown
Contributor Author

PR updated with a new commit

Fixes #28507: Add ADR for Handling IO encoding in Rust modules
@m4rtinh4rt
m4rtinh4rt marked this pull request as ready for review March 11, 2026 10:08
@m4rtinh4rt
m4rtinh4rt requested a review from amousset March 11, 2026 10:08
Comment thread adr/system/28504-io-encoding-in-rust-modules.md
@m4rtinh4rt

Copy link
Copy Markdown
Contributor Author

PR updated with a new commit

…modules

Fixes #28507: Add ADR for Handling IO encoding in Rust modules
@m4rtinh4rt

Copy link
Copy Markdown
Contributor Author

PR updated with a new commit

…n Rust modules

Fixes #28507: Add ADR for Handling IO encoding in Rust modules
@m4rtinh4rt
m4rtinh4rt requested a review from amousset April 1, 2026 13:45

## Consequences

The new functions must be used when performing I/O operations on files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only on Windows or everywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to use those functions everywhere to abstract the OS-specific logic (BOM vs. non-BOM) so we don’t have to repeat it in every module.

Comment thread adr/system/28504-io-encoding-in-rust-modules.md
- Takes as parameter the file path, the data string in UTF-8, and an enum specifying the target encoding.
- It supports writing files as UTF-8, UTF-8 with BOM and UTF-16 BOM LE.
- All writes to disk are atomic.
- On Windows, files written by this function include a BOM:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only on Windows? What would be the behavior on Linux?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code in rudderc adds an UTF-8 BOM only for the Windows backend.

impl Backend for Windows {
    fn generate(
        &self,
        technique: Technique,
        resources: &Path,
        _standalone: bool,
    ) -> Result<String> {
        // Powershell requires a BOM added at the beginning of all files when using UTF8 encoding
        // See https://docs.microsoft.com/en-us/windows/desktop/intl/using-byte-order-marks
        // Bom for UTF-8 content, three bytes: EF BB BF https://en.wikipedia.org/wiki/Byte_order_mark
        const UTF8_BOM: &[u8; 3] = &[0xef, 0xbb, 0xbf];
        let mut with_bom = String::from_utf8(UTF8_BOM.to_vec()).unwrap();
        with_bom.push_str(&Self::technique(technique, resources)?);
        Ok(with_bom)
    }
}

It is not needed on Linux and could potentially break things.

@m4rtinh4rt

Copy link
Copy Markdown
Contributor Author

PR updated with a new commit

…oding in Rust modules

Fixes #28507: Add ADR for Handling IO encoding in Rust modules
@m4rtinh4rt

Copy link
Copy Markdown
Contributor Author

PR updated with a new commit

… IO encoding in Rust modules

Fixes #28507: Add ADR for Handling IO encoding in Rust modules
@m4rtinh4rt

Copy link
Copy Markdown
Contributor Author

PR updated with a new commit

…andling IO encoding in Rust modules

Fixes #28507: Add ADR for Handling IO encoding in Rust modules
@amousset
amousset merged commit 495a327 into Normation:branches/rudder/9.0 Apr 22, 2026
14 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants