Giter Site home page Giter Site logo

uuid's Introduction

A Kotlin Multiplatform UUID

Maven Central Build Status Contributor Covenant

K/N doesn't have a UUID yet. This brings a UUID that matches UUIDs on various platforms:

  • iOS/Mac: NSUUID
  • Java: java.util.UUID

UUID

  • Frozen
  • Thread-safe (thread-safe randomness in native)
  • Adheres to RFC4122
  • Tested
  • Tested against macOS/iOS UUID to verify correctness

Setup

In your build.gradle(.kts):

  • Add mavenCentral() to your repositories
  • Add implementation "com.benasher44:uuid:<version>" as a dependency in your commonMain sourceSets.

This library publishes gradle module metadata. If you're using Gradle prior to version 6, you should have enableFeaturePreview("GRADLE_METADATA") in your settings.gradle(.kts).

Future Goals

  • Develop UUID functionality that can be contributed back to the Kotlin stdlib (see latest issues, PRs, and CHANGELOG.md for updates)

uuid's People

Contributors

antohaby avatar benasher44 avatar bschramke avatar c2h6o avatar cmota avatar dependabot[bot] avatar fleshgrinder avatar glureau avatar gzaccaroni avatar insanusmokrassar avatar joffrey-bion avatar krxwallo avatar martinbonnin avatar saket avatar twyatt avatar ychescale9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uuid's Issues

WASM JS support

Add support to the new, in alpha, WASM Js target

The target:

wasmJs { browser() }

Incorrect UUID generation when system calls fail on Linux

Trivial example:

fun main(args: Array<String>) {
    while (true) {
        val res = open("/dev/zero", O_RDONLY)
        // out of fds
        if (res == -1 && errno == EMFILE) break
    }

    val uuid = uuid4()
    println(uuid.bytes.contentToString())
}

Output:

> Task :runReleaseExecutableLinuxX64
[0, 0, 0, 0, 0, 0, 64, 0, -128, 0, 0, 0, 0, 0, 0, 0]

This creates an arbitrary EMFILE error (which is very possible given the nature of K/N), but it could happen with something like EINTR if you're unlucky and a user provides a bad signal handler.

Add setup instructions

Once I get this published, I'll update this ticket. Then, the README can be updated with setup instructions.

Could not find "uuid" when build for JS

Hi team, came across this issue when build for js, do you know what could be an issue? have no issues with other libraries like bignum, coroutines

e: Could not find "uuid" in [/Users/user/Library/Application Support/kotlin/daemon]

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileProductionExecutableKotlinJs'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

string to uuid

Hello,
Is it possible to convert uuid-as-a-string to UUID object? I need it for my REST API.

Provide conversion to/from platform specific UUIDs

Libraries that have Uuid (provided by this library) on their public API, may need to internally call native APIs that expect or return native UUID representations (e.g. NSUUID on iOS).

It would be helpful to provide platform specific conversions from Uuid to native UUID types (e.g. fun Uuid.toNSUUID(): NSUUID), and visa versa.

0.8.3 breaks native builds

Steps to reproduce

  1. Download the JetBrains KMP library template from https://kmp.jetbrains.com/#templateGallery
  2. Modify the library's build.gradle.kts to add the uuid library
  3. ./gradlew assemble

