# Switching license conditionally based on manifest feature

**URL:** <https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633>\
**Category:** cargo\
**Created:** [October 1, 2023, 3:39am UTC](https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633 "2023-10-01T03:39:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KisaragiEffective](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kisaragieffective/32/10678_2.png) [@KisaragiEffective](https://internals.rust-lang.org/u/KisaragiEffective)\
**Post date:** [October 1, 2023, 3:39am UTC](https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633/1 "2023-10-01T03:39:36Z")

</div>

I wish switching `package.license` field by its dependencies. I thought it's useful if we touch library (such as `*-sys`) which is licensed under copy-lefts that require "license propagation." (especially `/A?GPL/`) I have tried to make it happen with following manifests:

```toml
# ./local1/Cargo.toml
[package]
name = "local1"
version = "0.1.0"
edition = "2021"

[target.'cfg(not(feature = "2"))'.package]
license = "MIT"

[target.'cfg(feature = "2")'.package]
license = "GPL-3.0-or-later"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
local2_gpl = { path = "../local2_gpl", optional = true }

[features]
2 = ["dep:local2_gpl"]

```

```toml
[package]
name = "local2_gpl"
version = "0.1.0"
edition = "2021"
license = "GPL-3.0-or-later"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

```

However, `cargo-metadata -F 2` on workspace root does not recognize `target.cfg(...).package` section. It reports no license is tied with `local1` package.

How can I achieve this? Thank you.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [October 1, 2023, 10:23am UTC](https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633/2 "2023-10-01T10:23:16Z")

</div>

It's not possible to change the package license in the metadata on the basis of configuration. It's a fixed metadata field.

Current best practices I've seen involve documenting the dependency license in the README and making sure the dependency license is GPL-3.0-or-later, and relying on people to run tools like `cargo-deny` that check licenses recursively.

---

<div class="post-metadata">

**Author:** ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)\
**Post date:** [October 1, 2023, 12:29pm UTC](https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633/3 "2023-10-01T12:29:52Z")

</div>

> [@KisaragiEffective](#):
>
> which is licensed under copy-lefts that require "license propagation."

This only applies to binaries built from the sources together. The sources at-rest can be licensed under any license which is _compatible_ with re-distribution under the copy-left license. (This is why the standard Rust license is `Apache-2.0 OR MIT`, the MIT license is compatible to be re-distributed under the `GPL-3.0` license after becoming part of a combined work, Apache-2.0 on its own is not).

EDIT: To expand a little bit more, it's my understanding that usage of the GPL-3.0 copyrighted interface from the MIT licensed code falls under fair use, so it does not affect what license your code must be under. Only once you link in the implementation do you have to start complying with the GPL-3.0 license for that combined work. Largely based on the outcome of [Google LLC v. Oracle America, Inc.](https://en.wikipedia.org/wiki/Google_LLC_v._Oracle_America%2C_Inc.).

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 1, 2023, 1:15pm UTC](https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633/4 "2023-10-01T13:15:45Z")

</div>

> [@Nemo157](#):
>
> EDIT: To expand a little bit more, it's my understanding that usage of the GPL-3.0 copyrighted interface from the MIT licensed code falls under fair use, so it does not affect what license your code must be under. Only once you link in the implementation do you have to start complying with the GPL-3.0 license for that combined work. Largely based on the outcome of [Google LLC v. Oracle America, Inc.](https://en.wikipedia.org/wiki/Google_LLC_v._Oracle_America%2C_Inc.).

Not to derail the thread, but _Google v. Oracle_ was about whether APIs are inherently copyrightable. In this case, the "structure and organization" of APIs was insufficient for copyright in the first place. It's a narrow ruling and would need more cases to find "boundaries" one could use in the wild. Copyright flows through "derivative work" regardless of linking status or the like (but linking can be an indicator of whether something is such a derivative work).

Basically, my recommendations are the same: license your code as you see fit (provided it does not cause conflicting requirements), but your binaries are subject to your dependency's terms as well since they are included.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [October 1, 2023, 4:26pm UTC](https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633/5 "2023-10-01T16:26:39Z")

</div>

You can conditionally include dependencies. Having the code licensed differently as a dependency declaring its license in its own package should be enough.

Tools that scan dependencies need to scan everything recursively anyway.

The combined product will need to obey sum of all licenses, but you’re free to license your own code however you like.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [March 24, 2025, 4:27pm UTC](https://internals.rust-lang.org/t/switching-license-conditionally-based-on-manifest-feature/19633/6 "2025-03-24T16:27:14Z")

</div>

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
