Skip to content

Conversation

fhunleth
Copy link
Contributor

@fhunleth fhunleth commented Aug 16, 2025

This removes both the Elixir module and the NIF. There's no longer any
unintended NIF builds or loads or anything extra.

To enable this, either set the :default_backend application
environment key or force it by setting :include_i2c_dev. Most users
probably want:

config :circuits_i2c, default_backend: MyI2CBackend

This fixes the issue reported at https://elixirforum.com/t/circuits-sim-in-a-release/72076/3.

@fhunleth fhunleth requested a review from Copilot August 16, 2025 19:54
Copilot

This comment was marked as outdated.

@fhunleth fhunleth force-pushed the dont-load-nif-if-not-built branch from c73ab26 to 3881908 Compare August 17, 2025 20:26
@fhunleth fhunleth requested a review from Copilot August 17, 2025 20:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR restructures the Circuits.I2C project to make the NIF-based I2C backend optional, allowing builds without the native Linux dependencies. The changes move NIF-related code to a separate i2c_dev directory and introduce configuration options to control whether the NIF is built.

  • Moved all NIF-related C code and Elixir modules to a new i2c_dev subdirectory
  • Added application configuration to conditionally include or exclude the I2CDev backend
  • Enhanced the NilBackend to provide a complete implementation when I2CDev is disabled

Reviewed Changes

Copilot reviewed 7 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mix.exs Restructured project configuration to conditionally include NIF compilation based on build_i2c_dev?() function
lib/i2c/nil_backend.ex Added Bus protocol implementation with error-returning stubs for all I2C operations
i2c_dev/c_src/i2c_nif.c Fixed missing closing brace and added errno setting for test backend
REUSE.toml Updated file path references to reflect new i2c_dev directory structure
README.md Added documentation for new application configuration options
Makefile Updated all C source paths and removed "disabled" mode, now only supports "normal" and "test"
.formatter.exs Added i2c_dev directory to formatter input paths

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

This removes both the Elixir module and the NIF. There's no longer any
unintended NIF builds or loads or anything extra.

To enable this, either set the `:default_backend` application
environment key or force it by setting `:include_i2c_dev`. Most users
probably want:

```elixir
config :circuits_i2c, default_backend: MyI2CBackend
```
@fhunleth fhunleth force-pushed the dont-load-nif-if-not-built branch from 93aff92 to b575c18 Compare August 17, 2025 20:42
@fhunleth fhunleth changed the title Don't try to load NIF if not built Support builds that completely exclude I2CDev support Aug 17, 2025
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.

1 participant