Results

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':library:compileKotlinLinuxX64'.
> Could not resolve all task dependencies for configuration ':library:linuxX64CompileKlibraries'.
   > Could not resolve com.benasher44:uuid:0.8.3.
     Required by:
         project :library
      > No matching variant of com.benasher44:uuid:0.8.3 was found. The consumer was configured to find a library for use during 'kotlin-api', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64' but:
          - Variant 'iosArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosSimulatorArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosSimulatorArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosSimulatorArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosX64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosX64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'iosX64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'jsApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'jsRuntimeElements-published' capability com.benasher44:uuid:0.8.3 declares a library:
              - Incompatible because this component declares a component for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'jsSourcesElements-published' capability com.benasher44:uuid:0.8.3:
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'jvmApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during compile-time:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'jvmRuntimeElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during runtime:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'jvmSourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component for use during runtime:
              - Incompatible because this component declares documentation, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'macosArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'macos_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'macosArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'macos_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'macosArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'macos_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'macosX64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'macos_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'macosX64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'macos_x64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'macosX64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'macos_x64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'metadataApiElements' capability com.benasher44:uuid:0.8.3 declares a library:
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'metadataSourcesElements' capability com.benasher44:uuid:0.8.3:
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'mingwX64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'mingw_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'mingwX64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'mingw_x64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosSimulatorArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_simulator_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosSimulatorArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_simulator_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosSimulatorArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_simulator_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosX64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosX64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_x64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'tvosX64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'tvos_x64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'wasmJsApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'wasmJsRuntimeElements-published' capability com.benasher44:uuid:0.8.3 declares a library:
              - Incompatible because this component declares a component for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'wasmJsSourcesElements-published' capability com.benasher44:uuid:0.8.3:
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'wasm' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_x64')
          - Variant 'watchosArm32ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_arm32' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosArm32MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_arm32' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosArm32SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_arm32' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosDeviceArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_device_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosDeviceArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_device_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosDeviceArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_device_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosSimulatorArm64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_simulator_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosSimulatorArm64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_simulator_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosSimulatorArm64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_simulator_arm64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosX64ApiElements-published' capability com.benasher44:uuid:0.8.3 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosX64MetadataElements-published' capability com.benasher44:uuid:0.8.3 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_x64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Variant 'watchosX64SourcesElements-published' capability com.benasher44:uuid:0.8.3 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_x64' and the consumer needed a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)

* Try:
> Review the variant matching algorithm at https://docs.gradle.org/8.6/userguide/variant_attributes.html#sec:abm_algorithm.
> No matching variant errors are explained in more detail at https://docs.gradle.org/8.6/userguide/variant_model.html#sub:variant-no-match.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.6/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

Reduce dup builds

We could add HostManager checks to only add targets when running on specific host types, and then we won’t build for JVM on all 3 builds, for example.

Support for serialization

It would be nice to have support for kotlinx.serialization so we dont have to implement a serializer by hand when Uuid is used in a @Serializable class.

Nil UUID constant

RFC 4122 has a section:

4.1.7.  Nil UUID

The nil UUID is special form of UUID that is specified to have all
128 bits set to zero.

Would it make sense to have a constant value such as Uuid.ZERO to facilitate checking for the nil UUID in application code?

Unable to run publishToMavenLocal when pulling in uuid library as a dependency

Hey Ben, hope you are doing well!

I've been attempting to fix our internal publishing task, which seems to be broken because uuid5Of cannot be resolved and the build fails on compileIosMainKotlinMetadata. It isn't repo specific, and I've uploaded a playground project where running publishToMavenLocal fails with the same error.

ExpectActualPlayground.zip

It looks to be related to how the shared source sets are setup for the iOS target. If I remove support for everything apple but ios and simplify the source sets down to only iosMain (remove nonJvmMain and nativeMain), it seems to work just fine.

Simplified Uuid with jvm() and ios() targets

Not sure if you have any thoughts/pointers/suggestions on this. Cheers!

kotlinSourceSetMetadata IllegalStateException

I'm seeing an issue when I try to build from the command line, using "./gradlew assemble". I was able to replicate this issue using the output from Android Studio's new Project, select KMM Library, and then update the dependency block to include this library.

val commonMain by getting { dependencies { implementation("com.benasher44:uuid:0.5.0") } }

This is the output from the terminal showing the error:

% ./gradlew assemble

> Configure project :shared
Kotlin Multiplatform Projects are an Alpha feature. See: https://kotlinlang.org/docs/reference/evolution/components-stability.html. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.

The property 'kotlin.mpp.enableGranularSourceSetsMetadata=true' has no effect in this and future Kotlin versions, as Hierarchical Structures support is now enabled by default. It is safe to remove the property.

The property 'kotlin.native.enableDependencyPropagation=false' has no effect in this and future Kotlin versions, as Kotlin/Native dependency commonization is now enabled by default. It is safe to remove the property.


