microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
727 stars 638 forks source link

Information about setting build config macros in extensions and user settings #5329

Closed martinwork closed 1 year ago

martinwork commented 1 year ago

Is there any documentation about setting C++ build config macros in extensions and user settings?

In particular:

This question has arisen recently in a couple of circumstances...

PR https://github.com/microsoft/pxt-microbit/pull/5202

Is it possible for an extension to change the default BLE security mode to "No pairing required" in a way that is reflected in the Project Settings UI and allows the user to override the default?

https://github.com/lancaster-university/codal-microbit-v2/issues/354

I tried following this example, but that form didn't seem to work for me. https://github.com/microsoft/pxt-microbit/blob/c6a9d193378b90753be0a9b3d21fd40c4f013b09/libs/cpp-test/pxt.json#L9

    "microbit": {
        "config": {
            "MICROBIT_BLE_ENABLED": "0"
        }
    },

This form seems to be more common, and works for my example, but I didn't expect to need to wrap CODAL settings in "yotta". https://github.com/microsoft/pxt-common-packages/blob/47c24ccc95330be6b8193cf2636a9dbee7015a80/libs/mouse/pxt.json#L17

    "yotta": {
        "config": {
            "DEVICE_USB": 1,
            "DEVICE_MOUSE": 1
        }
    }

I also found https://github.com/microsoft/pxt-common-packages/blob/47c24ccc95330be6b8193cf2636a9dbee7015a80/libs/core/pxt.json#L46

    "yotta": {
        "config": {
            "codal": {
                "component_count": 64,
                "dmesg_buffer_size": 1024
            }
        }
    },
jwunderl commented 1 year ago

@ganicke do you happen to know if we have any docs related to this? I've definitely seen it as "yotta": { "config": { ... but it's not my area of expertise / would have to poke around to find exact details

ganicke commented 1 year ago

There are just two places where yotta is mentioned...

...however, YottaConfig isn't documented outside of just referring to https://docs.yottabuild.org/reference/config.html.

The settings mentioned are target specific and would need to be in a page under the target doc space or be listed in subsections of the pxt.json page?

jwunderl commented 1 year ago

Yeah, I guess probably as a target specific page would make sense. That said, I'm not really sure what we'd put in their besides some broad 'it should look vaguely like this' with some samples similar to the issue post, as it's already a rare enough case anyone would want to change anything there / for the most part changes here come from a pretty specific need iirc where they'd typically be copied from existing repos or coming with changes in compiler itself

ganicke commented 1 year ago

Another example using a lib config is https://github.com/microsoft/pxt-calliope/blob/f43f6567f02868f79d11fb455bf25a05a3ca0146/libs/bluetooth/pxt.json#L20

"yotta": {
     "config": {
        "microbit-dal": {
            "bluetooth": {
                "enabled": 1
            }
        }
    }
}

Also, looking through ./cli/buildengine.ts, it seems that extractConstants() is liking the config name of "microbit-dal".