It is obviously possible, but very tedious, and very complex.
Writing a new constraint implies:
- extending the proto to support the constraint
- writing the input validation
- writing the solution checker
- writing the loading (into CP-SAT engine) code
- writing the presolve rules
- writing the propagation code. Which is complex as every deduction needs to be fully explained.
- writing the linearization/cut generation code
The last 3 items are extremely error prone, and very hard to debug, as the effect of cuts and explanations are delayed, and sometimes never used.
For these reason, I recommend expanding the constraint into smaller ones. In fact, most of the CP constraints are expanded (alldiff, element, table, reservoir, inverse, automaton, some products, some modulos).
You can also submit a feature request for a new constraint. It can happen if it is useful/general enough.
Thanks