The following Kotlin source sets were configured but not added to any Kotlin compilation:
 * androidAndroidTestRelease
 * androidTestFixtures
 * androidTestFixturesDebug
 * androidTestFixturesRelease
You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets

> Task :shared:compileCommonMainKotlinMetadata FAILED
e: java.lang.IllegalStateException: e: Could not find "/Users/tethridge/Projects/test/mylib/shared/build/kotlinSourceSetMetadata/commonMain/com.benasher44-uuid/com.benasher44-uuid-commonMain.klib" in [/Users/tethridge/Library/Application Support/kotlin/daemon]
        at org.jetbrains.kotlin.library.SingleFileResolveKt$resolveSingleFileKlib$1.fatal(SingleFileResolve.kt:21)
        at org.jetbrains.kotlin.library.KotlinLibrarySearchPathResolver.resolve(SearchPathResolver.kt:175)
        at org.jetbrains.kotlin.library.KotlinLibrarySearchPathResolver.resolve(SearchPathResolver.kt:181)
        at org.jetbrains.kotlin.library.CompilerSingleFileKlibResolveStrategy.resolve(SearchPathResolver.kt:302)
        at org.jetbrains.kotlin.library.SingleFileResolveKt.resolveSingleFileKlib(SingleFileResolve.kt:24)
        at org.jetbrains.kotlin.library.SingleFileResolveKt.resolveSingleFileKlib$default(SingleFileResolve.kt:15)
        at org.jetbrains.kotlin.cli.metadata.KlibMetadataDependencyContainer.<init>(K2MetadataKlibSerializer.kt:122)
        at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer$serialize$analyzer$1.invoke(K2MetadataKlibSerializer.kt:54)
        at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer$serialize$analyzer$1.invoke(K2MetadataKlibSerializer.kt:48)
        at org.jetbrains.kotlin.cli.metadata.CommonAnalysisKt.runCommonAnalysisForSerialization(CommonAnalysis.kt:42)
        at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer.serialize(K2MetadataKlibSerializer.kt:53)
        at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:117)
        at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:40)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:91)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:43)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1623)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:598)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:844)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:721)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:720)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:compileCommonMainKotlinMetadata'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Internal compiler error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 664ms
25 actionable tasks: 23 executed, 2 up-to-date

Any idea what may be causing this issue?

Endianness and byte arrays

Exposing ByteArrays seams like a bad idea to me because of endianness concerns. I guess this is not an issue on the JVM but I seriously have no clue how the situation is with JavaScript and native platforms. I guess there is a reason why the Java people are not exposing their ByteArray functions and I’d say that we shouldn’t either.

That being said, we have to take special care with the MD5 and SHA-1 versions since their outcome might be affected by the endianness as well on other platforms than the JVM. We definitely should include test cases for these kind of things, however, I don’t know how we can. Maybe the Azure pipelines you use have a little-endian platform available to us?

Don’t get me wrong, supporting it would be nice. We could offer function to construct UUIDs from GUIDs and vice-versa. I also think that it’s possible; we just need a way to test it.

See also

Let’s collect some links here regarding this topic:

transformed metadata library build failure with 0.8.0

Hi, when I update from version 0.7.1 to 0.8.0 in my Kotlin Multiplatform-based project, I get this new build error:

java.lang.IllegalStateException: e: Could not find "~/project/shared/build/kotlinTransformedMetadataLibraries/commonMain/com.benasher44-uuid-0.8.0-commonMain-VraT7w.klib" in [~/Library/Application Support/kotlin/daemon]
	at org.jetbrains.kotlin.library.SingleFileResolveKt$resolveSingleFileKlib$1.fatal(SingleFileResolve.kt:21)
	at org.jetbrains.kotlin.library.KotlinLibrarySearchPathResolver.resolve(SearchPathResolver.kt:171)
	at org.jetbrains.kotlin.library.KotlinLibrarySearchPathResolver.resolve(SearchPathResolver.kt:176)
	at org.jetbrains.kotlin.library.CompilerSingleFileKlibResolveStrategy.resolve(SearchPathResolver.kt:298)
	at org.jetbrains.kotlin.library.SingleFileResolveKt.resolveSingleFileKlib(SingleFileResolve.kt:24)
	at org.jetbrains.kotlin.library.SingleFileResolveKt.resolveSingleFileKlib$default(SingleFileResolve.kt:15)
	at org.jetbrains.kotlin.cli.metadata.KlibMetadataDependencyContainer.<init>(K2MetadataKlibSerializer.kt:117)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer$serialize$analyzer$1.invoke(K2MetadataKlibSerializer.kt:49)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer$serialize$analyzer$1.invoke(K2MetadataKlibSerializer.kt:43)
	at org.jetbrains.kotlin.cli.metadata.CommonAnalysisKt.runCommonAnalysisForSerialization(CommonAnalysis.kt:42)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer.serialize(K2MetadataKlibSerializer.kt:48)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:122)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:40)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1486)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Anything else I can provide to help debug?

Thanks!

Built-in hasher for JavaScript for UUID v3 and v5

There are platform-specific hashers that enable uuid3Of and uuid5Of functions, but there isn't one for JS. I'm not sure if there is a recommended JS dependency to use for these, or if there is some JS API I don't know about that could provide these.

Parsing functions should be freestanding

Functions for creating new UUID instances that require parsing or other additional logic should be freestanding as is common in the Kotlin STD (e.g. listOf, setOf, mapOf).

fun uuidOf(value: String): UUID
fun uuid3(/* ???? */): UUID
fun uuid4(): UUID
fun uuid5(/* ???? */): UUID

I personally always think in versions and having uuid as the prefix should make them easy to find for users. However, some might prefer the randomUUID() as provided on the UUID class over uuid4(); which I can understand. However, the question would be how we should name the SHA-1 variant then. Java’s implementation calls the MD5 one nameUUIDFromBytes which is not very accurate and clear because there are two named versions (not to mention that MD5 is legacy). Summa summarum: going with the versions is the least ambiguous approach.

We could, maybe, have the following:

fun uuidMD5(/* ???? */): UUID
fun md5UUID(/* ???? */): UUID
fun uuidRandom(): UUID
fun randomUUID(): UUID
fun uuidSHA1(/* ???? */): UUID
fun sha1UUID(/* ???? */): UUID

But seriously, I think they’re all super ugly.

Regarding the arguments for the v3 and v5 functions. The RFC would ask us to provide uuid5(namespace: UUID, name: ByteArray|String) while Java offers the nameUUIDFromBytes that takes a single ByteArray; which is handy. A function that takes a variable amount of data and generates a UUID out of it is also very handy. I would thus propose the following:

fun uuid5(namespace: UUID, data: ByteArray): UUID
fun uuid5(namespace: UUID, data: String): UUID
fun uuid5(namespace: UUID, vararg data: String): UUID
fun uuid5(data: ByteArray): UUID
fun uuid5(data: String): UUID
fun uuid5(vararg data: String): UUID

Thoughts?

Required for inclusion in Kotlin STD (see #25).

Class API must be compatible with Java UUID

One of the promises of Kotlin is perfect Java interop. We have to uphold this promise if we want to be included in Kotlin’s STD. The java.util.UUID class has some functionality that nobody really needs, however, a subset of it is definitely relevant in general.

I would say that the following subset makes sense for a UUID class that supports multiple UUID versions:

expect class UUID(msb: Long, lsb: Long) : Comparable<UUID> {
    val mostSignificantBits: Long
    val leastSignificantBits: Long
    fun variant(): Int
    fun version(): Int
}

I chose expect in the above example on purpose because we have to define it as such in common. Otherwise we are not able to use actual typealias UUID = java.util.UUID in the JVM part of the library; which is required for perfect Java interoperability.

There are a few gotchas here but those should be resolved as part of the pull request.

Required for inclusion in Kotlin STD (see #25).

Add a serializer

To make it easier to use this with kotlinx-serialization, it would be nice to have a serializer added to the library. Possible serializer:

object UuidSerializer : KSerializer<Uuid> {
    override val descriptor = PrimitiveSerialDescriptor("Uuid", PrimitiveKind.STRING)
    override fun deserialize(decoder: Decoder): Uuid {
        return uuidFrom(decoder.decodeString())
    }
    override fun serialize(encoder: Encoder, value: Uuid) {
        encoder.encodeString(value.toString())
    }
}

with @Serializable(with=UuidSerializer::class) on the Uuid class.

Windows support

To support windows, the "native" tests should be moved into a macOS/iOS test-specific directory, and then I think this might build/work for windows?

Unable to access uuidFrom iOS app

Hello all!

First, let me say thank you for this awesome library! It saves me a lot of time not having to implement it from scratch 🙂.

I was trying to access the uuidFrom my iOS application, but it seems the method is not added to the framework, do you have any idea why?

This is the content generated

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("UuidUuid")))
@interface Common_dtoUuidUuid : Common_dtoBase <Common_dtoKotlinComparable>
- (instancetype)initWithMsb:(int64_t)msb lsb:(int64_t)lsb __attribute__((swift_name("init(msb:lsb:)"))) __attribute__((objc_designated_initializer));
- (instancetype)initWithUuidBytes:(Common_dtoKotlinByteArray *)uuidBytes __attribute__((swift_name("init(uuidBytes:)"))) __attribute__((objc_designated_initializer)) __attribute__((deprecated("Use `uuidOf` instead.")));
- (int32_t)compareToOther:(Common_dtoUuidUuid *)other __attribute__((swift_name("compareTo(other:)")));
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
- (NSUInteger)hash __attribute__((swift_name("hash()")));
- (NSString *)description __attribute__((swift_name("description()")));
@property (readonly) int64_t leastSignificantBits __attribute__((swift_name("leastSignificantBits")));
@property (readonly) int64_t mostSignificantBits __attribute__((swift_name("mostSignificantBits")));
@end;

Thank you 🙂

Support for M1 simulators

Since Kotlin 1.5.30 there are M1 simulator targets available. Would be great if you could add support for these as any project using this library cannot use the simulator targets until then. Hopefully it’s as simple as adding the new targets to build.gradle.kts.

Kotlin 1.7.20

Kotlin 1.7.20 is out with its new memory model.
Could we consider upgrading to the 1.7.20 and supporting the new memory model (if needed)?

CI

I have less experience with Windows (#1), but I think everything else should be easy enough to check with travis.

Combined time-GUID

Hello. Thank you for this library!
In my project I need to create a time-based UUID. So it has to have a timestamp part and a random part (instead of MAC part like in UUID version 1). How to make it possible with your library?
I expect the UUID to be comparable based on timestamp too. So it's kind of UUID version 1 + version 4.

Some derails of the idea:
https://en.m.wikipedia.org/wiki/Universally_unique_identifier#As_database_keys
http://www.informit.com/articles/article.aspx?p=25862

Add `watchosX64` target

It seems this target is missing and I believe there would be no additional cost to add this target, given that the shared code should just work

Polish, extend, and become part of Kotlin STD?

Hey @benasher44, I’m coming from KT-31880 where your library was mentioned as an attempt on creating a cross-platform UUID library for Kotlin. I would very much like to see this becoming part of Kotlin’s STD due to the reasons mentioned in the ticket.

Doing so would require significant changes, e.g. Java 1.6 support and instead of defining our own data class we’d have to implement it in a compatible fashion to Java.

Would you be interested in that?

Java 1.6 compatibility

The minimum JVM version supported by Kotlin is Java 1.6 and we require the same minimum compatibility for the library. The java.util.UUID was already included in that version and its API didn’t change over the years.

Required for inclusion in Kotlin STD (see #25).

Library status and publishing

Hi! This library looks really cool, could you tell about the status of this library for production? And when will it be published?

Built-in hasher for linux for UUID v3 and v5

There are platform-specific hashers that enable uuid3Of and uuid5Of functions, but I didn't add them for linux. I think it requires setting up a .def for openssl, but I don't have a linux setup to test/debug on easily + personal lack of familiarity

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.